Preference getContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Preference getContext method.

This code example shows how to use the following methods:getContext, setSummary
                // 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) { 
                // For ringtone preferences, look up the correct display value 
                // using RingtoneManager. 
                if (TextUtils.isEmpty(stringValue)) { 
                    // Empty values correspond to 'silent' (no ringtone). 
                    // preference.setSummary(R.string.pref_ringtone_silent); 
 
                } else { 
                    Ringtone ringtone = RingtoneManager.getRingtone( 
                            preference.getContext(), Uri.parse(stringValue)); 

7
CodeRank
This code example shows how to use the following methods:getContext, getKey, setOnPreferenceChangeListener
	 * @see #sBindPreferenceSummaryToValueListener 
	 */ 
	private static void bindPreferenceSummaryToValue(Preference preference) {
		// Set the listener to watch for value changes. 
		preference
				.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
 
		// Trigger the listener immediately with the preference's 
		// current value. 
		sBindPreferenceSummaryToValueListener.onPreferenceChange(
				preference,
				PreferenceManager.getDefaultSharedPreferences(
						preference.getContext()).getString(preference.getKey(),
						"")); 
	} 
 
	/** 
	 * This fragment shows general preferences only. It is used when the 
	 * activity is showing a two-pane settings UI. 
	 */ 
7
CodeRank
This code example shows how to use the following methods:getContext, getKey, setOnPreferenceChangeListener
     * immediately called with the preference's current value upon calling this method. 
     */ 
    public static void setAndCallPreferenceChangeListener(Preference preference,
            Preference.OnPreferenceChangeListener listener) {
        // Set the listener to watch for value changes. 
        preference.setOnPreferenceChangeListener(listener);
 
        // Trigger the listener immediately with the preference's 
        // current value. 
        listener.onPreferenceChange(preference,
                PreferenceManager 
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getContext, setSummary
                // 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]) 
                                .toString().replaceAll("%", "%%") 
                                : null); 
 
            } else if (preference instanceof RingtonePreference) { 
                // For ringtone preferences, look up the correct display value 
                // using RingtoneManager. 
                if (TextUtils.isEmpty(stringValue)) { 
                    // Empty values correspond to 'silent' (no ringtone). 
                    //preference.setSummary(R.string.pref_ringtone_silent); 
 
                } else { 
                    Ringtone ringtone = RingtoneManager.getRingtone( 

6
CodeRank
This code example shows how to use the following methods:getContext, getKey, setOnPreferenceChangeListener
     * immediately called with the preference's current value upon calling this method. 
     */ 
    public static void setAndCallPreferenceChangeListener(Preference preference,
            Preference.OnPreferenceChangeListener listener) {
        // Set the listener to watch for value changes. 
        preference.setOnPreferenceChangeListener(listener);
 
        // Trigger the listener immediately with the preference's 
        // current value. 
        listener.onPreferenceChange(preference,
                PreferenceManager 
                        .getDefaultSharedPreferences(preference.getContext())
                        .getBoolean(preference.getKey(), true));
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getContext, getSharedPreferences, setEnabled, setSummary
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.layout.recentvideo_setting);
	 } 
	 
	@Override 
	public void onResume() { 
		super.onResume(); 
		final EditTextPreference pref = (EditTextPreference)findPreference("recentvideo_last_refresh");
		new RecentVideoRefreshPrefUpdater(pref);
	} 
} 

6
CodeRank
This code example shows how to use the following methods:getContext, addPreference
        super(p);
    } 
 
    @Override 
    protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
        Context c = subpanel.getContext();
        subpanel.addPreference(createSecretPreference(c));
        subpanel.addPreference(createSecretStringPreference(c));
 
        L2tpProfile profile = (L2tpProfile) getProfile();
    } 
 
    @Override 
    public String validate() {
        String result = super.validate();
        if (!mSecret.isChecked()) return result;
 
        return ((result != null) ? result : mSecretHandler.validate());
    } 
 
6
CodeRank
This code example shows how to use the following methods:getContext, setSummary
                // 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]) 
                                .toString().replaceAll("%", "%%") 
                                : null); 
 
            } else if (preference instanceof RingtonePreference) { 
                // For ringtone preferences, look up the correct display value 
                // using RingtoneManager. 
                if (TextUtils.isEmpty(stringValue)) { 
                    // Empty values correspond to 'silent' (no ringtone). 
                    //preference.setSummary(R.string.pref_ringtone_silent); 
 
                } else { 
                    Ringtone ringtone = RingtoneManager.getRingtone( 

6
CodeRank
This code example shows how to use the following methods:getContext, getSharedPreferences, setEnabled, setSummary
		this.pref = pref;
		setValues(); 
	} 
 
	private void setValues() { 
		String timeAgoStr = pref.getSharedPreferences().getString("recentvideo_last_refresh", "0");
		String text = "";
		if(timeAgoStr == null || timeAgoStr.length() == 0)  {
			text = "Not yet";
		} 
		else { 
			long timeAgo = Long.valueOf(timeAgoStr);
			text = TimeAgo.toFriendlyString(pref.getContext(), timeAgo);
		} 
		 
		pref.setSummary(text);
		pref.setEnabled(false);
	} 
} 

6
CodeRank
This code example shows how to use the following methods:getContext, addPreference
        super(p);
    } 
 
    @Override 
    protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
        Context c = subpanel.getContext();
        subpanel.addPreference(createEncryptionPreference(c));
 
        PptpProfile profile = (PptpProfile) getProfile();
    } 
 
    private Preference createEncryptionPreference(Context c) {
        final PptpProfile profile = (PptpProfile) getProfile();
        CheckBoxPreference encryption = mEncryption = new CheckBoxPreference(c);
        boolean enabled = profile.isEncryptionEnabled();
        setCheckBoxTitle(encryption, R.string.vpn_pptp_encryption_title);
        encryption.setChecked(enabled);
        setEncryptionSummary(encryption, enabled);
        encryption.setOnPreferenceChangeListener(
                new Preference.OnPreferenceChangeListener() {
6
CodeRank

Related Preference getContext Questions & Answers:

getContext Method Overview
Returns the Context of this Preference.
See Code Examples for other Android Preference Methods: