Example usage for android.hardware Sensor TYPE_GRAVITY

List of usage examples for android.hardware Sensor TYPE_GRAVITY

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_GRAVITY.

Prototype

int TYPE_GRAVITY

To view the source code for android.hardware Sensor TYPE_GRAVITY.

Click Source Link

Document

A constant describing a gravity sensor type.

Usage

From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java

/**
 * @see android.hardware.SensorEventListener#onSensorChanged(android.hardware.SensorEvent)
 *///from www  .ja v a2  s. c  o m
@Override
public void onSensorChanged(SensorEvent event) {
    onAccuracyChanged(event.sensor, event.accuracy);

    timestampLabel.setVisibility(View.VISIBLE);
    timestamp.setVisibility(View.VISIBLE);
    timestamp.setText(String.valueOf(event.timestamp));
    timestampUnits.setVisibility(View.VISIBLE);

    switch (event.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        showEventData("Acceleration - gravity on axis", ACCELERATION_UNITS, event.values[0], event.values[1],
                event.values[2]);
        break;

    case Sensor.TYPE_MAGNETIC_FIELD:
        showEventData("Abient Magnetic Field", "uT", event.values[0], event.values[1], event.values[2]);
        break;
    case Sensor.TYPE_GYROSCOPE:
        showEventData("Angular speed around axis", "radians/sec", event.values[0], event.values[1],
                event.values[2]);
        break;
    case Sensor.TYPE_LIGHT:
        showEventData("Ambient light", "lux", event.values[0]);
        break;
    case Sensor.TYPE_PRESSURE:
        showEventData("Atmospheric pressure", "hPa", event.values[0]);
        break;
    case Sensor.TYPE_PROXIMITY:
        showEventData("Distance", "cm", event.values[0]);
        break;
    case Sensor.TYPE_GRAVITY:
        showEventData("Gravity", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]);
        break;
    case Sensor.TYPE_LINEAR_ACCELERATION:
        showEventData("Acceleration (not including gravity)", ACCELERATION_UNITS, event.values[0],
                event.values[1], event.values[2]);
        break;
    case Sensor.TYPE_ROTATION_VECTOR:

        showEventData("Rotation Vector", null, event.values[0], event.values[1], event.values[2]);

        xAxisLabel.setText("x*sin(" + THETA + "/2)");
        yAxisLabel.setText("y*sin(" + THETA + "/2)");
        zAxisLabel.setText("z*sin(" + THETA + "/2)");

        if (event.values.length == 4) {
            cosLabel.setVisibility(View.VISIBLE);
            cos.setVisibility(View.VISIBLE);
            cos.setText(String.valueOf(event.values[3]));
        }

        break;
    case Sensor.TYPE_ORIENTATION:
        showEventData("Angle", "Degrees", event.values[0], event.values[1], event.values[2]);

        xAxisLabel.setText(R.string.azimuthLabel);
        yAxisLabel.setText(R.string.pitchLabel);
        zAxisLabel.setText(R.string.rollLabel);

        break;
    case Sensor.TYPE_RELATIVE_HUMIDITY:
        showEventData("Relatice ambient air humidity", "%", event.values[0]);
        break;
    case Sensor.TYPE_AMBIENT_TEMPERATURE:
        showEventData("Ambien temperature", "degree Celcius", event.values[0]);
        break;
    }
}

From source file:it.unime.mobility4ckan.MainActivity.java

