Improve reliability of proximity sensor. <=4cm.
This commit is contained in:
parent
ba5811582a
commit
a8748ebc83
2 changed files with 19 additions and 8 deletions
|
@ -303,14 +303,9 @@ public class LinphoneActivity extends TabActivity {
|
|||
List<Sensor> lSensorList = mSensorManager.getSensorList(Sensor.TYPE_PROXIMITY);
|
||||
mSensorEventListener = new SensorEventListener() {
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (event.timestamp == 0) return; //just ignoring for nexus 1
|
||||
Log.d(TAG, "Proximity sensor report ["+event.values[0]+"] , for max range ["+event.sensor.getMaximumRange()+"]");
|
||||
|
||||
if (event.values[0] != event.sensor.getMaximumRange() ) {
|
||||
instance().hideScreen(true);
|
||||
} else {
|
||||
instance().hideScreen(false);
|
||||
}
|
||||
//just ignoring for nexus 1
|
||||
if (event.timestamp == 0) return;
|
||||
instance().hideScreen(LinphoneManager.isProximitySensorNearby(event));
|
||||
}
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
|
|
@ -73,6 +73,7 @@ import android.content.SharedPreferences;
|
|||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.ConnectivityManager;
|
||||
|
@ -894,4 +895,19 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
mLc.adjustSoftwareVolume((nextVolume - maxVolume)* dbStep);
|
||||
}
|
||||
|
||||
public static Boolean isProximitySensorNearby(final SensorEvent event) {
|
||||
float threshold = 4.001f; // <= 4 cm is near
|
||||
|
||||
final float distanceInCm = event.values[0];
|
||||
final float maxDistance = event.sensor.getMaximumRange();
|
||||
Log.d(TAG, "Proximity sensor report ["+distanceInCm+"] , for max range ["+maxDistance+"]");
|
||||
|
||||
if (maxDistance <= threshold) {
|
||||
// Case binary 0/1 and short sensors
|
||||
threshold = maxDistance;
|
||||
}
|
||||
|
||||
return distanceInCm < threshold;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue