Java Code Examples for android.hardware.Sensor#TYPE_PROXIMITY

The following examples show how to use android.hardware.Sensor#TYPE_PROXIMITY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 2
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 3
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 4
Source File: ProximityService.java    From CoolClock with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    float[] its = sensorEvent.values;
    Log.d(TAG, String.format("its %f %f %f len:,%d", its[0], its[1], its[2], its.length));
    if (sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY) {
        if (FuncUnit.isForeground(ClockApplication.getContext(), MainActivity.class.getName())) {
            if (its[0] == 0.0) {
                System.out.println("Hand stay");
                if (ScreenManager.isScreenOn()) {
                    ScreenManager.systemLock(ClockApplication.getInstance().getMainActivity());
                } else {
                    ScreenManager.systemUnLock();
                }
            } else {
                System.out.println("Hand leave...");
            }
        }
    }
}
 
Example 5
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 6
Source File: AudioSourceSwitcher.java    From android-auto-call-recorder with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
        if (event.values[0] >= -SENSOR_SENSITIVITY && event.values[0] <= SENSOR_SENSITIVITY) {
            //near
            Log.d(TAG, "near");
            playOnEarpiece();
        } else {
            //far
            Log.d(TAG, "far");
            playOnSpeaker();
        }
    }
}
 
Example 7
Source File: CallActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    WindowManager.LayoutParams params = this.getWindow().getAttributes();
    if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
        if (event.values[0] == 0) {
        /*  FileLog.d("onSensorChanged", "distance:" + event.values[0] + "");
          params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
          params.screenBrightness = 0;
          getWindow().setAttributes(params);*/
            if (!mProximityWakeLock.isHeld()) {
                mProximityWakeLock.acquire();
            }
        } else {
            if (mProximityWakeLock.isHeld()) {
                mProximityWakeLock.release();
            }
        /*params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
          params.screenBrightness = -1f;
          getWindow().setAttributes(params);*/
        }
      /*try {
        // Yeah, this is hidden field.
        //int field = PowerManager.class.getClass().getField("PROXIMITY_SCREEN_OFF_WAKE_LOCK").getInt(null);
      } catch (Throwable ignored) {

      }*/
    }
}
 
Example 8
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 5 votes vote down vote up
public static float getMinimumValueForSensor(Sensor sensor) {
    float minimumValue;
    switch (sensor.getType()) {
        case Sensor.TYPE_HEART_RATE:
        case Sensor.TYPE_LIGHT:
        case Sensor.TYPE_PROXIMITY:
        case Sensor.TYPE_STEP_COUNTER:
        case Sensor.TYPE_PRESSURE:
            minimumValue = 0;
            break;
        default:
            minimumValue = -sensor.getMaximumRange();
    }
    return minimumValue;
}
 
Example 9
Source File: Reminders.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
        proximity_events++;
        if (proximity_events < 20)
            Log.d(TAG, "Sensor: " + event.values[0] + " " + mProximity.getMaximumRange());
        if (event.values[0] <= (Math.min(mProximity.getMaximumRange() / 2, 10))) {
            proximity = true; // near
        } else {
            proximity = false; // far
        }
        if (proximity_events < 20) Log.d(TAG, "Proxmity set to: " + proximity);
    }
}
 
