List of usage examples for android.hardware Sensor TYPE_PROXIMITY
int TYPE_PROXIMITY
To view the source code for android.hardware Sensor TYPE_PROXIMITY.
Click Source Link
From source file:Main.java
@SuppressWarnings("deprecation") public static String getSensorTypeStr(int type) { switch (type) { case Sensor.TYPE_ALL://-1 return "TYPE_ALL"; //Accelerometer sensor type case Sensor.TYPE_ACCELEROMETER://1 return "TYPE_ACCELEROMETER"; //Magnetic field sensor type case Sensor.TYPE_MAGNETIC_FIELD://2 return "TYPE_MAGNETIC_FIELD"; //Orientation sensor type case Sensor.TYPE_ORIENTATION://3 return "TYPE_ORIENTATION"; //Gyroscope sensor type case Sensor.TYPE_GYROSCOPE://4 return "TYPE_GYROSCOPE"; //Light sensor type case Sensor.TYPE_LIGHT://5 return "TYPE_LIGHT"; //Pressure sensor type case Sensor.TYPE_PRESSURE://6 return "TYPE_PRESSURE"; //Temperature sensor type case Sensor.TYPE_TEMPERATURE://7 return "TYPE_TEMPERATURE"; //Proximity sensor type case Sensor.TYPE_PROXIMITY://8 return "TYPE_PROXIMITY"; //Gravity sensor type case Sensor.TYPE_GRAVITY://9 return "TYPE_GRAVITY"; //Linear acceleration sensor type case Sensor.TYPE_LINEAR_ACCELERATION://10 return "TYPE_LINEAR_ACCELERATION"; //Rotation vector sensor type case Sensor.TYPE_ROTATION_VECTOR://11 return "TYPE_ROTATION_VECTOR"; //Relative humidity sensor type case Sensor.TYPE_RELATIVE_HUMIDITY://12 return "TYPE_RELATIVE_HUMIDITY"; //Ambient temperature sensor type case Sensor.TYPE_AMBIENT_TEMPERATURE://13 return "TYPE_AMBIENT_TEMPERATURE"; //Uncalibrated magnetic field sensor type case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED://14 return "TYPE_MAGNETIC_FIELD_UNCALIBRATED"; //Uncalibrated rotation vector sensor type case Sensor.TYPE_GAME_ROTATION_VECTOR://15 return "TYPE_GAME_ROTATION_VECTOR"; //Uncalibreted gyroscope sensor type case Sensor.TYPE_GYROSCOPE_UNCALIBRATED://16 return "TYPE_GYROSCOPE_UNCALIBRATED"; //Significant motion trigger sensor case Sensor.TYPE_SIGNIFICANT_MOTION://17 return "TYPE_SIGNIFICANT_MOTION"; //Step detector sensor case Sensor.TYPE_STEP_DETECTOR://18 return "TYPE_STEP_DETECTOR"; //Step counter sensor case Sensor.TYPE_STEP_COUNTER://19 return "TYPE_STEP_COUNTER"; //Geo-magnetic rotation vector case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR://20 return "TYPE_GEOMAGNETIC_ROTATION_VECTOR"; //Heart rate monitor case Sensor.TYPE_HEART_RATE://21 return "TYPE_HEART_RATE"; default:/* w ww. ja va2 s .co m*/ return UNKNOWN; } }
From source file:org.durka.hallmonitor.ViewCoverProximityService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LOG_TAG + ".oSC", "View cover Proximity service started"); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY), SensorManager.SENSOR_DELAY_NORMAL); return START_STICKY; }
From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java
/** * {@inheritDoc}//from ww w. ja v a 2 s. c o m */ @Override public void onResume() { super.onResume(); // Skips if the sensor has been already attached if (proximitySensor != null) return; SensorManager manager = JitsiApplication.getSensorManager(); List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL); logger.trace("Device has " + sensors.size() + " sensors"); for (Sensor s : sensors) { logger.trace("Sensor " + s.getName() + " type: " + s.getType()); } this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (proximitySensor == null) { return; } logger.info("Using proximity sensor: " + proximitySensor.getName()); sensorDisabled = false; manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI); }
From source file:org.jitsi.android.gui.call.ProximitySensorFragment.java
/** * {@inheritDoc}//from w w w .ja va 2 s . com */ @Override public void onResume() { super.onResume(); SensorManager manager = JitsiApplication.getSensorManager(); // Skips if the sensor has been already attached if (proximitySensor != null) { // Re-registers the listener as it might have been // unregistered in onPause() manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI); return; } List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL); logger.trace("Device has " + sensors.size() + " sensors"); for (Sensor s : sensors) { logger.trace("Sensor " + s.getName() + " type: " + s.getType()); } this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (proximitySensor == null) { return; } logger.info("Using proximity sensor: " + proximitySensor.getName()); sensorDisabled = false; manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI); }
From source file:org.durka.hallmonitor.ViewCoverProximityService.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) { Log.d(LOG_TAG + ".onSC", "Proximity sensor changed, value=" + event.values[0]); proximity(event.values[0]);/*ww w . j av a2 s . co m*/ // improve reliability by refiring the event 200ms afterwards final float val = event.values[0]; Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { proximity(val); } }, 200); timer.schedule(new TimerTask() { @Override public void run() { proximity(val); } }, 500); } }
From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java
public static void onActivityReStart(Context context) { BDebug.i(tag, "onActivityReStart"); if (sensorEventListener != null) { SensorManager mSensorManager = (SensorManager) context.getApplicationContext() .getSystemService(Context.SENSOR_SERVICE); Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorManager.registerListener(sensorEventListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL); }/*from w ww .ja v a2 s. co m*/ }
From source file:com.achep.acdisplay.ui.fragments.PocketFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mProximityAvailable = mProximitySensor != null; if (mProximityAvailable) { mMaximumRange = mProximitySensor.getMaximumRange(); }// ww w.j av a 2 s .c o m }
From source file:ch.jeda.platform.android.SensorManager.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.sensorMap.clear(); this.sensorInfoMap.clear(); this.sensorListenerMap.clear(); this.imp = (android.hardware.SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE); this.checkAdd(SensorType.ACCELERATION, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); this.checkAdd(SensorType.GRAVITY, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_GRAVITY)); this.checkAdd(SensorType.LIGHT, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_LIGHT)); this.checkAdd(SensorType.LINEAR_ACCELERATION, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)); // Android returns values in micro Tesla this.checkAdd(SensorType.MAGNETIC_FIELD, 1e-6f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)); // Android returns value in hekto Pascal this.checkAdd(SensorType.PRESSURE, 100f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PRESSURE)); // Android returns value in centimeter this.checkAdd(SensorType.PROXIMITY, 0.01f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PROXIMITY)); // Android returns value in degrees Celcius this.checkAdd(SensorType.TEMPERATURE, 1f, -273.15f, this.imp.getDefaultSensor(Sensor.TYPE_TEMPERATURE)); }
From source file:rus.cpuinfo.AndroidDepedentModel.SensorsInfo.java
@Override @SuppressLint("NewApi") @NonNull// w w w .j a va 2 s . c o m public String getInfo(int query) { int type; switch (query) { case SENSOR_ACCELEROMETR: type = Sensor.TYPE_ACCELEROMETER; break; case SENSOR_AMBIENT_TEMPERATURE: type = Sensor.TYPE_AMBIENT_TEMPERATURE; break; case SENSOR_LINEAR_ACCELERATION: type = Sensor.TYPE_LINEAR_ACCELERATION; break; case SENSOR_LIGHT: type = Sensor.TYPE_LIGHT; break; case SENSOR_MAGNETIC_FIELD: type = Sensor.TYPE_MAGNETIC_FIELD; break; case SENSOR_ROTATION_VECTOR: type = Sensor.TYPE_ROTATION_VECTOR; break; case SENSOR_TYPE_GRAVITY: type = Sensor.TYPE_GRAVITY; break; case SENSOR_TYPE_GYROSCOPE: type = Sensor.TYPE_GYROSCOPE; break; case SENSOR_PROXIMITY: type = Sensor.TYPE_PROXIMITY; break; case SENSOR_PRESSURE: type = Sensor.TYPE_PRESSURE; break; case SENSOR_RELATIVE_HUMIDITY: type = Sensor.TYPE_RELATIVE_HUMIDITY; break; case SENSOR_TEMPERATURE: type = Sensor.TYPE_AMBIENT_TEMPERATURE; break; case SENSOR_HUMIDITY: type = Sensor.TYPE_RELATIVE_HUMIDITY; break; case SENSOR_ORIENTATION: type = Sensor.TYPE_ORIENTATION; break; case SENSOR_HEART_RATE: type = Sensor.TYPE_HEART_RATE; break; case SENSOR_SIGNIFICANT_MOTION: type = Sensor.TYPE_SIGNIFICANT_MOTION; break; case SENSOR_GEOMAGNETIC_ROTATION_VECTOR: type = Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR; break; case SENSOR_STEP_COUNTER: type = Sensor.TYPE_STEP_COUNTER; break; case SENSOR_STEP_DETECTOR: type = Sensor.TYPE_STEP_DETECTOR; break; case SENSOR_GAME_ROTATION_VECTOR: type = Sensor.TYPE_GAME_ROTATION_VECTOR; break; default: throw new IllegalArgumentException("Query must be with \"SENSOR.\" prefix"); } return getSensorName(type); }
From source file:com.configurer.easyscreenlock.service.ForegroundSensorService.java
protected void registerListener() { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); if (isSensorAvailable()) { sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); /**/*from ww w. j av a 2 s . c om*/ * Showing available sensor on Device * */ showAvailableSensors(); listener = new ProximitySensorEventListener(this); boolean isRegistered = mSensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_FASTEST); Log.i(TAG, "Registering listener : " + isRegistered); } else { Log.w(TAG, "Proximity Sensor not available, sorry :( "); } }