android.preference.EditTextPreference源码实例Demo

类android.preference.EditTextPreference源码实例Demo

下面列出了android.preference.EditTextPreference 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidAPS   文件: PreferencesActivity.java
private static void updatePrefSummary(Preference pref) {
    if (pref instanceof ListPreference) {
        ListPreference listPref = (ListPreference) pref;
        pref.setSummary(listPref.getEntry());
    }
    if (pref instanceof EditTextPreference) {
        EditTextPreference editTextPref = (EditTextPreference) pref;
        if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
            pref.setSummary("******");
        } else if (editTextPref.getText() != null) {
            ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
            pref.setSummary(editTextPref.getText());
        } else {
            for (PluginBase plugin : MainApp.getPluginsList()) {
                plugin.updatePreferenceSummary(pref);
            }
        }
    }
    if (pref != null)
        adjustUnitDependentPrefs(pref);
}
 
源代码2 项目: mytracks   文件: MapSettingsActivity.java
/**
 * Configures the IME action done.
 * 
 * @param editTextPreference the edit text preference
 */
private void configImeActionDone(final EditTextPreference editTextPreference) {
  editTextPreference.getEditText()
      .setOnEditorActionListener(new TextView.OnEditorActionListener() {
          @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
          if (actionId == EditorInfo.IME_ACTION_DONE) {
            Dialog dialog = editTextPreference.getDialog();
            editTextPreference.onClick(dialog, Dialog.BUTTON_POSITIVE);
            dialog.dismiss();
            return true;
          }
          return false;
        }
      });
}
 
源代码3 项目: Dashchan   文件: BasePreferenceFragment.java
public void onPreferenceAfterChange(Preference preference) {
	if (summaryListenersEditText != null) {
		if (preference instanceof EditTextPreference && summaryListenersEditText.contains(preference)) {
			updateEditTextSummary((EditTextPreference) preference);
		}
	}
	if (summaryListenersMultipleEditText != null) {
		if (preference instanceof MultipleEditTextPreference && summaryListenersMultipleEditText
				.containsKey(preference)) {
			updateMultipleEditTextSummary((MultipleEditTextPreference) preference,
					summaryListenersMultipleEditText.get(preference));
		}
	}
	if (preference instanceof ListPreference) {
		updateListSummary((ListPreference) preference);
	}
	if (dependencies != null) {
		for (Dependency dependency : dependencies) {
			if (preference.getKey().equals(dependency.dependencyKey)) {
				updateDependency(dependency, preference);
			}
		}
	}
}
 
源代码4 项目: trigger   文件: SetupActivity.java
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);
    }
}
 
源代码5 项目: batteryhub   文件: SettingsActivity.java
private void bindPreferenceSummaryToValue(Preference preference) {
    String stringValue = PreferenceManager
            .getDefaultSharedPreferences(preference.getContext())
            .getString(preference.getKey(), "");

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        stringValue = stringValue.replaceFirst("^0+(?!$)", "");

        editTextPreference.setText(stringValue);
        preference.setSummary(stringValue.replaceFirst("^0+(?!$)", ""));
    }
}
 
private void setSummaries() {
    final EditTextPreference urlPreference = (EditTextPreference) findPreference(PREF_SERVER_URL);
    urlPreference.setSummary(preferences.getString(PREF_SERVER_URL, this.getResources().getString(R.string.server_url_summary)));

    final String serverPassHash = preferences.getString(PREF_SERVER_PASS_HASH, "");
    final EditTextPreference serverPassTextPreference = (EditTextPreference) findPreference(PREF_SERVER_PASS);
    if (serverPassHash.isEmpty()) {
        serverPassTextPreference.setSummary(getResources().getString(R.string.server_password_summary));
    } else {
        serverPassTextPreference.setSummary(getResources().getString(R.string.server_password_summary_set));
    }

    final EditTextPreference httpLoginPreference = (EditTextPreference) findPreference(PREF_SERVER_HTTP_AUTH_LOGIN);
    httpLoginPreference.setSummary(preferences.getString(PREF_SERVER_HTTP_AUTH_LOGIN, ""));

    final String httpPass = preferences.getString(PREF_SERVER_HTTP_AUTH_PASS,"");
    if (!httpPass.isEmpty()) {
        final EditTextPreference httpPassPreference = (EditTextPreference) findPreference(PREF_SERVER_HTTP_AUTH_PASS);
        httpPassPreference.setSummary(getResources().getString(R.string.server_password_summary_set));
    }
}
 
