Java Code Examples for android.hardware.SensorEventListener

The following are top voted examples for showing how to use android.hardware.SensorEventListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Checkerboard-IMU-Comparator   File: SensorInitializer.java   View source code 7 votes vote down vote up
public void initializeSensor(Context context){
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    magneticValues = new float[3];
    accelerationValues = new float[3];
    orientationValues = new float[3];
    rotationMatrix = new float[9];
    final SensorEventListener mEventListener = new SensorEventListener() {
        public void onAccuracyChanged(android.hardware.Sensor sensor, int accuracy) {}
        public void onSensorChanged(SensorEvent event) {
            switch (event.sensor.getType()) {
                case android.hardware.Sensor.TYPE_ACCELEROMETER:
                    System.arraycopy(event.values, 0, accelerationValues, 0, 3);
                    break;
                case android.hardware.Sensor.TYPE_MAGNETIC_FIELD:
                    System.arraycopy(event.values, 0, magneticValues, 0, 3);
                    break;
            }
        }
    };
    setListeners(sensorManager, mEventListener);
}
 
Example 2
Project: ShakeItUpCodelab   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    audioPlayer = new AudioPlayer();
    audioPlayer.init(this, R.raw.ska_trek);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    sensorEventListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(final SensorEvent event) {
            Log.e(TAG, "" + event.timestamp);
            xValue.onNext(event.values[0]);
            yValue.onNext(event.values[1]);
            zValue.onNext(event.values[2]);
        }

        @Override
        public void onAccuracyChanged(final Sensor sensor, final int accuracy) {
            //No op
        }
    };
}
 
Example 3
Project: engine-stereo   File: BeeSensorProcessor.java   View source code 6 votes vote down vote up
@SuppressLint("InlinedApi")
public BeeSensorProcessor(Context context, SensorEventListener listener) {
	sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
	// checking for sensors
	if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) == null) {
		accelerometerEnabled = false;
	}
	if (sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) == null) {
		gyroscopeEnabled = false;
	}

	if (accelerometerEnabled && gyroscopeEnabled) {
		sensorRotation = sensorManager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR);
		if (sensorRotation == null) {
			versionCompatible = false;
		}
		if (versionCompatible) {
			sensorEnabled = true;
			sensorManager.registerListener(listener, sensorRotation, 0);
			quaternionFromEuler(diffQuaternion, new float[] { 0, 90, 180 });
			this.listener = listener;
		}
	}
}
 
Example 4
Project: engine-stereo   File: KalmanProcessor.java   View source code 6 votes vote down vote up
public KalmanProcessor(Context context, SensorEventListener listener) {
	sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
	accelerationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
	sensorManager.registerListener(listener, accelerationSensor, 0);
	gyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
	sensorManager.registerListener(listener, gyroSensor, 0);

	if (accelerationSensor != null && gyroSensor != null) {
		this.listener = listener;
		sensorEnabled = true;
	}

	gyroOrientation[0] = 0.0f;
	gyroOrientation[1] = 0.0f;
	gyroOrientation[2] = 0.0f;

	gyroMatrix[0] = 1.0f;
	gyroMatrix[1] = 0.0f;
	gyroMatrix[2] = 0.0f;
	gyroMatrix[3] = 0.0f;
	gyroMatrix[4] = 1.0f;
	gyroMatrix[5] = 0.0f;
	gyroMatrix[6] = 0.0f;
	gyroMatrix[7] = 0.0f;
	gyroMatrix[8] = 1.0f;
}
 