private void createListView() {

    overviewList.clear();//  w  ww  . j ava  2 s. com

    Overview overviewTitle = new Overview(getApplicationContext());
    overviewTitle.setSensorName("Nome Sensore");
    overviewTitle.setCurrentValue("Valore Corrente");
    overviewTitle.setValueSend("Valore Inviato");
    overviewList.add(overviewTitle);

    Overview overview0 = new Overview(getApplicationContext());
    overview0.setSensorName("Speed");
    overview0.setCurrentValue("" + mySensor.getCurrentSpeed());
    overview0.setValueSend(lastSpeedValue);
    overviewList.add(overview0);

    for (int k = 0; k < sensorList.size(); k++) {
        Overview overview = new Overview(getApplicationContext());
        switch (sensorList.get(k).getType()) {
        case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C)
            overview.setSensorName("Temperature");
            overview.setCurrentValue("" + mySensor.getCurrentTemp());
            overview.setValueSend(lastTempValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_PRESSURE:
            overview.setSensorName("Pressure");
            overview.setCurrentValue("" + mySensor.getCurrentPressure());
            overview.setValueSend(lastPressureValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_LIGHT: // lx
            overview.setSensorName("Light");
            overview.setCurrentValue("" + mySensor.getCurrentLight());
            overview.setValueSend(lastLightValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_ACCELEROMETER: // m/s2
            overview.setSensorName("Accelerometer");
            overview.setCurrentValue("" + mySensor.getCurrentAcceleration());
            overview.setValueSend(lastAccelerationValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_GYROSCOPE: // rad/s
            overview.setSensorName("Gyroscope");
            overview.setCurrentValue("" + mySensor.getCurrentGyroscope());
            overview.setValueSend(lastGyroscopeValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_MAGNETIC_FIELD: // T
            overview.setSensorName("Magnetic Field");
            overview.setCurrentValue("" + mySensor.getCurrentMagnetic());
            overview.setValueSend(lastMagneticValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_PROXIMITY: // cm
            overview.setSensorName("Proximity");
            overview.setCurrentValue("" + mySensor.getCurrentProximity());
            overview.setValueSend(lastProximityValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta
            overview.setSensorName("Rotation Vector");
            overview.setCurrentValue("" + mySensor.getCurrentRotation());
            overview.setValueSend(lastRotationValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_GRAVITY: // m/s2
            overview.setSensorName("Gravity");
            overview.setCurrentValue("" + mySensor.getCurrentGravity());
            overview.setValueSend(lastGravityValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2
            overview.setSensorName("Linear Acceleration");
            overview.setCurrentValue("" + mySensor.getCurrentLinearAcceleration());
            overview.setValueSend(lastLinearAccelerationValue);
            overviewList.add(overview);
            break;

        case Sensor.TYPE_RELATIVE_HUMIDITY: // %
            overview.setSensorName("Relative Humidity");
            overview.setCurrentValue("" + mySensor.getCurrentHumidity());
            overview.setValueSend(lastRelativeHumidity);
            overviewList.add(overview);
            break;

        default:
            break;
        }
    }

    listView.setAdapter(new OverviewAdapter(getApplicationContext(), overviewList));

}

From source file:io.authme.sdk.widget.LockPatternView.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LockPatternView(Context context, AttributeSet attrs) {
    super(context, attrs);
    senSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    if (senAccelerometer == null) {
        senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    }// ww  w  .j  a v a2s. c o  m

    senSensorManager.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_GAME);

    sensGyro = senSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

    if (sensGyro != null) {
        senSensorManager.registerListener(this, sensGyro, SensorManager.SENSOR_DELAY_GAME);
    }

    senMagnetometer = senSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    if (senMagnetometer != null) {
        senSensorManager.registerListener(this, senMagnetometer, SensorManager.SENSOR_DELAY_GAME);
    }

    accelList = new ArrayList<>();
    magnetics = new ArrayList<>();
    gyrolist = new ArrayList<>();
    rawXYList = new ArrayList<>();
    velocityList = new ArrayList<>();
    orientationArrayList = new ArrayList<>();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Alp_42447968_LockPatternView);

    final String aspect = a.getString(R.styleable.Alp_42447968_LockPatternView_alp_42447968_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    mRegularColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_regular));
    mErrorColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_error));
    mSuccessColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_success));

    mRegularColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_regularColor,
            mRegularColor);
    mErrorColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_successColor,
            mSuccessColor);

    int pathColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_pathColor, mRegularColor);
    mPathPaint.setColor(pathColor);

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size);
    mDotSizeActivated = getResources()
            .getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    mCellStates = new CellState[MATRIX_WIDTH][MATRIX_WIDTH];
    for (int i = 0; i < MATRIX_WIDTH; i++) {
        for (int j = 0; j < MATRIX_WIDTH; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].size = mDotSize;
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isInEditMode()) {
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.fast_out_slow_in);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.linear_out_slow_in);
    } // if
}

From source file:org.godotengine.godot.Godot.java