Example 10
Source File: SensorDetailFragment.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
private void populateTypeField( int type ) {
	if( type == 0 || mTypeRow == null || mType == null )
		return;

	String typeName;

	switch( type ) {
		case Sensor.TYPE_ACCELEROMETER: {
			typeName = "Accelerometer";
			break;
		}
		case Sensor.TYPE_AMBIENT_TEMPERATURE: {
			typeName = "Ambient Temperature";
			break;
		}
		case Sensor.TYPE_GAME_ROTATION_VECTOR: {
			typeName = "Game Rotation Vector";
			break;
		}
		case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR: {
			typeName = "Geomagnetic Rotation Vector";
			break;
		}
		case Sensor.TYPE_GRAVITY: {
			typeName = "Gravity";
			break;
		}
		case Sensor.TYPE_GYROSCOPE: {
			typeName = "Gyroscope";
			break;
		}
		case Sensor.TYPE_GYROSCOPE_UNCALIBRATED: {
			typeName = "Uncalibrated Gyroscope";
			break;
		}
		case Sensor.TYPE_LIGHT: {
			typeName = "Light";
			break;
		}
		case Sensor.TYPE_LINEAR_ACCELERATION: {
			typeName = "Linear Acceleration";
			break;
		}
		case Sensor.TYPE_MAGNETIC_FIELD: {
			typeName = "Magnetic Field";
			break;
		}
		case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED: {
			typeName = "Uncalibrated Magnetic Field";
			break;
		}
		case Sensor.TYPE_PRESSURE: {
			typeName = "Pressure";
			break;
		}
		case Sensor.TYPE_PROXIMITY: {
			typeName = "Proximity";
			break;
		}
		case Sensor.TYPE_RELATIVE_HUMIDITY: {
			typeName = "Relative Humidity";
			break;
		}
		case Sensor.TYPE_ROTATION_VECTOR: {
			typeName = "Rotation Vector";
			break;
		}
		case Sensor.TYPE_SIGNIFICANT_MOTION: {
			typeName = "Significant Motion";
			break;
		}
		case Sensor.TYPE_STEP_COUNTER: {
			typeName = "Step Counter";
			break;
		}
		case Sensor.TYPE_STEP_DETECTOR: {
			typeName = "Step Detector";
			break;
		}
		default: {
			typeName = "Other";
		}
	}
	mType.setText( typeName );
	mTypeRow.setVisibility( View.VISIBLE );
}
 
Example 11
Source File: XSensorManager.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean isRestricted(XParam param, int type) throws Throwable {
	if (type == Sensor.TYPE_ALL)
		return false;
	else if (type == Sensor.TYPE_ACCELEROMETER || type == Sensor.TYPE_LINEAR_ACCELERATION) {
		if (isRestricted(param, "acceleration"))
			return true;
	} else if (type == Sensor.TYPE_GRAVITY) {
		if (isRestricted(param, "gravity"))
			return true;
	} else if (type == Sensor.TYPE_RELATIVE_HUMIDITY) {
		if (isRestricted(param, "humidity"))
			return true;
	} else if (type == Sensor.TYPE_LIGHT) {
		if (isRestricted(param, "light"))
			return true;
	} else if (type == Sensor.TYPE_MAGNETIC_FIELD || type == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
		if (isRestricted(param, "magnetic"))
			return true;
	} else if (type == Sensor.TYPE_SIGNIFICANT_MOTION) {
		if (isRestricted(param, "motion"))
			return true;
	} else if (type == Sensor.TYPE_ORIENTATION || type == Sensor.TYPE_GYROSCOPE
			|| type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
		if (isRestricted(param, "orientation"))
			return true;
	} else if (type == Sensor.TYPE_PRESSURE) {
		if (isRestricted(param, "pressure"))
			return true;
	} else if (type == Sensor.TYPE_PROXIMITY) {
		if (isRestricted(param, "proximity"))
			return true;
	} else if (type == Sensor.TYPE_GAME_ROTATION_VECTOR || type == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR
			|| type == Sensor.TYPE_ROTATION_VECTOR) {
		if (isRestricted(param, "rotation"))
			return true;
	} else if (type == Sensor.TYPE_TEMPERATURE || type == Sensor.TYPE_AMBIENT_TEMPERATURE) {
		if (isRestricted(param, "temperature"))
			return true;
	} else if (type == Sensor.TYPE_STEP_COUNTER || type == Sensor.TYPE_STEP_DETECTOR) {
		if (isRestricted(param, "step"))
			return true;
	} else if (type == Sensor.TYPE_HEART_RATE) {
		if (isRestricted(param, "heartrate"))
			return true;
	} else if (type == 22) {
		// 22 = TYPE_TILT_DETECTOR
		// Do nothing
	} else if (type == 23 || type == 24 || type == 25) {
		// 23 = TYPE_WAKE_GESTURE
		// 24 = TYPE_GLANCE_GESTURE
		// 25 = TYPE_PICK_UP_GESTURE
		// 23/24 This sensor is expected to only be used by the system ui
		// 25 Expected to be used internally for always on display
	} else
		Util.log(this, Log.WARN, "Unknown sensor type=" + type);
	return false;
}
 