源代码7 项目: glimmr   文件: SettingsFragment.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);
    PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences,
            false);

    mSharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(getActivity());
    mIntervalsListPreference = (ListPreference) getPreferenceScreen()
        .findPreference(Constants.KEY_INTERVALS_LIST_PREFERENCE);
    mInitialTabListPreference = (ListPreference) getPreferenceScreen()
        .findPreference(Constants.KEY_INITIAL_TAB_LIST_PREFERENCE);
    mSlideshowIntervalPreference = (EditTextPreference)
        getPreferenceScreen().findPreference(
                Constants.KEY_SLIDESHOW_INTERVAL);
    mHighQualityThumbsCbPreference = (CheckBoxPreference) getPreferenceScreen()
            .findPreference(Constants.KEY_HIGH_QUALITY_THUMBNAILS);

    if (Constants.PRO_VERSION) {
        mHighQualityThumbsCbPreference.setEnabled(true);
    }
}
 
源代码8 项目: text_converter   文件: PreferencesUtil.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码9 项目: habpanelviewer   文件: PreferenceFragment.java
@Override
public void validationAvailable(List<String> items) {
    mUiHandler.post(() -> {
        List<Preference> list = getPreferenceList(getPreferenceScreen(), new ArrayList<>());
        for (Preference p : list) {
            if (p.getKey().endsWith(Constants.PREF_SUFFIX_ITEM) && p instanceof EditTextPreference) {
                final EditText editText = ((EditTextPreference) p).getEditText();

                if (editText instanceof AutoCompleteTextView) {
                    AutoCompleteTextView t = (AutoCompleteTextView) editText;
                    t.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, items));
                    t.performValidation();
                }
            }
        }
    });
}
 
源代码10 项目: sana.mobile   文件: BasicSettings.java
private void initPreferences() {
    Log.i(TAG, "initPreferences()");
    // Phone name
    // This doesn't always work
    String line1Number = ((TelephonyManager) getSystemService(
            Context.TELEPHONY_SERVICE))
            .getLine1Number();
    String deviceId = ((TelephonyManager) getSystemService(
            Context.TELEPHONY_SERVICE)).getDeviceId();
    Log.d(TAG, "...line1 number: " + line1Number);
    Log.d(TAG, "...device id: " + deviceId);
    String phoneNum = (!TextUtils.isEmpty(line1Number)) ? line1Number :
            (!TextUtils.isEmpty(deviceId)) ? deviceId : 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);
    }
}
 
源代码11 项目: Overchan-Android   文件: AbstractChanModule.java
/**
 * Добавить в группу параметров (на экран/в категорию) параметр задания пароля для удаления постов/файлов
 * @param group группа, на которую добавляется параметр
 */
protected void addPasswordPreference(PreferenceGroup group) {
    final Context context = group.getContext();
    EditTextPreference passwordPref = new EditTextPreference(context) {
        @Override
        protected void showDialog(Bundle state) {
            if (createPassword()) {
                setText(getDefaultPassword());
            }
            super.showDialog(state);
        }
    };
    passwordPref.setTitle(R.string.pref_password_title);
    passwordPref.setDialogTitle(R.string.pref_password_title);
    passwordPref.setSummary(R.string.pref_password_summary);
    passwordPref.setKey(getSharedKey(PREF_KEY_PASSWORD));
    passwordPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    passwordPref.getEditText().setSingleLine();
    passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) });
    group.addPreference(passwordPref);
}
 
源代码12 项目: javaide   文件: PreferencesUtil.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码13 项目: javaide   文件: PreferencesUtil.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码14 项目: Overchan-Android   文件: DobroModule.java
private void addDomainPreferences(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) {
                domain = (String) newValue;
                if (domain.length() == 0) domain = DEFAULT_DOMAIN;
                loadHanabiraCookie();
                return true;
            }
            return false;
        }
    };
    EditTextPreference domainPref = new EditTextPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    domainPref.setOnPreferenceChangeListener(updateDomainListener);
    group.addPreference(domainPref);
}
 
源代码15 项目: codeexamples-android   文件: DeviceAdminSample.java
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Retrieve the useful instance variables
    mActivity = (DeviceAdminSample) getActivity();
    mDPM = mActivity.mDPM;
    mDeviceAdminSample = mActivity.mDeviceAdminSample;
    mAdminActive = mActivity.isActiveAdmin();

    // Configure the shared UI elements (if they exist)
    mResetPassword = (EditTextPreference) findPreference(KEY_RESET_PASSWORD);
    mSetPassword = (PreferenceScreen) findPreference(KEY_SET_PASSWORD);

    if (mResetPassword != null) {
        mResetPassword.setOnPreferenceChangeListener(this);
    }
    if (mSetPassword != null) {
        mSetPassword.setOnPreferenceClickListener(this);
    }
}
 
