Code example for Sensor

Methods: getType

0
 
	@Override 
	public void onSensorChanged(SensorEvent event) {
		final float[] values = event.values;
		final Sensor sensor = event.sensor;
		if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			long curTime = System.currentTimeMillis();
			// only allow one update every 100ms. 
			if ((curTime - lastUpdate) > 100) {
				lastUpdate = curTime;
				// must be x-oriented 
				if ((Math.abs(values[0]) < Math.abs(values[1]) || (Math
						.abs(values[0]) < Math.abs(values[2])))) {
					free_frame_cnt++;
					// clear status every 0.3 seconds 
					if (free_frame_cnt >= 3) {
						mDirection = Direction.UNDETERMINED;
						free_frame_cnt = 0;
					} 
					return; 
				}