Example 5
Project: GestureWave   File: SensorService.java   View source code 6 votes vote down vote up
private BroadcastReceiver setScreenStateReceiver(final SensorEventListener sensorEventListener)
{
	return new BroadcastReceiver()
	{
		@Override
		public void onReceive(Context context, Intent intent)
		{
			//HANDLES SCREEN ON/OFF ACTIONS
			if(intent.getAction().equals(Intent.ACTION_SCREEN_ON))
			{
				//RE-REGISTERS PROXIMITY SENSOR LISTENER WHEN SCREEN IS ON TO ACCEPT USER INPUT
				sensorManager.registerListener(sensorEventListener, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
				statusBarDown = false;
			}
			else if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
			{
				//LOCKS THE SCREEN WHEN SCREEN IS OFF AND NOT IN A PHONE CALL
				if(audioManager.getMode() != AudioManager.MODE_IN_CALL)
					getSystemService(Context.DEVICE_POLICY_SERVICE);

				//UNREGISTERS PROXIMITY SENSOR LISTENER WHEN SCREEN IS OFF TO PREVENT USER INPUT
				sensorManager.unregisterListener(sensorEventListener, proximitySensor);
			}
		}
	};
}
 
Example 6
Project: xDrip   File: Reminders.java   View source code 6 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    Log.d(TAG, "onPause");
    final SensorEventListener activity = this;

    JoH.runOnUiThreadDelayed(new Runnable() {
        @Override
        public void run() {
            Log.d(TAG, "Unregistering proximity sensor listener");
            try {
                mSensorManager.unregisterListener(activity);
            } catch (Exception e) {
                Log.d(TAG, "Error unregistering proximity listener: " + e);
            }
        }
    }, 10000);
}
 
Example 7
Project: VirtualSensor   File: API24.java   View source code 6 votes vote down vote up
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
    SensorEventListener listener = (SensorEventListener) XposedHelpers.getObjectField(param.thisObject, "mListener");
    int handle = (int) param.args[0];
    Object mgr = XposedHelpers.getObjectField(param.thisObject, "mManager");
    HashMap<Integer, Sensor> sensors = (HashMap<Integer, Sensor>) XposedHelpers.getObjectField(mgr, "mHandleToSensor");
    Sensor s = sensors.get(handle);

    if (listener instanceof VirtualSensorListener) {
        float[] values = this.mSensorChange.handleListener(s, (VirtualSensorListener) listener, ((float[]) param.args[1]).clone(), (int) param.args[2], (long) param.args[3], XposedMod.ACCELEROMETER_RESOLUTION, XposedMod.MAGNETIC_RESOLUTION);
        if (values != null) {
            System.arraycopy(values, 0, param.args[1], 0, values.length);
            param.args[0] = XposedMod.sensorTypetoHandle.get(((VirtualSensorListener) listener).getSensor().getType());
        }// else param.setResult(null);
    }
}
 
Example 8
Project: VirtualSensor   File: API23.java   View source code 6 votes vote down vote up
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
    SensorEventListener listener = (SensorEventListener) XposedHelpers.getObjectField(param.thisObject, "mListener");
    int handle = (int) param.args[0];
    Object mgr = XposedHelpers.getObjectField(param.thisObject, "mManager");
    SparseArray<Sensor> sensors = (SparseArray<Sensor>) XposedHelpers.getObjectField(mgr, "mHandleToSensor");
    Sensor s = sensors.get(handle);

    if (listener instanceof VirtualSensorListener) {
        float[] values = this.mSensorChange.handleListener(s, (VirtualSensorListener) listener, ((float[]) param.args[1]).clone(), (int) param.args[2], (long) param.args[3], XposedMod.ACCELEROMETER_RESOLUTION, XposedMod.MAGNETIC_RESOLUTION);
        if (values != null) {
            System.arraycopy(values, 0, param.args[1], 0, values.length);
            param.args[0] = XposedMod.sensorTypetoHandle.get(((VirtualSensorListener) listener).getSensor().getType());
        }// else param.setResult(null);
    }
}
 
Example 9
Project: BikeHelper   File: DirectionUtils.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static void initialize(Context context) {
    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            mDirection = event.values[0];
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }

    };
}
 
Example 10
Project: ParrotModFloApp   File: MyService.java   View source code 6 votes vote down vote up
@Override
public void run() {
    mSensorEventListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {
            changed = System.currentTimeMillis();
            handler.postDelayed(mRunnable1, 300); // ms
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // don't need it
        }
    };
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    filter.addAction("android.intent.action.HDMI_PLUGGED");
    registerReceiver(mReceiver, filter);
    register();

}
 