private void initializeGodot() {

    if (expansion_pack_path != null) {

        String[] new_cmdline;
        int cll = 0;
        if (command_line != null) {
            new_cmdline = new String[command_line.length + 2];
            cll = command_line.length;/*from w ww.j  a  va 2s. c  om*/
            for (int i = 0; i < command_line.length; i++) {
                new_cmdline[i] = command_line[i];
            }
        } else {
            new_cmdline = new String[2];
        }

        new_cmdline[cll] = "--main-pack";
        new_cmdline[cll + 1] = expansion_pack_path;
        command_line = new_cmdline;
    }

    io = new GodotIO(this);
    io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    GodotLib.io = io;
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
    mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
    mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
    mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);

    GodotLib.initialize(this, getAssets(), use_apk_expansion);

    result_callback = null;

    mPaymentsManager = PaymentsManager.createManager(this).initService();

    godot_initialized = true;
}

From source file:tv.piratemedia.flightcontroller.BluetoothComputerFragment.java

public void setupGyro() {
    final Handler TimeoutHandler = new Handler();
    SensorManager mSensorManager;//from w  ww  .j  a va 2 s .  c  o  m
    Sensor mSensor;

    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);

    SensorEventListener sensorListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {
            int X = (int) (event.values[0] / 2.0f);
            int Y = (int) (event.values[1] / 2.0f);
            int Z = (int) (event.values[2] / 2.0f);
            Y = -Y;

            //Log.d("gyro", "X: " + X + " Y: " + Y + " Z: " + Z);
            if (currentPitch != Y || currentRoll != X || currentYaw != Z) {
                if (!Moving && currentTrottle > 10) {
                    if ((PitchCorrection < MaxCorrectionValue || Y < 0)
                            && (PitchCorrection > -MaxCorrectionValue || Y > 0)) {
                        PitchCorrection += Y;
                        if (PitchCorrection > MaxCorrectionValue) {
                            PitchCorrection = MaxCorrectionValue;
                        } else if (PitchCorrection < -MaxCorrectionValue) {
                            PitchCorrection = -MaxCorrectionValue;
                        }
                    }
                    if ((RollCorrection < MaxCorrectionValue || X < 0)
                            && (RollCorrection > -MaxCorrectionValue || X > 0)) {
                        RollCorrection += X;
                        if (RollCorrection > MaxCorrectionValue) {
                            RollCorrection = MaxCorrectionValue;
                        } else if (RollCorrection < -MaxCorrectionValue) {
                            RollCorrection = -MaxCorrectionValue;
                        }
                    }
                    updateThrottle(currentTrottle);
                } else if (currentTrottle <= 10) {
                    PitchCorrection = 0;
                    RollCorrection = 0;
                }
                currentPitch = Y;
                currentRoll = X;
                currentYaw = Z;

                JSONObject msg = new JSONObject();
                try {
                    msg.put("action", "gyro_update");
                    msg.put("x", currentRoll);
                    msg.put("y", currentPitch);
                    msg.put("z", currentYaw);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                sendTextMessage(msg.toString());
            }
        }

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

        }
    };

    if (mSensor != null) {
        mSensorManager.registerListener(sensorListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
    } else {
        Toast.makeText(getActivity().getApplicationContext(), "No Gravity Sensor on device", Toast.LENGTH_LONG)
                .show();
    }
}

From source file:it.unime.mobility4ckan.MainActivity.java

