Android Open Source - HexNanoController_Android Device Sensor Manager Wrapper






From Project

Back to project page HexNanoController_Android.

License

The source code is released under:

Code license GNU GPL v2 http://www.gnu.org/licenses/gpl.html Content license CC BY-NC-SA 4.0 http://creativecommons.org/licenses/by-nc-sa/4.0/

If you think the Android project HexNanoController_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hexairbot.hexmini.sensors;
//from   w  w  w . java 2 s  .  c  o  m
import java.util.List;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Handler;
import android.util.Log;

public class DeviceSensorManagerWrapper
        extends SensorManagerWrapper
{
    private static final String TAG = DeviceSensorManagerWrapper.class.getSimpleName();
    private SensorManager sensorManager;

    public DeviceSensorManagerWrapper(final Context theContext)
    {
        sensorManager = (SensorManager) theContext.getSystemService(Context.SENSOR_SERVICE);
        checkSensors(sensorManager);
    }

    private void checkSensors(SensorManager sensorManager)
    {
        List<Sensor> availableSensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

        Log.i(TAG, "Available sensors: " + getAvailableSensorsAsString(availableSensors));

        for (int i = 0; i < availableSensors.size(); ++i) {
            Sensor sensor = availableSensors.get(i);

            if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
                setAcceleroAvailable(true);
            } else if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {

                if (Build.BRAND.equalsIgnoreCase("nook")) {
                    // This is workaround for Nook Tablet.
                    // It is needed because system returns magnetic sensor, but
                    // because Nook Tabled doesn't have hardware magnetometer it
                    // doestn't work
                    setMagnetoAvailable(false);
                } else {
                    setMagnetoAvailable(true);
                }
            } else if (sensor.getType() == Sensor.TYPE_GYROSCOPE && Build.VERSION.SDK_INT > 8) {
                // We use method from the android 9 in the onGyrochanged, so we
                // need to ignore gyroscope for android <= 8
                setGyroAvailable(true);
            }
        }
    }

    @Override
    public boolean registerListener(SensorEventListener theListener, int theType, Handler handler)
    {
        Sensor sensor = sensorManager.getDefaultSensor(theType);
        if (sensor != null) {
            // Do not use SENSOR_DELAY_FASTEST here. This will cause problems on Nexus devices
          sensorManager.registerListener(theListener, sensor, SensorManager.SENSOR_DELAY_GAME, handler);
            return true;
        }
        return false;
    }

    @Override
    public void unregisterListener(SensorEventListener theListener)
    {
        this.sensorManager.unregisterListener(theListener);
    }

    private String getAvailableSensorsAsString(List<Sensor> availableSensors)
    {
        String sensors = "";

        for (int i = 0; i < availableSensors.size(); ++i) {
            Sensor sensor = availableSensors.get(i);
            sensors += sensor.getName() + "(" + sensor.getVendor() + ", " + sensor.getVersion() + "), ";
        }

        return sensors;
    }

    @Override
    public void onCreate()
    {}
    
    @Override
    public void onDestroy()
    {}

    @Override
    public void onPause()
    {}

    @Override
    public void onResume()
    {}
}




Java Source Code List

.FileHelper.java
.Input.java
.Output.java
.Serializable.java
com.hexairbot.hexmini.HelpActivity.java
com.hexairbot.hexmini.HexMiniApplication.java
com.hexairbot.hexmini.HudActivity.java
com.hexairbot.hexmini.HudViewControllerDelegate.java
com.hexairbot.hexmini.HudViewController.java
com.hexairbot.hexmini.SettingsDialogDelegate.java
com.hexairbot.hexmini.SettingsDialog.java
com.hexairbot.hexmini.SettingsViewControllerDelegate.java
com.hexairbot.hexmini.SettingsViewController.java
com.hexairbot.hexmini.ViewController.java
com.hexairbot.hexmini.adapter.SettingsViewAdapter.java
com.hexairbot.hexmini.ble.BleConnectinManagerDelegate.java
com.hexairbot.hexmini.ble.BleConnectinManager.java
com.hexairbot.hexmini.ble.BluetoothLeService.java
com.hexairbot.hexmini.gestures.EnhancedGestureDetector.java
com.hexairbot.hexmini.modal.ApplicationSettings.java
com.hexairbot.hexmini.modal.Channel.java
com.hexairbot.hexmini.modal.OSDCommon.java
com.hexairbot.hexmini.modal.Transmitter.java
com.hexairbot.hexmini.sensors.DeviceOrientationChangeDelegate.java
com.hexairbot.hexmini.sensors.DeviceOrientationManager.java
com.hexairbot.hexmini.sensors.DeviceSensorManagerWrapper.java
com.hexairbot.hexmini.sensors.SensorManagerWrapper.java
com.hexairbot.hexmini.services.ConnectStateManager.java
com.hexairbot.hexmini.services.IpcControlService.java
com.hexairbot.hexmini.services.IpcProxy.java
com.hexairbot.hexmini.services.NavData.java
com.hexairbot.hexmini.services.OnIpcConnectChangedListener.java
com.hexairbot.hexmini.services.VIConfig.java
com.hexairbot.hexmini.ui.Button.java
com.hexairbot.hexmini.ui.Image.java
com.hexairbot.hexmini.ui.Indicator.java
com.hexairbot.hexmini.ui.Sprite.java
com.hexairbot.hexmini.ui.Text.java
com.hexairbot.hexmini.ui.ToggleButton.java
com.hexairbot.hexmini.ui.UIRenderer.java
com.hexairbot.hexmini.ui.control.CustomSeekBar.java
com.hexairbot.hexmini.ui.control.ViewPagerIndicator.java
com.hexairbot.hexmini.ui.gl.GLSprite.java
com.hexairbot.hexmini.ui.joystick.AcceleratorJoystick.java
com.hexairbot.hexmini.ui.joystick.AnalogueJoystick.java
com.hexairbot.hexmini.ui.joystick.JoystickBase.java
com.hexairbot.hexmini.ui.joystick.JoystickFactory.java
com.hexairbot.hexmini.ui.joystick.JoystickListener.java
com.hexairbot.hexmini.util.DebugHandler.java
com.hexairbot.hexmini.util.FontUtils.java
com.hexairbot.hexmini.util.SystemUiHiderBase.java
com.hexairbot.hexmini.util.SystemUiHiderHoneycomb.java
com.hexairbot.hexmini.util.SystemUiHider.java
com.hexairbot.hexmini.util.SystemUtil.java
com.hexairbot.hexmini.util.TextureUtils.java
fix.android.opengl.GLES20.java