Example 11
Project: RxSensorManager   File: RxSensorManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testObserveSensor() throws Exception {
    setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 9);
    when(mockSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)).thenReturn(mockSensor);
    final int numberOfEventsToSend = 5;
    final ArgumentCaptor<SensorEventListener> argumentCaptor = ArgumentCaptor.forClass(SensorEventListener.class);
    when(mockSensorManager.registerListener(
            argumentCaptor.capture(),
            eq(mockSensor),
            eq(0)
    )).thenAnswer(new Answer<Boolean>() {
        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            for (int i = 0; i < numberOfEventsToSend; ++i) {
                argumentCaptor.getValue().onSensorChanged(mock(SensorEvent.class));
            }
            return true;
        }
    });
    rxSensorManager.observeSensor(Sensor.TYPE_ACCELEROMETER, 0)
            .test()
            .assertValueCount(numberOfEventsToSend);
}
 
Example 12
Project: RxSensorManager   File: RxSensorManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testObserveSensorAccuracy() throws Exception {
    setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 9);
    when(mockSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)).thenReturn(mockSensor);
    final int numberOfEventsToSend = 5;
    final ArgumentCaptor<SensorEventListener> argumentCaptor = ArgumentCaptor.forClass(SensorEventListener.class);
    when(mockSensorManager.registerListener(
            argumentCaptor.capture(),
            eq(mockSensor),
            eq(0)
    )).thenAnswer(new Answer<Boolean>() {
        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            for (int i = 0; i < numberOfEventsToSend; ++i) {
                argumentCaptor.getValue().onAccuracyChanged(mockSensor, SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
            }
            return true;
        }
    });
    rxSensorManager.observeSensorAccuracy(Sensor.TYPE_ACCELEROMETER, 0)
            .test()
            .assertValueCount(numberOfEventsToSend);
}
 
Example 13
Project: AndroidSchool   File: RxSensor.java   View source code 6 votes vote down vote up
@NonNull
public static Observable<SensorEvent> observeSensorChanged(final SensorManager sensorManager,
                                                           final Sensor sensor, final int samplingPeriodUs) {
    return Observable.fromEmitter(new Action1<AsyncEmitter<SensorEvent>>() {
        @Override
        public void call(final AsyncEmitter<SensorEvent> sensorEventAsyncEmitter) {
            final SensorEventListener sensorListener = new SensorEventListener() {
                @Override
                public void onSensorChanged(SensorEvent sensorEvent) {
                    sensorEventAsyncEmitter.onNext(sensorEvent);
                }

                @Override
                public void onAccuracyChanged(Sensor originSensor, int i) {
                    // do nothing
                }
            };

            sensorEventAsyncEmitter.setCancellation(() -> sensorManager.unregisterListener(sensorListener, sensor));
            sensorManager.registerListener(sensorListener, sensor, samplingPeriodUs);
        }
    }, AsyncEmitter.BackpressureMode.LATEST);
}
 
Example 14
Project: BikeHelper   File: DirectionUtils.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static void initialize(Context context) {
    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            mDirection = event.values[0];
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }

    };
}
 
Example 15
Project: dslink-java-android   File: StepsProvider.java   View source code 6 votes vote down vote up
@Override
public void setup() {
    eventListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(final SensorEvent sensorEvent) {
            update(new HashMap<String, Object>() {{
                put("value", sensorEvent.values[0]);
            }});
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }
    };
    LinkService.INSTANCE.sensorManager.registerListener(eventListener, LinkService.INSTANCE.sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), SensorManager.SENSOR_DELAY_NORMAL);
    setEnabled();
}
 
Example 16
Project: dslink-java-android   File: GyroscopeProvider.java   View source code 6 votes vote down vote up
@Override
public void setup() {
    eventListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(final SensorEvent sensorEvent) {
            update(new HashMap<String, Object>() {{
                put("X", sensorEvent.values[0]);
                put("Y", sensorEvent.values[1]);
                put("Z", sensorEvent.values[2]);
            }});
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int i) {
        }
    };

    LinkService.INSTANCE.sensorManager.registerListener(eventListener, LinkService.INSTANCE.sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_NORMAL);
    setEnabled();
}
 
