Example usage for android.preference EditTextPreference setOnPreferenceChangeListener

List of usage examples for android.preference EditTextPreference setOnPreferenceChangeListener

Introduction

In this page you can find the example usage for android.preference EditTextPreference setOnPreferenceChangeListener.

Prototype

public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener) 

Source Link

Document

Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).

Usage

From source file:com.aware.Aware_Preferences.java

/**
 * Webservices module settings UI/*from  w ww .j a v  a  2  s .  co  m*/
 */
private void webservices() {
    final CheckBoxPreference webservice = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_WEBSERVICE);
    webservice.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE).equals("true"));
    webservice.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() == 0) {
                showDialog(DIALOG_ERROR_MISSING_PARAMETERS);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE, false);
                webservice.setChecked(false);
                return false;
            } else {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE,
                        webservice.isChecked());
                if (webservice.isChecked()
                        && Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER).length() > 0) {
                    //setup and send data
                    Intent study_config = new Intent(getApplicationContext(), StudyConfig.class);
                    study_config.putExtra("study_url",
                            Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER));
                    startService(study_config);
                }
                return true;
            }
        }
    });

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

    final CheckBoxPreference webservice_wifi_only = (CheckBoxPreference) findPreference(
            Aware_Preferences.WEBSERVICE_WIFI_ONLY);
    webservice_wifi_only.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY).equals("true"));
    webservice_wifi_only.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY,
                    webservice_wifi_only.isChecked());
            return true;
        }
    });

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

    final ListPreference clean_old_data = (ListPreference) findPreference(FREQUENCY_CLEAN_OLD_DATA);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA).length() > 0) {
        String freq = Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA);
        if (freq.equals("0")) {
            clean_old_data.setSummary("Never");
        } else if (freq.equals("1")) {
            clean_old_data.setSummary("Weekly");
        } else if (freq.equals("2")) {
            clean_old_data.setSummary("Monthly");
        }
    }
    clean_old_data.setDefaultValue(Aware.getSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA));
    clean_old_data.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA, (String) newValue);
            if (((String) newValue).equals("0")) {
                clean_old_data.setSummary("Never");
            } else if (((String) newValue).equals("1")) {
                clean_old_data.setSummary("Weekly");
            } else if (((String) newValue).equals("2")) {
                clean_old_data.setSummary("Monthly");
            }
            return true;
        }
    });
}

From source file:com.aware.Aware_Preferences.java

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

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

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_PRESSURE) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                pressure.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BAROMETER, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BAROMETER, pressure.isChecked());
            if (pressure.isChecked()) {
                framework.startBarometer();
            } else {
                framework.stopBarometer();
            }
            return true;
        }
    });

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

}

From source file:com.aware.Aware_Preferences.java

/**
 * Gyroscope module settings UI/* ww  w.  ja v a2s . c o m*/
 */
private void gyroscope() {
    final PreferenceScreen gyro_pref = (PreferenceScreen) findPreference("gyroscope");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    if (temp != null) {
        gyro_pref.setSummary(
                gyro_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        gyro_pref.setSummary(gyro_pref.getSummary().toString().replace("*", ""));
    }

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

            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_GYROSCOPE) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                gyroscope.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_GYROSCOPE, false);
                return false;
            }
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_GYROSCOPE,
                    gyroscope.isChecked());
            if (gyroscope.isChecked()) {
                framework.startGyroscope();
            } else {
                framework.stopGyroscope();
            }
            return true;
        }
    });

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

}

From source file:com.aware.Aware_Preferences.java

/**
 * Proximity module settings UI/*from   www.  j  ava 2 s  .  co  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

/**
 * Temperature module settings UI//from  ww w .  j a v a  2  s . co 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

/**
 * Network module settings UI/*from  ww  w. j  a va2 s  .co  m*/
 */