Example 12
Source File: ProximitySensor.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getType() {
    return Sensor.TYPE_PROXIMITY;
}
 
Example 13
Source File: MainActivity.java    From journaldev with MIT License 4 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == currentSensor) {

        if (currentSensor == Sensor.TYPE_LIGHT) {
            float valueZ = event.values[0];
            textView.setText("Brightness " + valueZ);
        } else if (currentSensor == Sensor.TYPE_PROXIMITY) {
            float distance = event.values[0];
            textView.setText("Proximity " + distance);
        } else if (currentSensor == Sensor.TYPE_STEP_DETECTOR) {
            float steps = event.values[0];
            textView.setText("Steps : " + steps);
        } else if (currentSensor == Sensor.TYPE_ACCELEROMETER) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];

            long curTime = System.currentTimeMillis();

            if ((curTime - lastUpdate) > 100) {
                long diffTime = (curTime - lastUpdate);
                lastUpdate = curTime;

                float speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;

                if (speed > SHAKE_THRESHOLD) {
                    Toast.makeText(getApplicationContext(), "Your phone just shook", Toast.LENGTH_LONG).show();
                }

                last_x = x;
                last_y = y;
                last_z = z;
            }
        } else if (currentSensor == Sensor.TYPE_GYROSCOPE) {
            if (event.values[2] > 0.5f) {
                textView.setText("Anti Clock");
            } else if (event.values[2] < -0.5f) {
                textView.setText("Clock");
            }
        } else if (currentSensor == Sensor.TYPE_AMBIENT_TEMPERATURE) {
            textView.setText("Ambient Temp in Celsius :" + event.values[0]);
        }

    }

}
 
Example 14
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
public static String[] getLabelsForSensor(Context context, Sensor sensor) {
    String[] labels;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            labels = context.getResources().getStringArray(R.array.accelerometer_values);
            break;
        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            labels = context.getResources().getStringArray(R.array.ambient_temperature_values);
            break;
        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.game_rotation_vector_values);
            break;
        case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.rotation_vector_values);
            break;
        case Sensor.TYPE_GRAVITY:
            labels = context.getResources().getStringArray(R.array.gravity_values);
            break;
        case Sensor.TYPE_GYROSCOPE:
            labels = context.getResources().getStringArray(R.array.gyroscore_values);
            break;
        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            labels = context.getResources().getStringArray(R.array.gyroscore_uncalibrated_values);
            break;
        case Sensor.TYPE_HEART_RATE:
            labels = context.getResources().getStringArray(R.array.heart_rate_values);
            break;
        case Sensor.TYPE_LIGHT:
            labels = context.getResources().getStringArray(R.array.light_values);
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            labels = context.getResources().getStringArray(R.array.linear_acceleration_values);
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            labels = context.getResources().getStringArray(R.array.magnetic_values);
            break;
        case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
            labels = context.getResources().getStringArray(R.array.magnetic_field_uncalibrated_values);
            break;
        case Sensor.TYPE_PRESSURE:
            labels = context.getResources().getStringArray(R.array.pressure_values);
            break;
        case Sensor.TYPE_PROXIMITY:
            labels = context.getResources().getStringArray(R.array.proximity_values);
            break;
        case Sensor.TYPE_RELATIVE_HUMIDITY:
            labels = context.getResources().getStringArray(R.array.relative_humidity_values);
            break;
        case Sensor.TYPE_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.rotation_vector_values);
            break;
        case Sensor.TYPE_STEP_COUNTER:
            labels = context.getResources().getStringArray(R.array.step_counter_values);
            break;
        default:
            labels = new String[]{};
    }
    return labels;
}
 
