Example usage for android.hardware Sensor getPower

List of usage examples for android.hardware Sensor getPower

Introduction

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

Prototype

public float getPower() 

Source Link

Usage

From source file:com.aware.Aware_Preferences.java

/**
 * Temperature module settings UI/*from w ww. jav a  2 s  . c o  m*/
 */
private void temperature() {
    final PreferenceScreen temp_pref = (PreferenceScreen) findPreference("temperature");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_TEMPERATURE);
    if (temp != null) {
        temp_pref.setSummary(
                temp_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        temp_pref.setSummary(temp_pref.getSummary().toString().replace("*", ""));
    }

    final CheckBoxPreference temperature = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_TEMPERATURE);
    temperature.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE).equals("true"));
    temperature.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                temperature.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE,
                    temperature.isChecked());
            if (temperature.isChecked()) {
                framework.startTemperature();
            } else {
                framework.stopTemperature();
            }
            return true;
        }
    });

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

From source file:com.aware.Aware_Preferences.java

/**
 * Accelerometer module settings UI//w w w . j a  v a  2 s. c  o m
 */
private void accelerometer() {

    final PreferenceScreen accel_pref = (PreferenceScreen) findPreference("accelerometer");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (temp != null) {
        accel_pref.setSummary(
                accel_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        accel_pref.setSummary(accel_pref.getSummary().toString().replace("*", ""));
    }

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

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                accelerometer.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ACCELEROMETER, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ACCELEROMETER,
                    accelerometer.isChecked());
            if (accelerometer.isChecked()) {
                framework.startAccelerometer();
            } else {
                framework.stopAccelerometer();
            }
            return true;
        }
    });

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

}

From source file:com.aware.Aware_Preferences.java

/**
 * Magnetometer module settings UI//w  w w.  j  a  v  a2s.c  o m
 */
private void magnetometer() {
    final PreferenceScreen magno_pref = (PreferenceScreen) findPreference("magnetometer");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    if (temp != null) {
        magno_pref.setSummary(
                magno_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        magno_pref.setSummary(magno_pref.getSummary().toString().replace("*", ""));
    }

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

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                magnetometer.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MAGNETOMETER, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MAGNETOMETER,
                    magnetometer.isChecked());
            if (magnetometer.isChecked()) {
                framework.startMagnetometer();
            } else {
                framework.stopMagnetometer();
            }
            return true;
        }
    });

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

}

From source file:com.aware.Aware_Preferences.java

/**
 * Rotation module settings UI/* ww w . j a  v  a2  s . c  o  m*/
 */
private void rotation() {

    final PreferenceScreen rotation_pref = (PreferenceScreen) findPreference("rotation");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
    if (temp != null) {
        rotation_pref.setSummary(
                rotation_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        rotation_pref.setSummary(rotation_pref.getSummary().toString().replace("*", ""));
    }

    final CheckBoxPreference rotation = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_ROTATION);
    rotation.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_ROTATION).equals("true"));
    rotation.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                rotation.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ROTATION, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ROTATION, rotation.isChecked());
            if (rotation.isChecked()) {
                framework.startRotation();
            } else {
                framework.stopRotation();
            }
            return true;
        }
    });

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

}

From source file:com.aware.Aware_Preferences.java

/**
 * Proximity module settings UI/*from  ww w.  j  a v  a  2s.  c o  m*/
 */
private void proximity() {

    final PreferenceScreen proxi_pref = (PreferenceScreen) findPreference("proximity");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    if (temp != null) {
        proxi_pref.setSummary(
                proxi_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        proxi_pref.setSummary(proxi_pref.getSummary().toString().replace("*", ""));
    }

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

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_PROXIMITY) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                proximity.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_PROXIMITY, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_PROXIMITY,
                    proximity.isChecked());
            if (proximity.isChecked()) {
                framework.startProximity();
            } else {
                framework.stopProximity();
            }
            return true;
        }
    });

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

From source file:com.aware.Aware_Preferences.java

/**
 * Linear Accelerometer module settings UI
 *//*from  ww  w.j  a v  a  2  s. c  o m*/
private void linear_accelerometer() {

    final PreferenceScreen linear_pref = (PreferenceScreen) findPreference("linear_accelerometer");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    if (temp != null) {
        linear_pref.setSummary(
                linear_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        linear_pref.setSummary(linear_pref.getSummary().toString().replace("*", ""));
    }

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

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                linear_accelerometer.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LINEAR_ACCELEROMETER, false);
                return false;
            }
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LINEAR_ACCELEROMETER,
                    linear_accelerometer.isChecked());
            if (linear_accelerometer.isChecked()) {
                framework.startLinearAccelerometer();
            } else {
                framework.stopLinearAccelerometer();
            }
            return true;
        }
    });

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

}