Example usage for android.preference PreferenceScreen setSummary

List of usage examples for android.preference PreferenceScreen setSummary

Introduction

In this page you can find the example usage for android.preference PreferenceScreen setSummary.

Prototype

public void setSummary(CharSequence summary) 

Source Link

Document

Sets the summary for this Preference with a CharSequence.

Usage

From source file:com.aware.Aware_Preferences.java

/**
 * Proximity module settings UI//  www .  j  a  v a 2  s.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
 *///  w  w  w .  j a  v a2 s.  c  om
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;
        }
    });

}