Example 17
Project: WearableDataServer   File: ShadowSensorUnit.java   View source code 6 votes vote down vote up
@Implementation
public boolean listenSensor() {
    listener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {

        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    };
    shadow.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    if (shadow.hasListener(listener)) {
        return true;
    } else {
        return false;
    }
}
 
Example 18
Project: AndroidLibraryProject   File: AccelerometerDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to enable disable Accelerometer Sensor in Android
 */
public void disableAccelerometerListener(SensorEventListener listenerFromActivity)
{	
	try
	{
		if(listenerFromActivity!=null)
			mSensorManager.unregisterListener(listenerFromActivity);
		else
		{
			if(enableDebugging)
				Log.d(TAG,"listenerFromActivity is null");
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 19
Project: AndroidLibraryProject   File: LightDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to disable Light Sensor in Android
 * @param listenerFromActivity 
 * */
public void disableLightSensor(SensorEventListener listenerFromActivity)
{
	try
	{
		if(mSensorManager != null)
		{
			if(listenerFromActivity!=null)
				mSensorManager.unregisterListener(listenerFromActivity);
			else
			{
				if(enableDebugging)
					Log.d(TAG,"listenerFromActivity is null");
			}
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 20
Project: AndroidLibraryProject   File: ProximityDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to disable Proximity Sensor in Android
 */
public void disableProximitySensor(SensorEventListener listenerFromActivity)
{
	try
	{			
		if(mSensorManager != null)
		{
			if(listenerFromActivity!=null)
				mSensorManager.unregisterListener(listenerFromActivity);
			else
			{
				if(enableDebugging)
					Log.d(TAG,"listenerFromActivity is null");
			}
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 21
Project: AndroidLibraryProject   File: GyroscopeDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to enable disable Gyroscope Sensor in Android
 */
public void disableGyroscopeListener(SensorEventListener listenerFromActivity)
{	
	try
	{
		if(listenerFromActivity!=null)
			mSensorManager.unregisterListener(listenerFromActivity);
		else
		{
			if(enableDebugging)
				Log.d(TAG,"listenerFromActivity is null");
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 22
Project: AndroidLibraryProject   File: MagnetometerDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to enable disable Magnetometer Sensor in Android
 */
public void disableMagnetometerListener(SensorEventListener listenerFromActivity)
{	
	try
	{
		if(listenerFromActivity!=null)
			mSensorManager.unregisterListener(listenerFromActivity);
		else
		{
			if(enableDebugging)
				Log.d(TAG,"listenerFromActivity is null");
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 23
Project: AndroidLibraryProject   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Gyroscope 
 */
public final void unregisterMagnetometerService(SensorEventListener listenerfromMainApp) throws MagnetometerSensorException
{		
	if(listenerfromMainApp!=null)
	{	
		if(gyroscope!=null)
		{
			gyroscope.disableGyroscopeListener(listenerfromMainApp);
			CAFConfig.setSensorGyroscope(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Gyroscope Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}

}
 
Example 24
Project: AndroidLibraryProject   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Gyroscope 
 */
public final void unregisterGyroscopeService(SensorEventListener listenerfromMainApp) throws GyrometerSensorException
{		
	if(listenerfromMainApp!=null)
	{	
		if(gyroscope!=null)
		{
			gyroscope.disableGyroscopeListener(listenerfromMainApp);
			CAFConfig.setSensorGyroscope(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Gyroscope Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}

}
 
Example 25
Project: AndroidLibraryProject   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Accelerometer 
 */
public final void unregisterAccelerometerService(SensorEventListener listenerfromMainApp) throws AccelerometerSensorException
{		
	if(listenerfromMainApp!=null)
	{	
		if(accel!=null)
		{
			accel.disableAccelerometerListener(listenerfromMainApp);
			CAFConfig.setSensorAccelerometer(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Accelerometer Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}

}
 
Example 26
Project: AndroidLibraryProject   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Proximity Service
 */
public final void unregisterProximityService(SensorEventListener listenerfromMainApp) throws ProximitySensorException
{
	if(listenerfromMainApp!=null)
	{
		if(proximity!=null)
		{
				proximity.disableProximitySensor(listenerfromMainApp);
				CAFConfig.setSensorProximity(false);
				if(enableDebugging)
					Log.d(TAG,"Unregister Proximity Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}
}
 
Example 27
Project: AndroidLibraryProject   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Light sensor Service
 */
public final void unregisterLightService(SensorEventListener listenerfromMainApp) throws LightSensorException
{
	if(listenerfromMainApp!=null)
	{
		if(light!=null)
		{
			light.disableLightSensor(listenerfromMainApp);
			CAFConfig.setSensorLight(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Light Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}
}
 
Example 28
Project: contextawareframework   File: AccelerometerDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to enable disable Accelerometer Sensor in Android
 */
public void disableAccelerometerListener(SensorEventListener listenerFromActivity)
{	
	try
	{
		if(listenerFromActivity!=null)
			mSensorManager.unregisterListener(listenerFromActivity);
		else
		{
			if(enableDebugging)
				Log.d(TAG,"listenerFromActivity is null");
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 29
Project: contextawareframework   File: LightDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to disable Light Sensor in Android
 * @param listenerFromActivity 
 * */
public void disableLightSensor(SensorEventListener listenerFromActivity)
{
	try
	{
		if(mSensorManager != null)
		{
			if(listenerFromActivity!=null)
				mSensorManager.unregisterListener(listenerFromActivity);
			else
			{
				if(enableDebugging)
					Log.d(TAG,"listenerFromActivity is null");
			}
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 30
Project: contextawareframework   File: ProximityDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to disable Proximity Sensor in Android
 */
public void disableProximitySensor(SensorEventListener listenerFromActivity)
{
	try
	{			
		if(mSensorManager != null)
		{
			if(listenerFromActivity!=null)
				mSensorManager.unregisterListener(listenerFromActivity);
			else
			{
				if(enableDebugging)
					Log.d(TAG,"listenerFromActivity is null");
			}
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 31
Project: contextawareframework   File: GyroscopeDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to disable Gyroscope Sensor in Android
 */
public void disableGyroscopeListener(SensorEventListener listenerFromActivity)
{	
	try
	{
		if(listenerFromActivity!=null)
		{	mSensorManager.unregisterListener(listenerFromActivity);
			//if(enableDebugging)
				//Log.d(TAG,"unregistering Gyroscope Sensor");
		}
		else
		{
			if(enableDebugging)
				Log.d(TAG,"listenerFromActivity is null");
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 32
Project: contextawareframework   File: MagnetometerDataListener.java   View source code 6 votes vote down vote up
/**
 * Method to enable disable Magnetometer Sensor in Android
 */
public void disableMagnetometerListener(SensorEventListener listenerFromActivity)
{	
	try
	{
		if(listenerFromActivity!=null)
			mSensorManager.unregisterListener(listenerFromActivity);
		else
		{
			if(enableDebugging)
				Log.d(TAG,"listenerFromActivity is null");
		}
	}
	catch(NullPointerException e)
	{
		e.printStackTrace();
	}
}
 
Example 33
Project: contextawareframework   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Magnetometer 
 */
public final void unregisterMagnetometerService(SensorEventListener listenerfromMainApp) throws MagnetometerSensorException
{		
	if(listenerfromMainApp!=null)
	{	
		if(magnetometer!=null)
		{
			magnetometer.disableMagnetometerListener(listenerfromMainApp);
			CAFConfig.setSensorMagnetometer(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Magnetometer Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}

}
 
Example 34
Project: contextawareframework   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Gyroscope 
 */
public final void unregisterGyroscopeService(SensorEventListener listenerfromMainApp) throws GyrometerSensorException
{		
	if(listenerfromMainApp!=null)
	{	
		if(gyroscope!=null)
		{
			gyroscope.disableGyroscopeListener(listenerfromMainApp);
			CAFConfig.setSensorGyroscope(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Gyroscope Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}

}
 
Example 35
Project: contextawareframework   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Accelerometer 
 */
public final void unregisterAccelerometerService(SensorEventListener listenerfromMainApp) throws AccelerometerSensorException
{		
	if(listenerfromMainApp!=null)
	{	
		if(accel!=null)
		{
			accel.disableAccelerometerListener(listenerfromMainApp);
			CAFConfig.setSensorAccelerometer(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Accelerometer Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}

}
 
Example 36
Project: contextawareframework   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Proximity Service
 */
public final void unregisterProximityService(SensorEventListener listenerfromMainApp) throws ProximitySensorException
{
	if(listenerfromMainApp!=null)
	{
		if(proximity!=null)
		{
				proximity.disableProximitySensor(listenerfromMainApp);
				CAFConfig.setSensorProximity(false);
				if(enableDebugging)
					Log.d(TAG,"Unregister Proximity Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}
}
 
Example 37
Project: contextawareframework   File: SensorController.java   View source code 6 votes vote down vote up
/**
 * To un-register the Light sensor Service
 */
public final void unregisterLightService(SensorEventListener listenerfromMainApp) throws LightSensorException
{
	if(listenerfromMainApp!=null)
	{
		if(light!=null)
		{
			light.disableLightSensor(listenerfromMainApp);
			CAFConfig.setSensorLight(false);
			if(enableDebugging)
				Log.d(TAG,"Unregister Light Sensor");
		}
	}
	else
	{
		Log.d(TAG,"listenerfromMainApp is null");
	}
}
 
Example 38
Project: Flyver-Apps   File: MainControl.java   View source code 6 votes vote down vote up
/**
 * Registers to the orientation sensors of the phone
 */
public void registerToSensors() {
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    Sensor orientationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mSensorManager.registerListener(new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {
            //if the Start button is released, do not send data to the server
            if (mSendData) {
                jsonQuadruple = new Quadruple<>(COORDINATES, event.values[0], event.values[2], event.values[1]);
                jsonIntent.putExtra("json", JSONUtils.serialize(jsonQuadruple, jsonQuadrupleTypes));
                sendBroadcast(jsonIntent);
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    }, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
 
Example 39
Project: Flight-Computer-Android-Flightradar24   File: FCActivity.java   View source code 6 votes vote down vote up
public void startSensor()
  {
  	pressure_hPa_filter_ = new KalmanFilter(KF_VAR_ACCEL);   				
sensor_manager_ = (SensorManager) getSystemService(SENSOR_SERVICE);
   sensor_pressure_ = sensor_manager_.getDefaultSensor(Sensor.TYPE_PRESSURE);
       pressure_hPa_ = 1013.0912;		
       pressure_hPa_filter_.reset(pressure_hPa_);
       last_measurement_time_ = SystemClock.elapsedRealtime() / 1000.;	 
   	// Start listening to the pressure sensor.		    	  			 	
	mSensorListener = new SensorEventListener() {
	    	@Override
	        public void onSensorChanged(SensorEvent event) {		
	    		pressure_hPa_=event.values[0];
	        }
	        public void onAccuracyChanged(Sensor sensor, int accuracy) {
	        }				   
	    };	 
  }
 
Example 40
Project: notify_me   File: LightUp.java   View source code 6 votes vote down vote up
public void handlePocket(final Context context){
    handler = new Handler();
    prefs = new Prefs(this);
    long timeout = prefs.getProximityTimeout();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            mSensorManager.unregisterListener((SensorEventListener) context);
            mSensorManager = null;
            //Log.d("Unregistered ", System.currentTimeMillis()+"");
            IntentFilter iFilter = new IntentFilter();
            iFilter.addAction(Intent.ACTION_SCREEN_ON);

            listener = new screenOnListener();
            context.registerReceiver(listener, iFilter);
            countdown = false;
            //Log.d("Registered  broadcast receiver",System.currentTimeMillis()+"");
        }
    }, timeout
    );
}