private void network() {
    final CheckBoxPreference network_traffic = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_NETWORK_TRAFFIC);
    network_traffic.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_TRAFFIC).equals("true"));
    network_traffic.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_TRAFFIC,
                    network_traffic.isChecked());
            if (network_traffic.isChecked()) {
                framework.startTraffic();
            } else {
                framework.stopTraffic();
            }
            return true;
        }
    });

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

    final CheckBoxPreference network = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_NETWORK_EVENTS);
    network.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_EVENTS).equals("true"));
    network.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_EVENTS,
                    network.isChecked());
            if (network.isChecked()) {
                framework.startNetwork();
            } else {
                framework.stopNetwork();
            }
            return true;
        }
    });
}

From source file:com.aware.Aware_Preferences.java

/**
 * Magnetometer module settings UI//from www  . j av  a  2  s.  c om
 */
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

/**
 * Accelerometer module settings UI/*  w w  w. j av a 2 s .c om*/
 */
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

/**
 * Location module settings UI/*  www.ja v a 2 s  .  c  o m*/
 */
private void locations() {
    final CheckBoxPreference location_gps = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_LOCATION_GPS);
    location_gps.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS).equals("true"));
    location_gps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE);
            List<String> providers = localMng.getAllProviders();

            if (!providers.contains(LocationManager.GPS_PROVIDER)) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                location_gps.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS,
                    location_gps.isChecked());
            if (location_gps.isChecked()) {
                framework.startLocations();
            } else {
                framework.stopLocations();
            }
            return true;
        }
    });

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

            LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE);
            List<String> providers = localMng.getAllProviders();

            if (!providers.contains(LocationManager.NETWORK_PROVIDER)) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                location_gps.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK,
                    location_network.isChecked());
            if (location_network.isChecked()) {
                framework.startLocations();
            } else {
                framework.stopLocations();
            }
            return true;
        }
    });

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

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

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

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

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

From source file:com.aware.Aware_Preferences.java

/**
 * Applications module settings UI/* ww  w . j  a  va2 s  .  co m*/
 */
private void applications() {
    final CheckBoxPreference notifications = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_NOTIFICATIONS);
    notifications.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS).equals("true"));
    notifications.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (isAccessibilityServiceActive() && notifications.isChecked()) {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS,
                        notifications.isChecked());
                notifications.setChecked(true);
                framework.startApplications();
                return true;
            }
            if (!isAccessibilityServiceActive()) {
                showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY);
            }
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS, false);
            notifications.setChecked(false);
            return false;
        }
    });
    final CheckBoxPreference crashes = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_CRASHES);
    crashes.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES).equals("true"));
    crashes.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (isAccessibilityServiceActive() && crashes.isChecked()) {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES,
                        crashes.isChecked());
                crashes.setChecked(true);
                framework.startApplications();
                return true;
            }
            if (!isAccessibilityServiceActive()) {
                showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY);
            }
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES, false);
            crashes.setChecked(false);
            return false;
        }
    });
    final CheckBoxPreference applications = (CheckBoxPreference) findPreference("status_applications");
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS).equals("true")
            && !isAccessibilityServiceActive()) {
        showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY);
        Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS, false);
        framework.stopApplications();
    }
    applications.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS).equals("true"));
    applications.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (isAccessibilityServiceActive() && applications.isChecked()) {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS, true);
                applications.setChecked(true);
                framework.startApplications();
                return true;
            } else {
                if (!isAccessibilityServiceActive()) {
                    showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY);
                }

                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS, false);
                applications.setChecked(false);

                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS, false);
                notifications.setChecked(false);

                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES, false);
                crashes.setChecked(false);

                framework.stopApplications();
                return false;
            }
        }
    });

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

    final CheckBoxPreference installations = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_INSTALLATIONS);
    installations.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_INSTALLATIONS).equals("true"));
    installations.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_INSTALLATIONS,
                    installations.isChecked());
            if (installations.isChecked()) {
                framework.startInstallations();
            } else {
                framework.stopInstallations();
            }
            return true;
        }
    });
}