Example 15
Source File: PProximity.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public PProximity(AppRunner appRunner) {
    super(appRunner);

    type = Sensor.TYPE_PROXIMITY;
}
 
Example 16
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
public static String getDescription(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), including the force of gravity.";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Measures the ambient room temperature in degrees Celsius (°C).";

        case Sensor.TYPE_GRAVITY:
            return "Measures the force of gravity in m/s² that is applied to a device on all three physical axes (x, y, z).";

        case Sensor.TYPE_GYROSCOPE:
            return "Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z).";

        case Sensor.TYPE_HEART_RATE:
            return "Measures heart rate.";

        case Sensor.TYPE_LIGHT:
            return "Measures the ambient light level (illumination) in lx.";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity.";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT.";

        case Sensor.TYPE_PRESSURE:
            return "Measures the ambient air pressure in hPa or mbar.";

        case Sensor.TYPE_PROXIMITY:
            return "Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear.";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Measures the relative ambient humidity in percent (%).";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Measures the orientation of a device by providing the three elements of the device's rotation vector.";

        case Sensor.TYPE_ORIENTATION:
            return "Measures degrees of rotation that a device makes around all three physical axes (x, y, z). ";

        case Sensor.TYPE_TEMPERATURE:
            return "Measures the temperature of the device in degrees Celsius (°C). ";

        default:
            return "Information about this sensor is unavailable.";
    }
}
 
Example 17
Source File: MainActivity.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Called when a sensor's reading changes. Updates sensor display and rotates sky plot according
   * to bearing.
   */
  public void onSensorChanged(SensorEvent event) {
//to enforce sensor rate
boolean isRateElapsed = false;

switch (event.sensor.getType()) {
	case Sensor.TYPE_ACCELEROMETER:
		isRateElapsed = (event.timestamp / 1000) - mAccLast >= iSensorRate;
		// if Z acceleration is greater than X/Y combined, lock rotation, else unlock
		if (Math.pow(event.values[2], 2) > Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2)) {
			// workaround (SCREEN_ORIENTATION_LOCK is unsupported on API < 18)
			if (isWideScreen)
				setRequestedOrientation(OR_FROM_ROT_WIDE[this.getWindowManager().getDefaultDisplay().getRotation()]);
			else
				setRequestedOrientation(OR_FROM_ROT_TALL[this.getWindowManager().getDefaultDisplay().getRotation()]);
		} else {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
		}
		break;
	case Sensor.TYPE_ORIENTATION:
		isRateElapsed = (event.timestamp / 1000) - mOrLast >= iSensorRate;
		break;
	case Sensor.TYPE_GYROSCOPE:
		isRateElapsed = (event.timestamp / 1000) - mGyroLast >= iSensorRate;
		break;
	case Sensor.TYPE_MAGNETIC_FIELD:
		isRateElapsed = (event.timestamp / 1000) - mMagLast >= iSensorRate;
		break;
	case Sensor.TYPE_LIGHT:
		isRateElapsed = (event.timestamp / 1000) - mLightLast >= iSensorRate;
		break;
	case Sensor.TYPE_PROXIMITY:
		isRateElapsed = (event.timestamp / 1000) - mProximityLast >= iSensorRate;
		break;
	case Sensor.TYPE_PRESSURE:
		isRateElapsed = (event.timestamp / 1000) - mPressureLast >= iSensorRate;
		break;
	case Sensor.TYPE_RELATIVE_HUMIDITY:
		isRateElapsed = (event.timestamp / 1000) - mHumidityLast >= iSensorRate;
		break;
	case Sensor.TYPE_AMBIENT_TEMPERATURE:
		isRateElapsed = (event.timestamp / 1000) - mTempLast >= iSensorRate;
		break;
}

