@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getPreferenceManager() != null) { addPreferencesFromResource(R.xml.operator_preferences); PreferenceScreen prefSet = getPreferenceScreen(); mOperatorDisplayStyle = (ListPreference) prefSet.findPreference(OPERATOR_STYLE); mOperatorDisplayStyle.setOnPreferenceChangeListener(this); mOperatorDisplayText = (EditTextPreference) prefSet.findPreference(OPERATOR_TEXT); mOperatorDisplayText.setOnPreferenceChangeListener(this); if (mOperatorDisplayText != null) { String operLabel = mOperatorDisplayText.getText(); if (TextUtils.isEmpty(operLabel)) { mOperatorDisplayText.setSummary(getString(R.string.operator_display_summary)); } else { mOperatorDisplayText.setSummary(mOperatorDisplayText.getText()); } } int index = Settings.System.getInt(getContentResolver(), CARRIER_LABEL_TYPE, 0); index = index > (mOperatorDisplayStyle.getEntries().length - 1) ? 0 : index; mOperatorDisplayStyle.setSummary(mOperatorDisplayStyle.getEntries()[index]); mOperatorDisplayText.setEnabled(index == 3); } }
/** * Basic implementation of the account building based on simple implementation fields. A * specification of this class could extend and add its own post processing here. * * <p>{@inheritDoc} */ public SipProfile buildAccount(SipProfile account) { account.display_name = accountDisplayName.getText().trim(); account.acc_id = "<sip:" + SipUri.encodeUser(accountUsername.getText().trim()) + "@" + getDomain() + ">"; String regUri = "sip:" + getDomain(); account.reg_uri = regUri; account.proxies = new String[] {regUri}; account.realm = "*"; account.username = getText(accountUsername).trim(); account.data = getText(accountPassword); account.scheme = SipProfile.CRED_SCHEME_DIGEST; account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD; account.reg_timeout = 1800; if (canTcp()) { account.transport = accountUseTcp.isChecked() ? SipProfile.TRANSPORT_TCP : SipProfile.TRANSPORT_UDP; } else { account.transport = SipProfile.TRANSPORT_UDP; } return account; }
// Utilities functions protected boolean isEmpty(EditTextPreference edt) { if (edt.getText() == null) { return true; } if (edt.getText().equals("")) { return true; } return false; }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(LIST_SCALE)) { ListPreference listScalePref = (ListPreference) findPreference(LIST_SCALE); listScalePref.setSummary(listScalePref.getEntry()); } else if (key.equals(VIDEO_START_DELAY)) { EditTextPreference videoStartPref = (EditTextPreference) findPreference(VIDEO_START_DELAY); videoStartPref.setSummary(videoStartPref.getText()); } else if (key.equals(SEND_EMAIL_ADDRESS)) { EditTextPreference emailAddressPref = (EditTextPreference) findPreference(SEND_EMAIL_ADDRESS); emailAddressPref.setSummary(emailAddressPref.getText()); } }
/** Sets the default values for the the preferences */ 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); } // 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)); } }
private boolean IsFormValid() { CheckBoxPreference chkEnabled = (CheckBoxPreference) findPreference("opengts_enabled"); EditTextPreference txtOpenGTSServer = (EditTextPreference) findPreference("opengts_server"); EditTextPreference txtOpenGTSServerPort = (EditTextPreference) findPreference("opengts_server_port"); ListPreference txtOpenGTSCommunicationMethod = (ListPreference) findPreference("opengts_server_communication_method"); EditTextPreference txtOpenGTSServerPath = (EditTextPreference) findPreference("autoopengts_server_path"); EditTextPreference txtOpenGTSDeviceId = (EditTextPreference) findPreference("opengts_device_id"); return !chkEnabled.isChecked() || txtOpenGTSServer.getText() != null && txtOpenGTSServer.getText().length() > 0 && txtOpenGTSServerPort.getText() != null && isNumeric(txtOpenGTSServerPort.getText()) && txtOpenGTSCommunicationMethod.getValue() != null && txtOpenGTSCommunicationMethod.getValue().length() > 0 && txtOpenGTSDeviceId.getText() != null && txtOpenGTSDeviceId.getText().length() > 0 && URLUtil.isValidUrl( "http://" + txtOpenGTSServer.getText() + ":" + txtOpenGTSServerPort.getText() + txtOpenGTSServerPath.getText()); }
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); if (DBG) log("Settings: onCreate()..."); getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES_NAME); // This preference screen is ultra-simple; it's just 4 plain // <EditTextPreference>s, one for each of the 4 "canned responses". // // The only nontrivial thing we do here is copy the text value of // each of those EditTextPreferences and use it as the preference's // "title" as well, so that the user will immediately see all 4 // strings when they arrive here. // // Also, listen for change events (since we'll need to update the // title any time the user edits one of the strings.) addPreferencesFromResource(R.xml.respond_via_sms_settings); EditTextPreference pref; pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_1); pref.setTitle(pref.getText()); pref.setOnPreferenceChangeListener(this); pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_2); pref.setTitle(pref.getText()); pref.setOnPreferenceChangeListener(this); pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_3); pref.setTitle(pref.getText()); pref.setOnPreferenceChangeListener(this); pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_4); pref.setTitle(pref.getText()); pref.setOnPreferenceChangeListener(this); /* Begin: Modified by zxiaona for add_autosms 2012/07/27 */ pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_5); pref.setTitle(pref.getText()); pref.setOnPreferenceChangeListener(this); /* End: Modified by zxiaona for add_autosms 2012/07/27 */ ActionBar actionBar = getActionBar(); if (actionBar != null) { // android.R.id.home will be triggered in onOptionsItemSelected() actionBar.setDisplayHomeAsUpEnabled(true); } }
private static int getIntValue(EditTextPreference pref, int defaultValue) { try { return Integer.parseInt(pref.getText()); } catch (NumberFormatException e) { Log.e(THIS_FILE, "List item is not a number"); } return defaultValue; }
public SipProfile buildAccount(SipProfile account) { account.display_name = accountDisplayName.getText(); account.acc_id = "<sip:" + SipUri.encodeUser(accountUsername.getText().trim()) + "@" + getDomain() + ">"; String regUri = "sip:" + getDomain(); account.reg_uri = regUri; account.proxies = new String[] {"sip:" + accountProxy.getText()}; account.realm = "*"; account.username = getText(accountAuthorization).trim(); account.data = getText(accountPassword); account.scheme = SipProfile.CRED_SCHEME_DIGEST; account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD; account.reg_timeout = 1800; account.transport = SipProfile.TRANSPORT_UDP; return account; }
private void updatePrefSummary(Preference p, boolean updatevis) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummary(listPref.getEntry()); } else if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummary(editTextPref.getText()); } }
private void initPreference(String name) { Preference preference = findPreference(name); if (preference instanceof EditTextPreference) { preference.setOnPreferenceChangeListener(this); EditTextPreference p = (EditTextPreference) preference; preference.setSummary(p.getText()); } else if (preference instanceof ButtonPreference) { preference.setOnPreferenceChangeListener(this); preference.setOnPreferenceClickListener(this); } }
/* * @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String) */ @TargetApi(9) public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals("torrentleech_username")) { Preference pref = findPreference(key); EditTextPreference etpUsername = (EditTextPreference) pref; if (etpUsername.getText().isEmpty()) { etpUsername.setSummary(getResources().getString(R.string.enter_your_username)); } else { pref.setSummary(etpUsername.getText()); } } try { DateFormat dftFormat = new SimpleDateFormat("ddMMyyyy"); String strFilename = dftFormat.format(new Date()); if (this.getApplicationContext().getFileStreamPath(strFilename).exists()) { this.getApplicationContext().getFileStreamPath(strFilename).delete(); } } catch (Exception e) { Log.e( "fragments.SettingsFragment", "An error occurred when flusing the day's cache after a preference changed.", e); } if (key.equals("torrentleech_password")) { Preference pref = findPreference(key); EditTextPreference etpPassword = (EditTextPreference) pref; if (etpPassword.getText().isEmpty()) { etpPassword.setSummary(getResources().getString(R.string.enter_your_password)); } else { pref.setSummary(etpPassword.getText().replaceAll("(?s).", "*")); } } }
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof EditTextPreference) { EditTextPreference etp = (EditTextPreference) pref; pref.setSummary(etp.getText()); } else if (pref instanceof ListPreference) { ListPreference lp = (ListPreference) pref; if (lp.getTitle().equals(getString(R.string.titleAutoStopAfterTime))) { setSummary(pref, getString(R.string.summaryAutoStopAfterTime), lp.getValue()); } else if (lp.getTitle().equals(getString(R.string.titleRecordingRate))) { setSummary(pref, getString(R.string.summaryRecordingRate), lp.getValue()); } } }
public void updatePrefSummary(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummary(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getKey().equalsIgnoreCase("editKey")) { p.setSummary("*****"); } else { p.setSummary(editTextPref.getText()); } } }
/** * Set summary for preference * * @param pref preference * @param init true if no recursive */ private void setSummary(Preference pref, boolean init) { if (pref instanceof EditTextPreference) { EditTextPreference editPref = (EditTextPreference) pref; pref.setSummary(editPref.getText()); if (editPref.getKey().equals("logfile") && !init) { editPref.setText(PrefStore.getLogFile(this)); pref.setSummary(editPref.getText()); } } if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummary(listPref.getEntry()); } if (pref instanceof CheckBoxPreference) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; if (checkPref.getKey().equals("logger") && checkPref.isChecked() && init) { requestWritePermissions(); } } }
public SipProfile buildAccount(SipProfile account) { account.display_name = accountDisplayName.getText(); // TODO add an user display name account.acc_id = "<sip:" + accountPhoneNumber.getText() + "@" + accountServerDomain.getText() + ">"; String server_ip = accountServerIp.getText(); if (TextUtils.isEmpty(server_ip)) { server_ip = accountServerDomain.getText(); } String regUri = "sip:" + server_ip; account.reg_uri = regUri; account.proxies = new String[] {regUri}; account.realm = "*"; account.username = getText(accountUsername); account.data = getText(accountPassword); account.scheme = SipProfile.CRED_SCHEME_DIGEST; account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD; return account; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference); final EditTextPreference defaultValuePreference = (EditTextPreference) getPreferenceScreen().findPreference("defaultValue"); defaultValuePreference.setSummary(defaultValuePreference.getText()); defaultValuePreference.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { defaultValuePreference.setSummary((String) newValue); return true; } }); }
@Override public SipProfile buildAccount(SipProfile account) { account = super.buildAccount(account); account.proxies = null; account.reg_timeout = 3600; account.contact_rewrite_method = 1; account.try_clean_registers = 0; String finalUsername = accountUsername.getText().trim(); if (accountSuffix != null) { String suffix = accountSuffix.getText(); if (!TextUtils.isEmpty(suffix)) { finalUsername += "x" + suffix.trim(); } } account.acc_id = "<sip:" + SipUri.encodeUser(finalUsername) + "@" + getDomain() + ">"; return account; }
private void updateEditTextPreference(String key) { EditTextPreference pref = (EditTextPreference) getPreferenceScreen().findPreference(key); String entry; try { entry = pref.getText(); } catch (NullPointerException e) { Log.e(AnkiDroidApp.TAG, "Error getting set preference value of " + key + ": " + e); entry = "?"; } if (mListsToUpdate.containsKey(key)) { pref.setSummary(replaceString(mListsToUpdate.get(key), entry)); } else { String oldsum = (String) pref.getSummary(); if (oldsum.contains("XXX")) { mListsToUpdate.put(key, oldsum); pref.setSummary(replaceString(oldsum, entry)); } else { pref.setSummary(entry); } } }
private void updatePrefSummary(Preference p) { if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummary(editTextPref.getText()); } /* if (p instanceof SwitchPreference) { SwitchPreference switchPref = (SwitchPreference) p; p.setSummary(switchPref.isChecked() ? getString(R.string.enabled) : getString(R.string.disabled)); }*/ if (p instanceof CheckBoxPreference) { CheckBoxPreference checkBoxPref = (CheckBoxPreference) p; p.setSummary( checkBoxPref.isChecked() ? getString(R.string.enabled) : getString(R.string.disabled)); } if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummary(listPref.getEntry()); } }
private long saveAlarm() { Alarm alarm = new Alarm(); alarm.id = mId; alarm.enabled = mEnabledPref.isChecked(); alarm.hour = mHour; alarm.minutes = mMinutes; alarm.daysOfWeek = mRepeatPref.getDaysOfWeek(); alarm.vibrate = mVibratePref.isChecked(); alarm.label = mLabel.getText(); alarm.alert = mAlarmPref.getAlert(); long time; if (alarm.id == -1) { time = Alarms.addAlarm(this, alarm); // addAlarm populates the alarm with the new id. Update mId so that // changes to other preferences update the new alarm. mId = alarm.id; } else { time = Alarms.setAlarm(this, alarm); } return time; }
@Override public void onCreate(Bundle savedInstanceState) { settings = getSharedPreferences("preferences", 0); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); EditTextPreference Audiorepetitiontime = (EditTextPreference) findPreference("Audio_repetition_time"); Audiorepetitiontime.setSummary(Audiorepetitiontime.getText()); Audiorepetitiontime.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object o) { preference.setSummary(o.toString()); // GetApplicationSettings(); return true; }; }); }
public SipProfile buildAccount(SipProfile account) { account.display_name = accountDisplayName.getText(); account.transport = getIntValue(accountTransport, SipProfile.TRANSPORT_UDP); account.default_uri_scheme = accountDefaultUriScheme.getValue(); account.acc_id = getText(accountAccId); account.reg_uri = getText(accountRegUri); account.use_srtp = getIntValue(accountUseSrtp, -1); account.use_zrtp = getIntValue(accountUseZrtp, -1); if (!isEmpty(accountUserName)) { account.realm = getText(accountRealm); account.username = getText(accountUserName); account.data = getText(accountData); account.scheme = accountScheme.getValue(); String dataType = accountDataType.getValue(); if (dataType.equalsIgnoreCase("0")) { account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD; } else if (dataType.equalsIgnoreCase("1")) { account.datatype = SipProfile.CRED_DATA_DIGEST; } // DISABLED SINCE NOT SUPPORTED YET /*else if(dataType.equalsIgnoreCase("16")){ ci.setData_type(SipProfile.CRED_DATA_EXT_AKA); } */ else { account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD; } } else { account.realm = ""; account.username = ""; account.data = ""; account.scheme = SipProfile.CRED_SCHEME_DIGEST; account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD; } account.initial_auth = accountInitAuth.isChecked(); account.auth_algo = accountAuthAlgo.getText(); account.publish_enabled = accountPublishEnabled.isChecked() ? 1 : 0; int regTo = getIntValue(accountRegTimeout, -1); if (regTo > 0) { account.reg_timeout = regTo; } int regDelay = getIntValue(accountRegDelayRefresh, -1); if (regDelay > 0) { account.reg_delay_before_refresh = regDelay; } account.contact_rewrite_method = getIntValue(accountContactRewriteMethod, 2); account.allow_contact_rewrite = accountAllowContactRewrite.isChecked(); account.allow_via_rewrite = accountAllowViaRewrite.isChecked(); String forceContact = getText(accountForceContact); if (!TextUtils.isEmpty(forceContact)) { account.force_contact = forceContact; } else { account.force_contact = ""; } if (!isEmpty(accountProxy)) { account.proxies = new String[] {accountProxy.getText()}; } else { account.proxies = null; } String vmNbr = getText(accountVm); if (!TextUtils.isEmpty(vmNbr)) { account.vm_nbr = vmNbr; } else { account.vm_nbr = ""; } account.mwi_enabled = mwiEnabled.isChecked(); account.try_clean_registers = (tryCleanRegisters.isChecked()) ? 1 : 0; account.use_rfc5626 = useRfc5626.isChecked(); account.rfc5626_instance_id = rfc5626_instanceId.getText(); account.rfc5626_reg_id = rfc5626_regId.getText(); account.vid_in_auto_show = getIntValue(vidInAutoShow, -1); account.vid_out_auto_transmit = getIntValue(vidOutAutoTransmit, -1); account.rtp_port = getIntValue(rtpPort, -1); account.rtp_bound_addr = rtpBoundAddr.getText(); account.rtp_public_addr = rtpPublicAddr.getText(); account.rtp_enable_qos = getIntValue(rtpEnableQos, -1); account.rtp_qos_dscp = getIntValue(rtpQosDscp, -1); account.sip_stun_use = getIntValue(sipStunUse, -1); account.media_stun_use = getIntValue(mediaStunUse, -1); account.ice_cfg_use = iceCfgUse.isChecked() ? 1 : -1; account.ice_cfg_enable = iceCfgEnable.isChecked() ? 1 : 0; account.turn_cfg_use = turnCfgUse.isChecked() ? 1 : -1; account.turn_cfg_enable = turnCfgEnable.isChecked() ? 1 : 0; account.turn_cfg_server = turnCfgServer.getText(); account.turn_cfg_user = turnCfgUser.getText(); account.turn_cfg_password = turnCfgPassword.getText(); account.ipv6_media_use = ipv6MediaEnable.isChecked() ? 1 : 0; return account; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); setTitle(getString(R.string.app_name) + " > " + getString(R.string.general_preferences)); // not super safe, but we're just putting in this mode to help administrate // would require code to access it boolean adminMode = getIntent().getBooleanExtra("adminMode", false); SharedPreferences adminPreferences = getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0); boolean serverAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_SERVER, true); PreferenceCategory serverCategory = (PreferenceCategory) findPreference(getString(R.string.server_preferences)); mServerUrlPreference = (EditTextPreference) findPreference(KEY_SERVER_URL); mServerUrlPreference.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String url = newValue.toString(); // remove all trailing "/"s while (url.endsWith("/")) { url = url.substring(0, url.length() - 1); } if (UrlUtils.isValidUrl(url)) { preference.setSummary(newValue.toString()); return true; } else { Toast.makeText(getApplicationContext(), R.string.url_error, Toast.LENGTH_SHORT) .show(); return false; } } }); mServerUrlPreference.setSummary(mServerUrlPreference.getText()); mServerUrlPreference.getEditText().setFilters(new InputFilter[] {getReturnFilter()}); if (!(serverAvailable || adminMode)) { Preference protocol = findPreference(KEY_PROTOCOL); serverCategory.removePreference(protocol); serverCategory.removePreference(mServerUrlPreference); } else { // this just removes the value from protocol, but protocol doesn't // exist if we take away access disableFeaturesInDevelopment(); } mUsernamePreference = (EditTextPreference) findPreference(KEY_USERNAME); mUsernamePreference.setOnPreferenceChangeListener(this); mUsernamePreference.setSummary(mUsernamePreference.getText()); mUsernamePreference.getEditText().setFilters(new InputFilter[] {getReturnFilter()}); boolean usernameAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_USERNAME, true); if (!(usernameAvailable || adminMode)) { serverCategory.removePreference(mUsernamePreference); } mPasswordPreference = (EditTextPreference) findPreference(KEY_PASSWORD); mPasswordPreference.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String pw = newValue.toString(); if (pw.length() > 0) { mPasswordPreference.setSummary("********"); } else { mPasswordPreference.setSummary(""); } return true; } }); if (mPasswordPreference.getText() != null && mPasswordPreference.getText().length() > 0) { mPasswordPreference.setSummary("********"); } mUsernamePreference.getEditText().setFilters(new InputFilter[] {getReturnFilter()}); boolean passwordAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_PASSWORD, true); if (!(passwordAvailable || adminMode)) { serverCategory.removePreference(mPasswordPreference); } // mSelectedGoogleAccountPreference = (PreferenceScreen) // findPreference(KEY_SELECTED_GOOGLE_ACCOUNT); // mSelectedGoogleAccountPreference // .setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // Intent i = new Intent(getApplicationContext(), AccountList.class); // startActivity(i); // return true; // } // }); // mSelectedGoogleAccountPreference.setSummary(mSelectedGoogleAccountPreference // .getSharedPreferences().getString(KEY_ACCOUNT, "")); // boolean googleAccounAvailable = adminPreferences.getBoolean( // AdminPreferencesActivity.KEY_CHANGE_GOOGLE_ACCOUNT, true); // if (!(googleAccounAvailable || adminMode)) { // serverCategory.removePreference(mSelectedGoogleAccountPreference); // } // mFormListUrlPreference = (EditTextPreference) findPreference(KEY_FORMLIST_URL); // mFormListUrlPreference.setOnPreferenceChangeListener(this); // mFormListUrlPreference.setSummary(mFormListUrlPreference.getText()); // mServerUrlPreference.getEditText().setFilters( // new InputFilter[] { // getReturnFilter(), getWhitespaceFilter() // }); // if (!(serverAvailable || adminMode)) { // serverCategory.removePreference(mFormListUrlPreference); // } // mSubmissionUrlPreference = (EditTextPreference) findPreference(KEY_SUBMISSION_URL); // mSubmissionUrlPreference.setOnPreferenceChangeListener(this); // mSubmissionUrlPreference.setSummary(mSubmissionUrlPreference.getText()); // mServerUrlPreference.getEditText().setFilters( // new InputFilter[] { // getReturnFilter(), getWhitespaceFilter() // }); // if (!(serverAvailable || adminMode)) { // serverCategory.removePreference(mSubmissionUrlPreference); // } // // if (!(serverAvailable || usernameAvailable || passwordAvailable || adminMode)) { // getPreferenceScreen().removePreference(serverCategory); // } PreferenceCategory clientCategory = (PreferenceCategory) findPreference(getString(R.string.client)); boolean fontAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_FONT_SIZE, true); mFontSizePreference = (ListPreference) findPreference(KEY_FONT_SIZE); mFontSizePreference.setSummary(mFontSizePreference.getEntry()); mFontSizePreference.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int index = ((ListPreference) preference).findIndexOfValue(newValue.toString()); String entry = (String) ((ListPreference) preference).getEntries()[index]; ((ListPreference) preference).setSummary(entry); return true; } }); if (!(fontAvailable || adminMode)) { clientCategory.removePreference(mFontSizePreference); } boolean defaultAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_DEFAULT_TO_FINALIZED, true); Preference defaultFinalized = findPreference(KEY_COMPLETED_DEFAULT); if (!(defaultAvailable || adminMode)) { clientCategory.removePreference(defaultFinalized); } boolean splashAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_SELECT_SPLASH_SCREEN, true); mSplashPathPreference = (PreferenceScreen) findPreference(KEY_SPLASH_PATH); mSplashPathPreference.setOnPreferenceClickListener( new OnPreferenceClickListener() { private void launchImageChooser() { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); startActivityForResult(i, PreferencesActivity.IMAGE_CHOOSER); } @Override public boolean onPreferenceClick(Preference preference) { // if you have a value, you can clear it or select new. CharSequence cs = mSplashPathPreference.getSummary(); if (cs != null && cs.toString().contains("/")) { final CharSequence[] items = { getString(R.string.select_another_image), getString(R.string.use_odk_default) }; AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesActivity.this); builder.setTitle(getString(R.string.change_splash_path)); builder.setNeutralButton( getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); builder.setItems( items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (items[item].equals(getString(R.string.select_another_image))) { launchImageChooser(); } else { setSplashPath(getString(R.string.default_splash_path)); } } }); AlertDialog alert = builder.create(); alert.show(); } else { launchImageChooser(); } return true; } }); if (!(splashAvailable || adminMode)) { clientCategory.removePreference(mSplashPathPreference); } boolean showSplashAvailable = adminPreferences.getBoolean(AdminPreferencesActivity.KEY_SHOW_SPLASH_SCREEN, true); CheckBoxPreference showSplashPreference = (CheckBoxPreference) findPreference(KEY_SHOW_SPLASH); if (!(showSplashAvailable || adminMode)) { clientCategory.removePreference(showSplashPreference); } if (!(fontAvailable || defaultAvailable || splashAvailable || showSplashAvailable || adminMode)) { getPreferenceScreen().removePreference(clientCategory); } }
private void initUI() { mLanguagePref = (ListPreference) findPreference(SpeechConstant.LANGUAGE); mCategoryPref = (ListPreference) findPreference(SpeechConstant.ISE_CATEGORY); mResultLevelPref = (ListPreference) findPreference(SpeechConstant.RESULT_LEVEL); mVadBosPref = (EditTextPreference) findPreference(SpeechConstant.VAD_BOS); mVadEosPref = (EditTextPreference) findPreference(SpeechConstant.VAD_EOS); mSpeechTimeoutPref = (EditTextPreference) findPreference(SpeechConstant.KEY_SPEECH_TIMEOUT); mToast = Toast.makeText(IseSettings.this, "", Toast.LENGTH_LONG); mLanguagePref.setSummary("当前:" + mLanguagePref.getEntry()); mCategoryPref.setSummary("当前:" + mCategoryPref.getEntry()); mResultLevelPref.setSummary("当前:" + mResultLevelPref.getEntry()); mVadBosPref.setSummary("当前:" + mVadBosPref.getText() + "ms"); mVadEosPref.setSummary("当前:" + mVadEosPref.getText() + "ms"); String speech_timeout = mSpeechTimeoutPref.getText(); String summary = "当前:" + speech_timeout; if (!"-1".equals(speech_timeout)) { summary += "ms"; } mSpeechTimeoutPref.setSummary(summary); mLanguagePref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if ("zh_cn".equals(newValue.toString())) { if ("plain".equals(mResultLevelPref.getValue())) { showTip("汉语评测结果格式不支持plain设置"); return false; } } else { if ("read_syllable".equals(mCategoryPref.getValue())) { showTip("英语评测不支持单字"); return false; } } int newValueIndex = mLanguagePref.findIndexOfValue(newValue.toString()); String newEntry = (String) mLanguagePref.getEntries()[newValueIndex]; mLanguagePref.setSummary("当前:" + newEntry); return true; } }); mCategoryPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if ("en_us".equals(mLanguagePref.getValue()) && "read_syllable".equals(newValue.toString())) { showTip("英语评测不支持单字,请选其他项"); return false; } int newValueIndex = mCategoryPref.findIndexOfValue(newValue.toString()); String newEntry = (String) mCategoryPref.getEntries()[newValueIndex]; mCategoryPref.setSummary("当前:" + newEntry); return true; } }); mResultLevelPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if ("zh_cn".equals(mLanguagePref.getValue()) && "plain".equals(newValue.toString())) { showTip("汉语评测不支持plain,请选其他项"); return false; } mResultLevelPref.setSummary("当前:" + newValue.toString()); return true; } }); mVadBosPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); mVadBosPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int bos; try { bos = Integer.parseInt(newValue.toString()); } catch (Exception e) { showTip("无效输入!"); return false; } if (bos < 0 || bos > 30000) { showTip("取值范围为0~30000"); return false; } mVadBosPref.setSummary("当前:" + bos + "ms"); return true; } }); mVadEosPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); mVadEosPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int eos; try { eos = Integer.parseInt(newValue.toString()); } catch (Exception e) { showTip("无效输入!"); return false; } if (eos < 0 || eos > 30000) { showTip("取值范围为0~30000"); return false; } mVadEosPref.setSummary("当前:" + eos + "ms"); return true; } }); mSpeechTimeoutPref .getEditText() .setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER); mSpeechTimeoutPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int speech_timeout; try { speech_timeout = Integer.parseInt(newValue.toString()); } catch (Exception e) { showTip("无效输入!"); return false; } if (speech_timeout < -1) { showTip("必须大于等于-1"); return false; } if (speech_timeout == -1) { mSpeechTimeoutPref.setSummary("当前:-1"); } else { mSpeechTimeoutPref.setSummary("当前:" + speech_timeout + "ms"); } return true; } }); }
private void updatePrefences(Preference preference) { if (preference instanceof EditTextPreference) { if (preference.getKey().equals(MyApplication.PROFILE_NAME_KEY)) { EditTextPreference etp = (EditTextPreference) preference; if (etp.getText() != null && !etp.getText().equals("")) { profile.setName(etp.getText()); isNameSet = true; } isReady = isNameSet && isRepeatingSet && isActivatoinSet; etp.setSummary(etp.getText()); } } else if (preference instanceof ListPreference) { ListPreference lp = (ListPreference) preference; if (preference.getKey().equals(MyApplication.AUTO_ACTIVATION_KEY)) { lp.setSummary(lp.getEntry()); int idx = Integer.parseInt(lp.getValue()); switch (idx) { case 0: break; case 1: showFromDialog(); profile.setAcivationMode(MyApplication.BY_TIME); // lp.setSummary(profile.getSubTitle()); break; case 2: profile.setAcivationMode(MyApplication.BY_LOCATOIN); profile.setSubTitle("By Location "); isActivatoinSet = true; isReady = isNameSet && isRepeatingSet && isActivatoinSet; break; } lp.setSummary(profile.getSubTitle()); } else if (preference.getKey().equals(MyApplication.RING_MODE_KEY)) { lp.setSummary(lp.getEntry()); profile.setRingerMode(Integer.parseInt(lp.getValue())); } else if (preference.getKey().equals(MyApplication.CHANGE_WIFI_KEY)) { lp.setSummary(lp.getEntry()); profile.setWifiMode(Integer.parseInt(lp.getValue())); } else if (preference.getKey().equals(MyApplication.CHANGE_BLUETOOEH_KEY)) { lp.setSummary(lp.getEntry()); profile.setBlueToothMode(Integer.parseInt(lp.getValue())); } } else if (preference instanceof MultiSelectListPreference) { if (preference.getKey().equals(MyApplication.REPEATIN_DAYS_KEY)) { MultiSelectListPreference msp = (MultiSelectListPreference) preference; Set<String> selectedDays = msp.getValues(); ArrayList<Integer> selectedIndx = new ArrayList<>(); for (String day : selectedDays) { selectedIndx.add(Integer.parseInt(day)); // Toast.makeText(MyApplication.APP_CNTX,day,Toast.LENGTH_SHORT).show(); } Collections.sort(selectedIndx); String summary = ""; for (int idx : selectedIndx) { summary += MyApplication.DAYS_OF_WEEK[idx % 7].substring(0, 3) + ","; } if (summary.length() == 0) summary = "NONE"; msp.setSummary(summary); profile.setRepeatingDays(selectedIndx); isRepeatingSet = true; isReady = isNameSet && isRepeatingSet && isActivatoinSet; } } else if (preference instanceof CheckBoxPreference) { CheckBoxPreference cbp = (CheckBoxPreference) preference; if (cbp.getKey().equals(MyApplication.CHANGE_RINGTONE_KEY)) { findPreference(MyApplication.CHOOSE_RINGTONE_KEY).setEnabled(cbp.isChecked()); profile.setChangeRingtone(cbp.isChecked()); } else if (cbp.getKey().equals(MyApplication.CHANGE_NOTIFICATION_KEY)) { findPreference(MyApplication.CHOOSE_NOTIFICATION_KEY).setEnabled(cbp.isChecked()); profile.setChangeNotiTone(cbp.isChecked()); } } else if (preference instanceof RingtonePreference) { RingtonePreference rtp = (RingtonePreference) preference; if (rtp.getKey().equals(MyApplication.CHOOSE_RINGTONE_KEY)) { String ring = getRingToneURI(); Uri uri = Uri.parse(ring); Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri); if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity())); profile.setRingeToneURI(ring); } else if (rtp.getKey().equals(MyApplication.CHOOSE_NOTIFICATION_KEY)) { String ring = getNotiToneURI(); Uri uri = Uri.parse(ring); Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri); if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity())); profile.setNotiToneURI(ring); } } }
@Test public void setTextShouldStoreNull() { preference.setText(null); assertNull(preference.getText()); }
@Test public void setTextShouldStoreText() { preference.setText("some other text"); assertThat(preference.getText()).isEqualTo("some other text"); }
// initialise the summary displayed private void initSummary(Preference p) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummary(editTextPref.getText()); }
protected String getDomain() { return accountServer.getText(); }