void sendTask(final boolean shouldUpdateCountdown) {
    if (!isDeviceCurrentSensorsRegistered && !isRegistering) {
        new RegisterDevice(this).execute(datasetName);
        isRegistering = true;//  w  w  w. j  a  v  a  2 s .c  om
        return;
    }

    if (!isDeviceCurrentSensorsRegistered || !isGPSReady) {
        return;
    }

    String currentSpeedValue = "" + mySensor.getCurrentSpeed();
    getSensorDataToSend("speedDatastoreUUID", "Speed", currentSpeedValue);
    lastSpeedValue = currentSpeedValue;

    for (int k = 0; k < sensorList.size(); k++) {
        switch (sensorList.get(k).getType()) {
        case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C)
            String currentTempValue = "" + mySensor.getCurrentTemp();
            getSensorDataToSend("temperatureDatastoreUUID", "Temperature", currentTempValue);
            lastTempValue = currentTempValue;
            break;

        case Sensor.TYPE_PRESSURE:
            String currentPressureValue = "" + mySensor.getCurrentPressure();
            getSensorDataToSend("pressureDatastoreUUID", "Pressure", currentPressureValue);
            lastPressureValue = currentPressureValue;
            break;

        case Sensor.TYPE_LIGHT: // lx
            String currentLightValue = "" + mySensor.getCurrentLight();
            getSensorDataToSend("lightDatastoreUUID", "Light", currentLightValue);
            lastLightValue = currentLightValue;
            break;

        case Sensor.TYPE_ACCELEROMETER: // m/s2
            String currentAccelerationValue = mySensor.getCurrentAcceleration();
            getSensorDataToSend("accelerometerDatastoreUUID", "Accelerometer", currentAccelerationValue);
            lastAccelerationValue = currentAccelerationValue;
            break;

        case Sensor.TYPE_GYROSCOPE: // rad/s
            String currentGyroscopeValue = mySensor.getCurrentGyroscope();
            getSensorDataToSend("gyroscopeDatastoreUUID", "Gyroscope", currentGyroscopeValue);
            lastGyroscopeValue = currentGyroscopeValue;
            break;

        case Sensor.TYPE_MAGNETIC_FIELD: // T
            String currentMagneticValue = mySensor.getCurrentMagnetic();
            getSensorDataToSend("magneticFieldDatastoreUUID", "MagneticField", currentMagneticValue);
            lastMagneticValue = currentMagneticValue;
            break;

        case Sensor.TYPE_PROXIMITY: // cm
            String currentProximityValue = "" + mySensor.getCurrentProximity();
            getSensorDataToSend("proximityDatastoreUUID", "Proximity", currentProximityValue);
            lastProximityValue = currentProximityValue;
            break;

        case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta
            String currentRotationValue = mySensor.getCurrentRotation();
            getSensorDataToSend("rotationVector", "RotationVector", currentRotationValue);
            lastRotationValue = currentRotationValue;
            break;

        case Sensor.TYPE_GRAVITY: // m/s2
            String currentGravityValue = mySensor.getCurrentGravity();
            getSensorDataToSend("gravity", "Gravity", currentGravityValue);
            lastGravityValue = currentGravityValue;
            break;

        case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2
            String currentLinearAccelerationValue = mySensor.getCurrentLinearAcceleration();
            getSensorDataToSend("linearAcceleration", "LinearAcceleration", currentLinearAccelerationValue);
            lastLinearAccelerationValue = currentLinearAccelerationValue;
            break;

        case Sensor.TYPE_RELATIVE_HUMIDITY: // %
            String currentRelativeHumidity = "" + mySensor.getCurrentHumidity();
            getSensorDataToSend("relativeHumidity", "RelativeHumidity", currentRelativeHumidity);
            lastRelativeHumidity = currentRelativeHumidity;
            break;

        default:
            break;
        }
    }

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (shouldUpdateCountdown) {
                new CountDownTimer(countdown, 1000) {
                    public void onTick(long millisUntilFinished) {
                        countdownText.setText("" + millisUntilFinished / 1000);
                    }

                    public void onFinish() {
                    }
                }.start();
            }
        }
    });

}

From source file:org.godotengine.godot.Godot.java

@Override
public void onSensorChanged(SensorEvent event) {
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    int displayRotation = display.getRotation();

    float[] adjustedValues = new float[3];
    final int axisSwap[][] = { { 1, -1, 0, 1 }, // ROTATION_0
            { -1, -1, 1, 0 }, // ROTATION_90
            { -1, 1, 0, 1 }, // ROTATION_180
            { 1, 1, 1, 0 } }; // ROTATION_270

    final int[] as = axisSwap[displayRotation];
    adjustedValues[0] = (float) as[0] * event.values[as[2]];
    adjustedValues[1] = (float) as[1] * event.values[as[3]];
    adjustedValues[2] = event.values[2];

    final float x = adjustedValues[0];
    final float y = adjustedValues[1];
    final float z = adjustedValues[2];

    final int typeOfSensor = event.sensor.getType();
    if (mView != null) {
        mView.queueEvent(new Runnable() {
            @Override/*from w ww .jav a2 s  .c  o m*/
            public void run() {
                if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) {
                    GodotLib.accelerometer(-x, y, -z);
                }
                if (typeOfSensor == Sensor.TYPE_GRAVITY) {
                    GodotLib.gravity(-x, y, -z);
                }
                if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) {
                    GodotLib.magnetometer(-x, y, -z);
                }
                if (typeOfSensor == Sensor.TYPE_GYROSCOPE) {
                    GodotLib.gyroscope(x, -y, z);
                }
            }
        });
    }
}

From source file:com.aware.Aware_Preferences.java

/**
 * Gravity module settings UI//ww w . j  av a2s.  c o m
 */