if (!isRateElapsed)
	return;

switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
	mAccLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_ORIENTATION:
	mOrLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_GYROSCOPE:
	mGyroLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_MAGNETIC_FIELD:
	mMagLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_LIGHT:
	mLightLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_PROXIMITY:
	mProximityLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_PRESSURE:
	mPressureLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_RELATIVE_HUMIDITY:
	mHumidityLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_AMBIENT_TEMPERATURE:
	mTempLast = event.timestamp / 1000;
	break;
}


if (sensorSectionFragment != null) {
	sensorSectionFragment.onSensorChanged(event);
  	}
if (gpsSectionFragment != null) {
	gpsSectionFragment.onSensorChanged(event);
}
  }
 
Example 18
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
@Nullable
public static String getHumanStringType(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Accelerometer";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Ambient Temperature";

        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            return "Game Rotation Vector";

        case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            return "Geomagnetic Rotation Vector";

        case Sensor.TYPE_GRAVITY:
            return "Gravity";

        case Sensor.TYPE_GYROSCOPE:
            return "Gyroscope";

        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            return "Gyroscope (Uncalibrated)";

        case Sensor.TYPE_HEART_RATE:
            return "Heart Rate";

        case Sensor.TYPE_LIGHT:
            return "Light";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Linear Acceleration";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Magnetic Field";

        case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
            return "Magnetic Field (Uncalibrated)";

        case Sensor.TYPE_PRESSURE:
            return "Pressure";

        case Sensor.TYPE_PROXIMITY:
            return "Proximity";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Relative Humidity";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Rotation Vector";

        case Sensor.TYPE_SIGNIFICANT_MOTION:
            return "Significant Motion";

        case Sensor.TYPE_STEP_COUNTER:
            return "Step Counter";

        case Sensor.TYPE_STEP_DETECTOR:
            return "Step Detector";

        case Sensor.TYPE_ORIENTATION:
            return "Orientation";

        case Sensor.TYPE_TEMPERATURE:
            return "Temperature";
    }
    return null;
}
 
Example 19
Source File: ProximitySensor.java    From SensorsAndAi with MIT License 4 votes vote down vote up
public void onSensorChanged(SensorEvent sensorEvent) {
    if (sensorEvent.sensor.getType( ) == Sensor.TYPE_PROXIMITY){
        textView.setText(""+ sensorEvent.values[0]);
    }

}
 
Example 20
Source File: AudioSlidePlayer.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() != Sensor.TYPE_PROXIMITY)
        return;
    if (mediaPlayer == null || !mediaPlayer.isPlaying())
        return;

    int streamType;

    if (event.values[0] < 5f && event.values[0] != proximitySensor.getMaximumRange()) {
        streamType = AudioManager.STREAM_VOICE_CALL;
    } else {
        streamType = AudioManager.STREAM_MUSIC;
    }

    if (streamType == AudioManager.STREAM_VOICE_CALL &&
            mediaPlayer.getAudioStreamType() != streamType &&
            !audioManager.isWiredHeadsetOn()) {
        double position = mediaPlayer.getCurrentPosition();
        double duration = mediaPlayer.getDuration();
        double progress = position / duration;

        Logger.d("AudioSlidePlayer onSensorChanged, replay");
        if (wakeLock != null)
            wakeLock.acquire();
        stop(true);
        try {
            if (forSensor) {
                play(progress, true);
            } else if (wakeLock != null) {
                wakeLock.release();
            }
        } catch (IOException e) {
            Log.w(TAG, e);
        }
    } else if (streamType == AudioManager.STREAM_MUSIC &&
            mediaPlayer.getAudioStreamType() != streamType &&
            System.currentTimeMillis() - startTime > 500) {

        Logger.d("AudioSlidePlayer onSensorChanged, stop");
        if (wakeLock != null)
            wakeLock.release();
        stop();
        notifyOnStop();
    }
}