源代码16 项目: NightWidget   文件: SettingsFragment.java
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	/* set preferences */
	addPreferencesFromResource(R.xml.preferences);
	addMedtronicOptionsListener();
	PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
	final ListPreference mon_type = (ListPreference) findPreference("monitor_type_widget");
	final EditTextPreference med_id = (EditTextPreference) findPreference("medtronic_cgm_id_widget");
	final ListPreference metric_type = (ListPreference) findPreference("metric_preference_widget");
	final CustomSwitchPreference mmolDecimals = (CustomSwitchPreference)findPreference("mmolDecimals_widget");
	int index = mon_type.findIndexOfValue(mon_type.getValue());

	if (index == 1) {
		med_id.setEnabled(true);
	} else {
		med_id.setEnabled(false);
	}
	int index_met = metric_type.findIndexOfValue(PreferenceManager.getDefaultSharedPreferences(context).getString("metric_preference_widget", "1"));

	if (index_met == 0){

		mmolDecimals.setEnabled(false);
	}else{ 
		mmolDecimals.setEnabled(true);
	}
	// iterate through all preferences and update to saved value
	for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
		initSummary(getPreferenceScreen().getPreference(i));
	}

}
 
源代码17 项目: DeviceConnect-Android   文件: SettingsFragment.java
/**
 * Show IP Address.
 */
private void showIPAddress() {
    String ipAddress = DConnectUtil.getIPAddress(getActivity());

    // Set Host IP Address.
    EditTextPreference editHostPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_host));
    editHostPreferences.setSummary(ipAddress);
    
    // Set Host IP Address.
    EditTextPreference webHostPref = (EditTextPreference)
            getPreferenceScreen().findPreference(getString(R.string.key_settings_web_server_host));
    webHostPref.setSummary(ipAddress);
}
 
源代码18 项目: cast-videos-android   文件: CastPreference.java
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.application_preference);
    getPreferenceScreen().getSharedPreferences().
            registerOnSharedPreferenceChangeListener(this);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    EditTextPreference versionPref = (EditTextPreference) findPreference("app_version");
    versionPref.setTitle(getString(R.string.version, Utils.getAppVersionName(this)));
}
 
源代码19 项目: SkyTube   文件: OthersPreferenceFragment.java
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
	if(key != null) {
		if (key.equals(getString(R.string.pref_key_default_tab_name))) {
			// If the user changed the Default Tab Preference, update the summary to show the new default tab
			ListPreference defaultTabPref = (ListPreference) findPreference(key);
			defaultTabPref.setSummary(String.format(getString(R.string.pref_summary_default_tab), defaultTabPref.getEntry()));
		} else if (key.equals(getString(R.string.pref_key_hide_tabs))) {
			displayRestartDialog(R.string.pref_hide_tabs_restart, true);
		} else if (key.equals(getString(R.string.pref_youtube_api_key))) {
			// Validate the entered API Key when saved (and not empty), with a simple call to get the most popular video
			EditTextPreference    youtubeAPIKeyPref = (EditTextPreference) findPreference(getString(R.string.pref_youtube_api_key));
			String                youtubeAPIKey     = youtubeAPIKeyPref.getText();

			if (youtubeAPIKey != null) {
				youtubeAPIKey = youtubeAPIKey.trim();

				if (!youtubeAPIKey.isEmpty()) {
					// validate the user's API key
					new ValidateYouTubeAPIKeyTask(youtubeAPIKey).executeInParallel();
				}
				else {
					// inform the user that we are going to use the default YouTube API key and
					// that we need to restart the app
					displayRestartDialog(R.string.pref_youtube_api_key_default,false);
				}
			}
		} else if (key.equals(getString(R.string.pref_key_subscriptions_alphabetical_order))) {
			SubsAdapter subsAdapter = SubsAdapter.get(getActivity());
			subsAdapter.refreshSubsList();
		}/*else if (key.equals(getString(R.string.pref_feed_notification_key))) {
			ListPreference feedNotificationPref = (ListPreference) findPreference(key);
			feedNotificationPref.setSummary(String.format(getString(R.string.pref_summary_feed_notification), feedNotificationPref.getEntry()));

			int interval = Integer.parseInt(feedNotificationPref.getValue());

			SkyTubeApp.setFeedUpdateInterval(interval);
		}*/
	}
}
 
