Java Code Examples for android.preference.EditTextPreference#setText()
The following examples show how to use
android.preference.EditTextPreference#setText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetupActivity.java From trigger with GNU General Public License v2.0 | 6 votes |
private void setText(String key, String value) { Preference p = findAnyPreference(key, null); if (p instanceof EditTextPreference) { EditTextPreference etp = (EditTextPreference) p; etp.setText(value); // show value as summary etp.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { preference.setSummary(getSummaryValue(key, newValue.toString())); return true; }); etp.setSummary(getSummaryValue(key, value)); } else if (p instanceof ListPreference) { ListPreference lp = (ListPreference) p; lp.setValue(value); // set summary field to "%s" in xml } else { Log.w("SetupActivity.setText", "Cannot find EditTextPreference/ListPreference in PreferenceGroup with key: " + key); } }
Example 2
Source File: TrackPreferenceFragment.java From tickmate with GNU General Public License v3.0 | 6 votes |
private void loadTrack() { Log.d(TAG, "Loading track #" + track.getId()); icon = (IconPreference) findPreference("icon"); icon.setText(track.getIcon()); name = (EditTextPreference) findPreference("name"); name.setText(track.getName()); name.setSummary(track.getName()); description = (EditTextPreference) findPreference("description"); description.setText(track.getDescription()); description.setSummary(track.getDescription()); enabled = (CheckBoxPreference) findPreference("enabled"); enabled.setChecked(track.isEnabled()); multiple_entries_enabled = (CheckBoxPreference) findPreference("multiple_entries_enabled"); multiple_entries_enabled.setChecked(track.multipleEntriesEnabled()); mGroupsPref = (GroupListPreference) findPreference("groups"); mGroupsPref.setTrack(track); mGroupsPref.populate(); mTickColorPreference = (TickColorPreference) findPreference("tick_button_color"); mTickColorPreference.setColor(track.getTickColor()); }
Example 3
Source File: ConnectionPrefsFragment.java From xpra-client with GNU General Public License v3.0 | 6 votes |
protected void setSshPreferencesEnabled(boolean enabled) { final EditTextPreference portPref = (EditTextPreference) findPreference(PREF_PORT); if(enabled) { if("10000".equals(portPref.getText())) { portPref.setText("22"); PreferenceHelper.callChangeListener(portPref, portPref.getText()); } } else { if("22".equals(portPref.getText())) { portPref.setText("10000"); PreferenceHelper.callChangeListener(portPref, portPref.getText()); } } findPreference(PREF_USERNAME).setEnabled(enabled); findPreference(PREF_PRIVATE_KEY).setEnabled(enabled); }
Example 4
Source File: PreferencesActivity.java From ministocks with MIT License | 6 votes |
private void updateStockValue(SharedPreferences sharedPreferences, String key) { // Unregister the listener whenever a key changes getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); // Massages the value: remove whitespace and upper-case String value = sharedPreferences.getString(key, ""); value = value.replace(" ", ""); value = value.toUpperCase(); Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.apply(); // Also update the UI EditTextPreference preference = (EditTextPreference) findPreference(key); preference.setText(value); // Set up a listener whenever a key changes sharedPreferences.registerOnSharedPreferenceChangeListener(this); }
Example 5
Source File: PreferencesActivity.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
private static void adjustUnitDependentPrefs(Preference pref) { // convert preferences values to current units String[] unitDependent = new String[]{ MainApp.gs(R.string.key_hypo_target), MainApp.gs(R.string.key_activity_target), MainApp.gs(R.string.key_eatingsoon_target), MainApp.gs(R.string.key_high_mark), MainApp.gs(R.string.key_low_mark) }; if (Arrays.asList(unitDependent).contains(pref.getKey())) { EditTextPreference editTextPref = (EditTextPreference) pref; String converted = Profile.toCurrentUnitsString(SafeParse.stringToDouble(editTextPref.getText())); editTextPref.setSummary(converted); editTextPref.setText(converted); } }
Example 6
Source File: Preferences.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void updateMibandPreferencesData(){ EditTextPreference prefMac = (EditTextPreference) findPreference(MiBandEntry.PREF_MIBAND_MAC); if (prefMac != null ) { prefMac.setText(MiBand.getMac()); sBindPreferenceTitleAppendToMacValueListener.onPreferenceChange(prefMac, PreferenceManager .getDefaultSharedPreferences(prefMac.getContext()) .getString(prefMac.getKey(), "")); } EditTextPreference prefAuthKey = (EditTextPreference) findPreference(MiBandEntry.PREF_MIBAND_AUTH_KEY); if (prefAuthKey != null )prefAuthKey.setText(MiBand.getAuthKey()); }
Example 7
Source File: Preferences.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static void setSummary_static(AllPrefsFragment allPrefsFragment, String pref_name) { try { // is there a cleaner way to bind these values when setting programatically? final String pref_val = allPrefsFragment.prefs.getString(pref_name, ""); allPrefsFragment.findPreference(pref_name).setSummary(pref_val); EditTextPreference thispref = (EditTextPreference) allPrefsFragment.findPreference(pref_name); thispref.setText(pref_val); } catch (Exception e) { Log.e(TAG, "Exception during setSummary: " + e.toString()); } }
Example 8
Source File: SettingsFragment.java From Linphone4Android with GNU General Public License v3.0 | 5 votes |
private void initNetworkSettings() { ((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key))).setChecked(mPrefs.isWifiOnlyEnabled()); // Disable UPnP if ICE si enabled, or disable ICE if UPnP is enabled CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key)); CheckBoxPreference turn = (CheckBoxPreference) findPreference(getString(R.string.pref_turn_enable_key)); ice.setChecked(mPrefs.isIceEnabled()); turn.setEnabled(mPrefs.getStunServer() != null); turn.setChecked(mPrefs.isTurnEnabled()); EditTextPreference turnUsername = (EditTextPreference) findPreference(getString(R.string.pref_turn_username_key)); EditTextPreference turnPassword = (EditTextPreference) findPreference(getString(R.string.pref_turn_passwd_key)); turnUsername.setEnabled(mPrefs.isTurnEnabled()); turnUsername.setSummary(mPrefs.getTurnUsername()); turnUsername.setText(mPrefs.getTurnUsername()); turnPassword.setEnabled(mPrefs.isTurnEnabled()); CheckBoxPreference randomPort = (CheckBoxPreference) findPreference(getString(R.string.pref_transport_use_random_ports_key)); randomPort.setChecked(mPrefs.isUsingRandomPort()); // Disable sip port choice if port is random EditTextPreference sipPort = (EditTextPreference) findPreference(getString(R.string.pref_sip_port_key)); sipPort.setEnabled(!randomPort.isChecked()); sipPort.setSummary(mPrefs.getSipPort()); sipPort.setText(mPrefs.getSipPort()); EditTextPreference stun = (EditTextPreference) findPreference(getString(R.string.pref_stun_server_key)); stun.setSummary(mPrefs.getStunServer()); stun.setText(mPrefs.getStunServer()); ((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key))).setChecked(mPrefs.isPushNotificationEnabled()); ((CheckBoxPreference) findPreference(getString(R.string.pref_ipv6_key))).setChecked(mPrefs.isUsingIpv6()); }
Example 9
Source File: SettingsActivity.java From AnkiDroid-Wear with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.activity_settings); NumberPickerPreference fontSizeNumberPicker = (NumberPickerPreference) this.findPreference(getResources().getString(R.string.font_size_key)); NumberPickerPreference screenTimeoutNumberPicker = (NumberPickerPreference) this.findPreference(getResources().getString(R.string.screen_timeout)); EditTextPreference mediaLocationDir = (EditTextPreference) this.findPreference(getResources().getString(R.string.media_folder_location)); if (mediaLocationDir.getText() == null || mediaLocationDir.getText().isEmpty()) { mediaLocationDir.setText(Environment.getExternalStorageDirectory() + "/AnkiDroid/collection.media"); } CardMedia.mediaFolder = mediaLocationDir.getText(); SendToWatchWhenPreferencesChangeListener listener = new SendToWatchWhenPreferencesChangeListener(); fontSizeNumberPicker.setOnPreferenceChangeListener(listener); screenTimeoutNumberPicker.setOnPreferenceChangeListener(listener); this.findPreference(getResources().getString(R.string.card_flip_animation_key)).setOnPreferenceChangeListener(listener); this.findPreference(getResources().getString(R.string.double_tap_key)).setOnPreferenceChangeListener(listener); this.findPreference(getResources().getString(R.string.play_sounds)).setOnPreferenceChangeListener(listener); this.findPreference(getResources().getString(R.string.ask_before_first_sound)).setOnPreferenceChangeListener(listener); this.findPreference(getResources().getString(R.string.day_mode)).setOnPreferenceChangeListener(listener); this.findPreference(getResources().getString(R.string.ambient_mode_key)) .setOnPreferenceChangeListener(listener); mediaLocationDir.setOnPreferenceChangeListener(listener); }
Example 10
Source File: ResourceSettings.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Sets the default values for the preference screen */ private void initPreferences() { // Binary file location EditTextPreference binaryFileLocation = (EditTextPreference) findPreference(Constants.PREFERENCE_STORAGE_DIRECTORY); if (TextUtils.isEmpty(binaryFileLocation.getText())) { binaryFileLocation.setText(EnvironmentUtil.getProcedureDirectory()); } // Image downscale factor EditTextPreference imageDownscale = (EditTextPreference) findPreference(Constants.PREFERENCE_IMAGE_SCALE); if (TextUtils.isEmpty(imageDownscale.getText())) { imageDownscale.setText("" + Constants.IMAGE_SCALE_FACTOR); } imageDownscale.getEditText().setKeyListener(new DigitsKeyListener()); // View all edu resources PreferenceScreen resourcePref = (PreferenceScreen) findPreference("s_education_resource"); Intent intent = EducationResourceList.getIntent(Intent.ACTION_PICK, Audience.ALL); intent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_VIEW)); resourcePref.setIntent(intent); // SD card loading procedures PreferenceScreen intentPref = (PreferenceScreen) findPreference("s_procedures"); intentPref.setIntent(new Intent("org.sana.android.activity.IMPORT_PROCEDURE")); //intentPref.setIntent(new Intent(ResourceSettings.this, // ProcedureSdImporter.class)); }
Example 11
Source File: SettingsFragment.java From Linphone4Android with GNU General Public License v3.0 | 5 votes |
private void setPreferenceDefaultValueAndSummary(int pref, String value) { if (value != null) { EditTextPreference etPref = (EditTextPreference) findPreference(getString(pref)); if (etPref != null) { etPref.setText(value); etPref.setSummary(value); } } }
Example 12
Source File: Settings.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Sets the default values for the the preferences */ private void initPreferences() { // Health worker username for OpenMRS EditTextPreference prefEmrUsername = (EditTextPreference) findPreference(Constants.PREFERENCE_EMR_USERNAME); if (TextUtils.isEmpty(prefEmrUsername.getText())) { prefEmrUsername.setText(Constants.DEFAULT_USERNAME); } // Health worker password for OpenMRS EditTextPreference prefEmrPassword = (EditTextPreference) findPreference(Constants.PREFERENCE_EMR_PASSWORD); prefEmrPassword.getEditText().setTransformationMethod( new PasswordTransformationMethod()); if (TextUtils.isEmpty(prefEmrPassword.getText())) { prefEmrPassword.setText(Constants.DEFAULT_PASSWORD); } // Whether barcode reading is enabled on the phone /* * CheckBoxPreference barcodeEnabled = new CheckBoxPreference(this); * barcodeEnabled.setKey(Constants.PREFERENCE_BARCODE_ENABLED); * barcodeEnabled.setTitle("Enable barcode reading"); * barcodeEnabled.setSummary * ("Enable barcode reading of patient and physician ids"); * barcodeEnabled.setDefaultValue(false); * dialogBasedPrefCat.addPreference(barcodeEnabled); */ // Launches network preferences PreferenceScreen prefNetwork = (PreferenceScreen) findPreference("s_network_settings"); if (prefNetwork != null) { prefNetwork.setIntent(new Intent(this, NetworkSettings.class)); } // Launches resource preferences PreferenceScreen prefResource = (PreferenceScreen) findPreference("s_resource_settings"); if (prefResource != null) { prefResource.setIntent(new Intent(this, ResourceSettings.class)); } }
Example 13
Source File: CreateModulePreference.java From GNSS_Compare with Apache License 2.0 | 5 votes |
/** * defines a name preference * @param intentExtras intent passed to the preference */ private void defineNamePreference(Bundle intentExtras){ EditTextPreference prefName = (EditTextPreference) findPreference(KEY_NAME); if(intentExtras == null) { prefName.setText("Scheme " + ALPHABET[invocationCounter]); } else { prefName.setText(intentExtras.getString(KEY_NAME)); } }
Example 14
Source File: ActivitiesTest.java From tickmate with GNU General Public License v3.0 | 5 votes |
@Test public void editTrackActivityStoresChanges() throws Exception { openMethod.invoke(dataSource); Track t = new Track("Testing", "Run my tests"); t.setEnabled(true); dataSource.storeTrack(t); closeMethod.invoke(dataSource); assertThat(t, equalTo(t)); Intent i = new Intent(RuntimeEnvironment.application.getApplicationContext(), tickmate.getClass()); i.putExtra("track_id", t.getId()); ActivityController<TrackPreferenceActivity> r_eta = Robolectric.buildActivity(TrackPreferenceActivity.class) .withIntent(i) .create(new Bundle()) .start() .resume(); TrackPreferenceActivity eta = r_eta.get(); TrackPreferenceFragment tpf = (TrackPreferenceFragment) eta.getFragmentManager().findFragmentById(android.R.id.content); EditTextPreference description = (EditTextPreference) tpf.findPreference("description"); assertThat(description.getText().toString(), is("Run my tests")); description.setText("Krishna Hare"); r_eta.pause(); r_eta.stop(); Track t_also = dataSource.getTrack(t.getId()); assertThat(t, equalTo(t_also)); assertThat(t_also.getName(), is(t.getName())); assertThat(t_also.getIcon(), is(t.getIcon())); assertThat(t_also.getDescription(), is("Krishna Hare")); assertThat(t_also.isEnabled(), is(t.isEnabled())); }
Example 15
Source File: SettingsActivity.java From android-app with GNU General Public License v3.0 | 5 votes |
private void setTextPreference(int preferenceID, String value) { EditTextPreference preference = (EditTextPreference) findPreference(getString(preferenceID)); if(preference != null) { preference.setText(value); } }
Example 16
Source File: Settings.java From SMP with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { Log.d("Settings", "onCreate"); super.onCreate(savedInstanceState); params = new ParametersImpl(this); // fixme: everything should be put in onResume? addPreferencesFromResource(R.xml.preferences); playIntent = new Intent(this, MusicService.class); bindService(playIntent, musicConnection, Context.BIND_AUTO_CREATE); SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); String thresholdKeys = PrefKeys.SHAKE_THRESHOLD.name(); EditTextPreference prefShakeThreshold = (EditTextPreference) findPreference(thresholdKeys); CheckBoxPreference prefEnableShake = (CheckBoxPreference) findPreference(PrefKeys.ENABLE_SHAKE.name()); if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)) { prefShakeThreshold.setSummary(String.valueOf(params.getShakeThreshold())); prefEnableShake.setChecked(params.getEnableShake()); } else { prefShakeThreshold.setEnabled(false); prefEnableShake.setEnabled(false); Toast.makeText(getApplicationContext(), getResources().getString(R.string.settings_no_accelerometer), Toast.LENGTH_LONG).show(); } findPreference(PrefKeys.TEXT_SIZE_NORMAL.name()).setSummary(String.valueOf(params.getNormalTextSize())); findPreference(PrefKeys.TEXT_SIZE_BIG.name()).setSummary(String.valueOf(params.getBigTextSize())); findPreference(PrefKeys.TEXT_SIZE_RATIO.name()).setSummary(String.valueOf(params.getTextSizeRatio())); Preference rescan = findPreference(getResources().getString(R.string.settings_rescan_key)); rescan.setOnPreferenceClickListener(this); Preference donate = findPreference(getResources().getString(R.string.settings_donate_key)); donate.setOnPreferenceClickListener(this); setUnfoldSubgroup(); setUnfoldThresholdSummary(); String rootFoldersKey = PrefKeys.ROOT_FOLDERS.name(); EditTextPreference prefRootFolders = (EditTextPreference) findPreference(rootFoldersKey); prefRootFolders.setSummary(params.getRootFolders()); if(!sharedPreferences.contains(rootFoldersKey)) prefRootFolders.setText(Path.getMusicStoragesStr(getBaseContext())); setFoldSummary(); this.onContentChanged(); }
Example 17
Source File: NetworkSettings.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Sets the default values for the preference screen */ private void initPreferences() { // Phone name String phoneNum = ((TelephonyManager) getSystemService( Context.TELEPHONY_SERVICE)) .getLine1Number(); Log.d(TAG, "Phone number of this phone: " + phoneNum); if (TextUtils.isEmpty(phoneNum)) phoneNum = Constants.DEFAULT_PHONE_NUMBER; EditTextPreference prefPhoneName = (EditTextPreference) findPreference(Constants.PREFERENCE_PHONE_NAME); if (TextUtils.isEmpty(prefPhoneName.getText())) { prefPhoneName.setText(phoneNum); } // Sana Dispatch Server URL EditTextPreference prefMdsUrl = (EditTextPreference) findPreference(Constants.PREFERENCE_MDS_URL); if (TextUtils.isEmpty(prefMdsUrl.getText())) { prefMdsUrl.setText(Constants.DEFAULT_DISPATCH_SERVER); } // Initial packet size EditTextPreference prefInitPacketSize = (EditTextPreference) findPreference(Constants.PREFERENCE_PACKET_SIZE); if (TextUtils.isEmpty(prefMdsUrl.getText())) { prefInitPacketSize.setText("" + Constants.DEFAULT_INIT_PACKET_SIZE); } prefInitPacketSize.getEditText().setKeyListener(new DigitsKeyListener()); // How often the database gets refreshed EditTextPreference prefDatabaseRefresh = (EditTextPreference) findPreference(Constants.PREFERENCE_DATABASE_UPLOAD); if (TextUtils.isEmpty(prefDatabaseRefresh.getText())) { prefDatabaseRefresh.setText("" + Constants.DEFAULT_DATABASE_UPLOAD); } prefDatabaseRefresh.getEditText().setKeyListener(new DigitsKeyListener()); // Estimated network bandwidth EditTextPreference prefEstimatedNetworkBandwidth = (EditTextPreference) findPreference(Constants.PREFERENCE_NETWORK_BANDWIDTH); if (TextUtils.isEmpty(prefEstimatedNetworkBandwidth.getText())) { prefEstimatedNetworkBandwidth.setText("" + Constants.ESTIMATED_NETWORK_BANDWIDTH); } prefEstimatedNetworkBandwidth.getEditText().setKeyListener( new DigitsKeyListener()); }
Example 18
Source File: Advanced.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
private void setFieldTextSafe(EditTextPreference pref, String value) { if(pref != null) { pref.setText(value); } }
Example 19
Source File: SwitchAccessPreferenceActivity.java From talkback with Apache License 2.0 | 4 votes |
private void updatePreferenceValue(EditTextPreference preference, String newValue) { preference.setText(newValue); preference.getOnPreferenceChangeListener().onPreferenceChange(preference, newValue); }
Example 20
Source File: Settings.java From SMP with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { Log.d("Settings", "onCreate"); super.onCreate(savedInstanceState); params = new ParametersImpl(this); // fixme: everything should be put in onResume? addPreferencesFromResource(R.xml.preferences); playIntent = new Intent(this, MusicService.class); bindService(playIntent, musicConnection, Context.BIND_AUTO_CREATE); SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); String thresholdKeys = PrefKeys.SHAKE_THRESHOLD.name(); EditTextPreference prefShakeThreshold = (EditTextPreference) findPreference(thresholdKeys); CheckBoxPreference prefEnableShake = (CheckBoxPreference) findPreference(PrefKeys.ENABLE_SHAKE.name()); if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)) { prefShakeThreshold.setSummary(String.valueOf(params.getShakeThreshold())); prefEnableShake.setChecked(params.getEnableShake()); } else { prefShakeThreshold.setEnabled(false); prefEnableShake.setEnabled(false); Toast.makeText(getApplicationContext(), getResources().getString(R.string.settings_no_accelerometer), Toast.LENGTH_LONG).show(); } findPreference(PrefKeys.TEXT_SIZE_NORMAL.name()).setSummary(String.valueOf(params.getNormalTextSize())); findPreference(PrefKeys.TEXT_SIZE_BIG.name()).setSummary(String.valueOf(params.getBigTextSize())); findPreference(PrefKeys.TEXT_SIZE_RATIO.name()).setSummary(String.valueOf(params.getTextSizeRatio())); Preference rescan = findPreference(getResources().getString(R.string.settings_rescan_key)); rescan.setOnPreferenceClickListener(this); Preference donate = findPreference(getResources().getString(R.string.settings_donate_key)); donate.setOnPreferenceClickListener(this); setUnfoldSubgroup(); setUnfoldThresholdSummary(); String rootFoldersKey = PrefKeys.ROOT_FOLDERS.name(); EditTextPreference prefRootFolders = (EditTextPreference) findPreference(rootFoldersKey); prefRootFolders.setSummary(params.getRootFolders()); if(!sharedPreferences.contains(rootFoldersKey)) prefRootFolders.setText(Path.getMusicStoragesStr(getBaseContext())); setFoldSummary(); this.onContentChanged(); }