List of usage examples for android.preference CheckBoxPreference setOnPreferenceClickListener
public void setOnPreferenceClickListener(OnPreferenceClickListener onPreferenceClickListener)
From source file:com.aware.Aware_Preferences.java
/** * Rotation module settings UI//from ww w .j a va 2 s . c om */ 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
/** * Atmospheric Pressure module settings UI *///from w w w. java2 s. 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
/** * Processor module settings UI//from w ww . java2s.co m */ private void processor() { final CheckBoxPreference processor = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_PROCESSOR); processor.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_PROCESSOR).equals("true")); processor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_PROCESSOR, processor.isChecked()); if (processor.isChecked()) { framework.startProcessor(); } else { framework.stopProcessor(); } return true; } }); final EditTextPreference frequencyProcessor = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_PROCESSOR); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_PROCESSOR).length() > 0) { frequencyProcessor.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_PROCESSOR) + " seconds"); } frequencyProcessor .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_PROCESSOR)); frequencyProcessor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_PROCESSOR, (String) newValue); frequencyProcessor.setSummary((String) newValue + " seconds"); framework.startProcessor(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Developer UI options// w ww . ja v a2s . c o m * - Debug flag * - Debug tag * - AWARE updates * - Device ID */ private void developerOptions() { final CheckBoxPreference debug_flag = (CheckBoxPreference) findPreference(Aware_Preferences.DEBUG_FLAG); debug_flag .setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true")); debug_flag.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.DEBUG = debug_flag.isChecked(); Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG, debug_flag.isChecked()); return true; } }); final EditTextPreference debug_tag = (EditTextPreference) findPreference(Aware_Preferences.DEBUG_TAG); debug_tag.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG)); debug_tag.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.TAG = (String) newValue; Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG, (String) newValue); return true; } }); final CheckBoxPreference auto_update = (CheckBoxPreference) findPreference( Aware_Preferences.AWARE_AUTO_UPDATE); auto_update.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE).equals("true")); PackageInfo awareInfo = null; try { awareInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES); } catch (NameNotFoundException e) { e.printStackTrace(); } auto_update.setSummary("Current version is " + ((awareInfo != null) ? awareInfo.versionCode : "???")); auto_update.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE, auto_update.isChecked()); return true; } }); final CheckBoxPreference debug_db_slow = (CheckBoxPreference) findPreference( Aware_Preferences.DEBUG_DB_SLOW); debug_db_slow.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true")); debug_db_slow.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW, debug_db_slow.isChecked()); return true; } }); final EditTextPreference device_id = (EditTextPreference) findPreference(Aware_Preferences.DEVICE_ID); device_id.setSummary("UUID: " + Aware.getSetting(getApplicationContext(), DEVICE_ID)); device_id.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID)); device_id.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, (String) newValue); device_id.setSummary( "UUID: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID)); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Bluetooth module settings UI/* www.ja v a2 s . c om*/ */ private void bluetooth() { final CheckBoxPreference bluetooth = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_BLUETOOTH); bluetooth.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_BLUETOOTH).equals("true")); bluetooth.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); bluetooth.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BLUETOOTH, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BLUETOOTH, bluetooth.isChecked()); if (bluetooth.isChecked()) { framework.startBluetooth(); } else { framework.stopBluetooth(); } return true; } }); final EditTextPreference bluetoothInterval = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_BLUETOOTH); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BLUETOOTH).length() > 0) { bluetoothInterval.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BLUETOOTH) + " seconds"); } bluetoothInterval.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BLUETOOTH)); bluetoothInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_BLUETOOTH, (String) newValue); bluetoothInterval.setSummary((String) newValue + " seconds"); framework.startBluetooth(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Gyroscope module settings UI//from w w w . jav a 2s . c om */ 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/*w w w . j a v a2s . 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
/** * MQTT module settings UI/*from w w w .jav a 2s . co m*/ */ private void mqtt() { final CheckBoxPreference mqtt = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_MQTT); mqtt.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_MQTT).equals("true")); mqtt.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER).length() == 0) { showDialog(DIALOG_ERROR_MISSING_PARAMETERS); mqtt.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MQTT, false); return false; } else { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MQTT, mqtt.isChecked()); if (mqtt.isChecked()) { framework.startMQTT(); } else { framework.stopMQTT(); } return true; } } }); final EditTextPreference mqttServer = (EditTextPreference) findPreference(Aware_Preferences.MQTT_SERVER); mqttServer.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER)); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER).length() > 0) { mqttServer.setSummary( "Server: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER)); } mqttServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER, (String) newValue); mqttServer.setSummary("Server: " + (String) newValue); return true; } }); final EditTextPreference mqttPort = (EditTextPreference) findPreference(Aware_Preferences.MQTT_PORT); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT).length() > 0) { mqttPort.setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT)); } mqttPort.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT)); mqttPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT, (String) newValue); return true; } }); final EditTextPreference mqttUsername = (EditTextPreference) findPreference( Aware_Preferences.MQTT_USERNAME); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME).length() > 0) { mqttUsername.setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME)); } mqttUsername.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME)); mqttUsername.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME, (String) newValue); return true; } }); final EditTextPreference mqttPassword = (EditTextPreference) findPreference( Aware_Preferences.MQTT_PASSWORD); mqttPassword.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PASSWORD)); mqttPassword.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_PASSWORD, (String) newValue); return true; } }); final EditTextPreference mqttKeepAlive = (EditTextPreference) findPreference( Aware_Preferences.MQTT_KEEP_ALIVE); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE).length() > 0) { mqttKeepAlive.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE) + " seconds"); } mqttKeepAlive.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE)); mqttKeepAlive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE, (String) newValue); mqttKeepAlive.setSummary((String) newValue + " seconds"); return true; } }); final EditTextPreference mqttQoS = (EditTextPreference) findPreference(Aware_Preferences.MQTT_QOS); mqttQoS.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_QOS)); mqttQoS.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_QOS, (String) newValue); return true; } }); final EditTextPreference mqttProtocol = (EditTextPreference) findPreference( Aware_Preferences.MQTT_PROTOCOL); mqttProtocol.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PROTOCOL)); mqttProtocol.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_PROTOCOL, (String) newValue); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Temperature module settings UI// w ww . j a v 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
/** * Magnetometer module settings UI/*from w ww. ja va 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; } }); }