源代码20 项目: NoiseCapture   文件: SettingsFragment.java
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if(preference instanceof EditTextPreference && newValue instanceof String) {
        EditText prefText = ((EditTextPreference) preference).getEditText();
        int editorType = prefText.getInputType();
        if(EditorInfo.TYPE_CLASS_NUMBER == (EditorInfo.TYPE_CLASS_NUMBER & editorType)) {
            // Try to convert to double
            double res;
            try {
                res = Double.valueOf((String)newValue);
            } catch (NumberFormatException ex) {
                return false;
            }
            if(EditorInfo.TYPE_NUMBER_FLAG_SIGNED != (EditorInfo.TYPE_NUMBER_FLAG_SIGNED & editorType)) {
                // Must be superior than 0
                if(res < 0) {
                    return false;
                }
            }
            if(EditorInfo.TYPE_NUMBER_FLAG_SIGNED != (EditorInfo.TYPE_NUMBER_FLAG_SIGNED & editorType)) {
                // Must be an integer
                if(Double.compare(res % 1,0) != 0) {
                    return false;
                }
            }
        }
        return true;
    }
    return true;
}
 
源代码21 项目: document-viewer   文件: PreferencesDecorator.java
public void decoratePreference(final Preference pref) {
    if (pref instanceof ListPreference) {
        decorateListPreference((ListPreference) pref);
    } else if (pref instanceof EditTextPreference) {
        decorateEditPreference((EditTextPreference) pref);
    } else if (pref instanceof SeekBarPreference) {
        decorateSeekPreference((SeekBarPreference) pref);
    } else if (pref instanceof PreferenceGroup) {
        final PreferenceGroup group = (PreferenceGroup) pref;
        for (int i = 0, n = group.getPreferenceCount(); i < n; i++) {
            decoratePreference(group.getPreference(i));
        }
    }
}
 
源代码22 项目: styT   文件: SettingActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO: Implement this method
    super.onCreate(savedInstanceState);
    //this.getListView().setBackgroundResource(R.color.deepskyblue);
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    addPreferencesFromResource(R.xml.settings);

    cb_use_first_size = (CheckBoxPreference) findPreference("cb_use_first_size");

    edit_pic_width = (EditTextPreference) findPreference("edit_pic_width");
    edit_pic_height = (EditTextPreference) findPreference("edit_pic_height");

    isSelected = cb_use_first_size.isChecked();
    setTwoEditEnabled();

    cb_use_first_size.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference p1, Object p2) {
            if (p1.getKey().equals("cb_use_first_size")) {
                isSelected = !cb_use_first_size.isChecked();
                setTwoEditEnabled();
            }
            return true;
        }
    });
}
 
源代码23 项目: physical-web   文件: SettingsFragment.java
private void updatePwsPreference() {
  ListPreference listPreference = (ListPreference) findPreference(
      getString(R.string.pws_endpoint_setting_key));
  String entry = (String) listPreference.getEntry();
  if (entry == null) {
    return;
  }

  if (entry.equals(getString(R.string.custom_pws))) {
    // User selected custom PWS therefore need to update it accordingly
    EditTextPreference customPwsUrlPreference =
        (EditTextPreference) mCustomEndpointCategory.findPreference(
            getString(R.string.custom_pws_url_key));
    ListPreference customPwsVersionPreference =
        (ListPreference) mCustomEndpointCategory.findPreference(
            getString(R.string.custom_pws_version_key));
    EditTextPreference customPwsApiKeyPreference =
        (EditTextPreference) mCustomEndpointCategory.findPreference(
            getString(R.string.custom_pws_api_key_key));
    String customPwsUrl = customPwsUrlPreference.getText();
    int customPwsVersion = Integer.parseInt(customPwsVersionPreference.getValue());
    String customPwsApiKey = customPwsApiKeyPreference.getText();
    customPwsUrl = customPwsUrl == null ? "" : customPwsUrl;
    customPwsApiKey = customPwsApiKey == null ? "" : customPwsApiKey;
    listPreference.setValue(Utils.formatEndpointForSharedPrefernces(customPwsUrl,
        customPwsVersion, customPwsApiKey));
    getPreferenceScreen().addPreference(mCustomEndpointCategory);
  } else {
    getPreferenceScreen().removePreference(mCustomEndpointCategory);
  }
}
 
源代码24 项目: trigger   文件: SetupActivity.java
private String getText(String key) {
    Preference p = findAnyPreference(key, null);
    if (p instanceof EditTextPreference) {
        EditTextPreference etp = (EditTextPreference) p;
        return etp.getText();
    } else if (p instanceof ListPreference) {
        ListPreference lp = (ListPreference) p;
        return lp.getValue();
    } else {
        Log.w("SetupActivity.setText", "Cannot find EditTextPreference/ListPreference in PreferenceGroup with key: " + key);
        return "";
    }
}
 
源代码25 项目: FineGeotag   文件: ActivitySettings.java
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    Preference pref = findPreference(key);

    // Remove empty string settings
    if (pref instanceof EditTextPreference)
        if ("".equals(prefs.getString(key, null))) {
            SharedPreferences.Editor edit = prefs.edit();
            edit.remove(key);
            edit.apply();
        }

    if (PREF_ENABLED.equals(key))
        pref.setSummary(prefs.getBoolean(PREF_ENABLED, true) ? getString(R.string.summary_enabled) : null);

    else if (PREF_TOAST.equals(key))
        pref.setSummary(prefs.getBoolean(PREF_TOAST, true) ? getString(R.string.summary_toast) : null);

    else if (PREF_ALTITUDE.equals(key))
        pref.setSummary(prefs.getBoolean(PREF_ALTITUDE, true) ? getString(R.string.summary_altitude) : null);

    else if (PREF_ACCURACY.equals(key))
        pref.setTitle(getString(R.string.title_accuracy, prefs.getString(key, DEFAULT_ACCURACY)));

    else if (PREF_TIMEOUT.equals(key))
        pref.setTitle(getString(R.string.title_timeout, prefs.getString(key, DEFAULT_TIMEOUT)));

    else if (PREF_KNOWN.equals(key)) {
        ListPreference lpref = (ListPreference) pref;
        int index = lpref.findIndexOfValue(prefs.getString(key, DEFAULT_KNOWN));
        pref.setTitle(getString(R.string.title_known, lpref.getEntries()[index]));
    }
}
 
源代码26 项目: Linphone4Android   文件: SettingsFragment.java
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());
}
 
@Override
public void onAccountCreatorPasswordUpdated(LinphoneAccountCreator accountCreator, LinphoneAccountCreator.Status status) {
	progress.dismiss();
	if (status.equals(LinphoneAccountCreator.Status.Ok)) {
		mPrefs.setAccountPassword(n, accountCreator.getPassword());
		PreferenceCategory account = (PreferenceCategory) getPreferenceScreen().findPreference(getString(R.string.pref_sipaccount_key));
		((EditTextPreference) account.getPreference(2)).setText(mPrefs.getAccountPassword(n));
		LinphoneUtils.displayErrorAlert(getString(R.string.pref_password_changed), LinphoneActivity.instance());
	} else {
		LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance());
	}
}
 
源代码28 项目: LaunchEnr   文件: BoardActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
    addPreferencesFromResource(R.xml.board_preferences);

    mBoardTitlePreference = (EditTextPreference) findPreference(BoardUtils.BOARD_TITLE_KEY);

    setBoardTitlePreference();

    mListenerOptions = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

            switch (key) {
                case BoardUtils.BOARD_TITLE_KEY:
                    updateBoardTitlePreferenceSummary();
                    break;
                case BoardUtils.CUSTOM_APP_KEY:
                    manageCustomAppPreference();
                    break;
            }
        }
    };

    mCustomAppPreference = findPreference(BoardUtils.CUSTOM_APP_PREF_KEY);
    manageCustomAppPreference();
    mCustomAppPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), MultiSelectRecyclerViewActivity.class);
            getActivity().startActivity(intent);
            return false;
        }
    });
}
 
源代码29 项目: stynico   文件: SettingActivity.java
@Override
protected void onCreate(Bundle savedInstanceState)
{
	// TODO: Implement this method
	super.onCreate(savedInstanceState);
	//this.getListView().setBackgroundResource(R.color.deepskyblue);
	addPreferencesFromResource(R.xml.settings);

	cb_use_first_size = (CheckBoxPreference)findPreference("cb_use_first_size");

	edit_pic_width = (EditTextPreference)findPreference("edit_pic_width");
	edit_pic_height = (EditTextPreference)findPreference("edit_pic_height");

	isSelected=cb_use_first_size.isChecked();
	setTwoEditEnabled();

	cb_use_first_size.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
		{
			public boolean onPreferenceChange(Preference p1, Object p2)
			{
				if (p1.getKey().equals("cb_use_first_size"))
				{
					isSelected=!cb_use_first_size.isChecked();
					setTwoEditEnabled();
				}
				return true;
			}
		});
}
 
源代码30 项目: AnkiDroid-Wear   文件: SettingsActivity.java
@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);

}