private void gravity() {
    final PreferenceScreen grav_pref = (PreferenceScreen) findPreference("gravity");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_GRAVITY);
    if (temp != null) {
        grav_pref.setSummary(
                grav_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        grav_pref.setSummary(grav_pref.getSummary().toString().replace("*", ""));
    }

    final CheckBoxPreference gravity = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_GRAVITY);
    gravity.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_GRAVITY).equals("true"));
    gravity.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_GRAVITY) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                gravity.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_GRAVITY, false);
                return false;
            }
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_GRAVITY, gravity.isChecked());
            if (gravity.isChecked()) {
                framework.startGravity();
            } else {
                framework.stopGravity();
            }
            return true;
        }
    });

    final EditTextPreference frequency_gravity = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_GRAVITY);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GRAVITY).length() > 0) {
        frequency_gravity
                .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GRAVITY)
                        + " microseconds");
    }
    frequency_gravity.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GRAVITY));
    frequency_gravity.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GRAVITY, (String) newValue);
            frequency_gravity.setSummary((String) newValue + " microseconds");
            framework.startGravity();
            return true;
        }
    });
}

From source file:com.example.sensingapp.SensingApp.java

private void UpdateSensorServiceRegistration() {
    //Register sensors according to the enable/disable status
    //       if (m_blnAcclEnabled) {
    //          m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), m_nAcclMode);
    //          m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nAcclMode);
    //       } else {
    //          m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION));
    //          m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    //       }//from   w  w w.  ja va 2  s . co m

    if (m_blnAcclEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                m_nAcclMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    }

    if (m_blnLinearAcclEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                m_nLinearAcclMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome,
                m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION));
    }

    if (m_blnGravityEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GRAVITY),
                m_nGravityMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GRAVITY));
    }

    if (m_blnGyroEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
                m_nGyroMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GYROSCOPE));
    }

    if (m_blnMagnetEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                m_nMagnetMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD));
    }

    // Changed on 20150910
    //       if (m_blnOrientEnabled) {
    //         if (!m_blnAcclEnabled) { 
    //            m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nOrientMode);
    //         }
    //         
    //         if (!m_blnMagnetEnabled) {
    //            m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), m_nOrientMode);
    //         }              
    //       } else {
    //          if (!m_blnAcclEnabled) {
    //             m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    //          }
    //          
    //          if (!m_blnMagnetEnabled) {
    //             m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD));
    //          }
    //       }

    if (m_blnOrientEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                m_nOrientMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR));
    }

    if (m_blnLightEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LIGHT), m_nLightMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LIGHT));
    }

    if (m_blnBarometerEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_PRESSURE),
                m_nBarometerMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_PRESSURE));
    }

}

From source file:com.example.sensingapp.SensingApp.java

private void checkSensorAvailability() {
    //List<Sensor> lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ORIENTATION);
    List<Sensor> lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ROTATION_VECTOR); //Changed on 20150910
    if (lstSensor.size() > 0) {
        m_blnOrientPresent = true;//from  ww  w .ja  v a2  s  .co  m
    } else {
        m_blnOrientPresent = false;
        m_blnOrientEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_GYROSCOPE);
    if (lstSensor.size() > 0) {
        m_blnGyroPresent = true;
    } else {
        m_blnGyroPresent = false;
        m_blnGyroEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ACCELEROMETER);
    if (lstSensor.size() > 0) {
        m_blnAcclPresent = true;
    } else {
        m_blnAcclPresent = false;
        m_blnAcclEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_LINEAR_ACCELERATION);
    if (lstSensor.size() > 0) {
        m_blnLinearAcclPresent = true;
    } else {
        m_blnLinearAcclPresent = false;
        m_blnLinearAcclEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_GRAVITY);
    if (lstSensor.size() > 0) {
        m_blnGravityPresent = true;
    } else {
        m_blnGravityPresent = false;
        m_blnGravityEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
    if (lstSensor.size() > 0) {
        m_blnMagnetPresent = true;
    } else {
        m_blnMagnetPresent = false;
        m_blnMagnetEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_LIGHT);
    if (lstSensor.size() > 0) {
        m_blnLightPresent = true;
    } else {
        m_blnLightPresent = false;
        m_blnLightEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_PRESSURE);
    if (lstSensor.size() > 0) {
        m_blnBarometerPresent = true;
    } else {
        m_blnBarometerPresent = false;
        m_blnBarometerEnabled = false;
    }

}