proximity trigger
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -27,15 +27,39 @@
|
||||
android:paddingRight="@dimen/default_margin"
|
||||
android:text="@string/state"/>
|
||||
|
||||
<com.google.android.material.slider.RangeSlider
|
||||
android:id="@+id/rsProximity"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
android:valueFrom="0"
|
||||
android:valueTo="100"
|
||||
android:stepSize="1"
|
||||
android:theme="@style/AppThemeCompat" />
|
||||
<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>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user