proximity trigger

This commit is contained in:
2025-11-06 23:27:32 +01:00
parent 55a1c24753
commit fdcdaf53c9
3 changed files with 60 additions and 8 deletions

View File

@@ -86,11 +86,23 @@ public class ActivityManageTriggerProximity extends Activity
}
});
startPreview();
rsProximity.setValues(20f, 80f);
}
@Override
protected void onResume()
{
super.onResume();
startPreview();
}
@Override
protected void onPause()
{
super.onPause();
stopPreview();
}
void startPreview()
{
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
@@ -113,6 +125,12 @@ public class ActivityManageTriggerProximity extends Activity
}
}
void stopPreview()
{
if(proximitySensor != null)
sensorManager.unregisterListener(proximitySensorEventListener);
}
SensorEventListener proximitySensorEventListener = new SensorEventListener()
{
@Override

View File

@@ -27,16 +27,40 @@
android:paddingRight="@dimen/default_margin"
android:text="@string/state"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.slider.RangeSlider
android:id="@+id/rsProximity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="100"
android:stepSize="1"
android:theme="@style/AppThemeCompat" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/close"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/far"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
</TableRow>
</TableLayout>
@@ -52,9 +76,16 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:text="@string/testArea"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/default_margin"
android:text="@string/proximitySensorHint" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -966,4 +966,7 @@
<string name="testArea">Test area</string>
<string name="testAreaProximityComment">Approach your device to test how it reacts.</string>
<string name="deviceDoesntHaveProximitySensor">Your device doesn\'t seem to have a proximity sensor.</string>
<string name="proximitySensorHint">A proximity sensor works differently on every device model. On some it just reports close or far as binary values, on others it may report more granular values. You may use this tester to see how it behaves on your device.</string>
<string name="close">close</string>
<string name="far">far</string>
</resources>