List of usage examples for android.preference PreferenceScreen setSummary
public void setSummary(CharSequence summary)
From source file:github.popeen.dsub.fragments.SettingsFragment.java
private PreferenceScreen expandServer(final int instance) { final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); final EditTextPreference serverNamePreference = new EditTextPreference(context); serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); }//from w ww . ja v a 2 s .c o m serverNamePreference.setSummary(serverNamePreference.getText()); final EditTextPreference serverUrlPreference = new EditTextPreference(context); serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance); serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); } serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { super.onAddEditTextToDialogView(dialogView, editText); ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0); Button defaultButton = new Button(getContext()); defaultButton.setText(internalSSIDDisplay); defaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(internalSSID); } }); root.addView(defaultButton); } }; serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue(""); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(context); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(context); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); serverPasswordPreference.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); serverPasswordPreference.setSummary("***"); serverPasswordPreference.setTitle(R.string.settings_server_password); final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); serverOpenBrowser.setTitle(R.string.settings_server_open_browser); serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { openInBrowser(instance); return true; } }); Preference serverRemoveServerPreference = new Preference(context); serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance); serverRemoveServerPreference.setPersistent(false); serverRemoveServerPreference.setTitle(R.string.settings_servers_remove); serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Reset values to null so when we ask for them again they are new serverNamePreference.setText(null); serverUrlPreference.setText(null); serverUsernamePreference.setText(null); serverPasswordPreference.setText(null); // Don't use Util.getActiveServer since it is 0 if offline int activeServer = Util.getPreferences(context) .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); for (int i = instance; i <= serverCount; i++) { Util.removeInstanceName(context, i, activeServer); } serverCount--; SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.commit(); removeCurrent(); SubsonicFragment parentFragment = context.getCurrentFragment(); if (parentFragment instanceof SettingsFragment) { SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment; serverSelectionFragment.checkForRemoved(); } } }); return true; } }); Preference serverTestConnectionPreference = new Preference(context); serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance); serverTestConnectionPreference.setPersistent(false); serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title); serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { testConnection(instance); return false; } }); screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverSyncPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); return screen; }
From source file:github.daneren2005.dsub.fragments.SettingsFragment.java
private PreferenceScreen expandServer(final int instance) { final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); final EditTextPreference serverNamePreference = new EditTextPreference(context); serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); }/*from w w w. j a v a 2 s. c om*/ serverNamePreference.setSummary(serverNamePreference.getText()); final EditTextPreference serverUrlPreference = new EditTextPreference(context); serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance); serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); } serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { super.onAddEditTextToDialogView(dialogView, editText); ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0); Button defaultButton = new Button(getContext()); defaultButton.setText(internalSSIDDisplay); defaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(internalSSID); } }); root.addView(defaultButton); } }; serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue(""); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(context); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(context); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); serverPasswordPreference.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); serverPasswordPreference.setSummary("***"); serverPasswordPreference.setTitle(R.string.settings_server_password); final CheckBoxPreference serverTagPreference = new CheckBoxPreference(context); serverTagPreference.setKey(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance); serverTagPreference.setChecked(Util.isTagBrowsing(context, instance)); serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary); serverTagPreference.setTitle(R.string.settings_browse_by_tags); serverPasswordPreference.setDialogTitle(R.string.settings_server_password); final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); serverOpenBrowser.setTitle(R.string.settings_server_open_browser); serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { openInBrowser(instance); return true; } }); Preference serverRemoveServerPreference = new Preference(context); serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance); serverRemoveServerPreference.setPersistent(false); serverRemoveServerPreference.setTitle(R.string.settings_servers_remove); serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Reset values to null so when we ask for them again they are new serverNamePreference.setText(null); serverUrlPreference.setText(null); serverUsernamePreference.setText(null); serverPasswordPreference.setText(null); // Don't use Util.getActiveServer since it is 0 if offline int activeServer = Util.getPreferences(context) .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); for (int i = instance; i <= serverCount; i++) { Util.removeInstanceName(context, i, activeServer); } serverCount--; SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.commit(); removeCurrent(); SubsonicFragment parentFragment = context.getCurrentFragment(); if (parentFragment instanceof SettingsFragment) { SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment; serverSelectionFragment.checkForRemoved(); } } }); return true; } }); Preference serverTestConnectionPreference = new Preference(context); serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance); serverTestConnectionPreference.setPersistent(false); serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title); serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { testConnection(instance); return false; } }); screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverTagPreference); screen.addPreference(serverSyncPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); return screen; }
From source file:com.aware.Aware_Preferences.java
/** * Light module settings UI/*from w ww .j a v a 2 s . com*/ */ private void light() { final PreferenceScreen light_pref = (PreferenceScreen) findPreference("light"); Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT); if (temp != null) { light_pref.setSummary( light_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA")); } else { light_pref.setSummary(light_pref.getSummary().toString().replace("*", "")); } final CheckBoxPreference light = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_LIGHT); light.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_LIGHT).equals("true")); light.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (mSensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT) == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); light.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LIGHT, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LIGHT, light.isChecked()); if (light.isChecked()) { framework.startLight(); } else { framework.stopLight(); } return true; } }); final EditTextPreference frequency_light = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_LIGHT); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT).length() > 0) { frequency_light.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT) + " microseconds"); } frequency_light.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT)); frequency_light.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT, (String) newValue); frequency_light.setSummary((String) newValue + " microseconds"); framework.startLight(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Gravity module settings UI/*from www.j ava 2s .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.aware.Aware_Preferences.java
/** * Atmospheric Pressure module settings UI */// www. j a va 2s. 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 . j a va 2 s . co 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
/** * Temperature module settings UI/*w w w .j ava 2s .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
/** * Rotation module settings UI//from w w w . j a v a 2 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
/** * Magnetometer module settings UI//from w ww . j ava 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/*from w ww .j av a 2s .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; } }); }