Java Code Examples for android.preference.Preference#setSummary()

The following examples show how to use android.preference.Preference#setSummary() . 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: SettingsActivity.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 2
Source File: SettingsActivity.java    From privacy-friendly-passwordgenerator with GNU General Public License v3.0 6 votes vote down vote up
@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 {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 3
Source File: SettingsActivity.java    From remotekeyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
		String key) {
	Preference preference = findPreference(key);
	if (preference instanceof ListPreference) {
		preference.setSummary(((ListPreference) preference).getEntry());
	}
	SharedPreferences sharedPref = PreferenceManager
			.getDefaultSharedPreferences(this);
	if (sharedPref.getString(TelnetEditorShell.PREF_PASSWORD, "").equals("")) {
		findPreference(TelnetEditorShell.PREF_PASSWORD).setSummary(
				R.string.msg_password_not_set);
	}
	else {
		findPreference(TelnetEditorShell.PREF_PASSWORD).setSummary(
				R.string.msg_password_set);
	}
	
	try {
		RemoteKeyboardService.self.updateFullscreenMode();
	}
	catch (Exception e) {}

}
 
Example 4
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example 5
Source File: BasePreferenceFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public Preference makeButton(PreferenceGroup parent, CharSequence title, CharSequence summary,
		boolean information) {
	Preference preference = information ? new Preference(getActivity(), null,
			android.R.attr.preferenceInformationStyle) : new Preference(getActivity());
	preference.setTitle(title);
	preference.setSummary(summary);
	addPreference(parent, preference);
	return preference;
}
 
Example 6
Source File: AutofillAndPaymentsPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void refreshPaymentAppsPref() {
    Preference pref = findPreference(PREF_ANDROID_PAYMENT_APPS);
    if (pref != null) {
        if (AndroidPaymentAppFactory.hasAndroidPaymentApps()) {
            pref.setSummary(null);
            pref.setEnabled(true);
        } else {
            pref.setSummary(getActivity().getString(R.string.payment_no_apps_summary));
            pref.setEnabled(false);
        }
    }
}
 
Example 7
Source File: SettingsActivity.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary("Silent");
        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }
    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 8
Source File: AccountPreferencesFragment.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
	if (isNewAccount) {
		builder.setDisplayName(newValue.toString());
	} else {
		mPrefs.setAccountDisplayName(n, newValue.toString());
	}
	preference.setSummary(newValue.toString());
	return true;
}
 
Example 9
Source File: AboutFragment.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.about_settings);

    Preference author = findPreference(KEY_AUTHOR);
    // Preference donate = findPreference(KEY_DONATE);
    // Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);

    author.setSummary(getString(R.string.settings_about_author_summary).replace('$', '@'));

    author.setOnPreferenceClickListener(this);
    // donate.setOnPreferenceClickListener(this);
    // checkForUpdate.setOnPreferenceClickListener(this);
}
 
Example 10
Source File: AccountPreferencesFragment.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
	if (isNewAccount) {
		builder.setUserId(newValue.toString());
	} else {
		mPrefs.setAccountUserId(n, newValue.toString());
	}
	preference.setSummary(newValue.toString());
	return true;
}
 
Example 11
Source File: SettingsActivity.java    From mOrgAnd with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    preference.setSummary(value.toString());

    PreferenceUtils.set("git_local_path", "");
    preference.getPreferenceManager().findPreference("git_local_path").setSummary("");

    return true;
}
 
Example 12
Source File: SettingsActivity.java    From wshell with GNU General Public License v3.0 5 votes vote down vote up
private void setSummary(Preference pref, boolean init) {
	if (pref instanceof EditTextPreference) {
		EditTextPreference editPref = (EditTextPreference) pref;
		pref.setSummary(editPref.getText());
	}

	if (pref instanceof ListPreference) {
		ListPreference listPref = (ListPreference) pref;
		pref.setSummary(listPref.getEntry());
	}
}
 
Example 13
Source File: ThemeSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
static void updateKeyboardThemeSummary(final Preference pref) {
    final Context context = pref.getContext();
    final Resources res = context.getResources();
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeNames.length; index++) {
        if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
            pref.setSummary(keyboardThemeNames[index]);
            return;
        }
    }
}
 
Example 14
Source File: AboutPreferenceFragment.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	addPreferencesFromResource(R.xml.preference_about);

	// set the app's version number
	Preference versionPref = findPreference(getString(R.string.pref_key_version));
	versionPref.setSummary(getAppVersion());

	// check for updates option
	Preference updatesPref = findPreference(getString(R.string.pref_key_updates));
	if (BuildConfig.FLAVOR.equalsIgnoreCase("oss")) {
		// remove the updates option if the user is running the OSS flavor...
		getPreferenceScreen().removePreference(updatesPref);
	} else {
		updatesPref.setOnPreferenceClickListener(preference -> {
			new UpdatesCheckerTask(getActivity(), true).executeInParallel();
			return true;
		});
	}

	// if the user clicks on the website link, then open it using an external browser
	Preference websitePref = findPreference(getString(R.string.pref_key_website));
	websitePref.setSummary(BuildConfig.SKYTUBE_WEBSITE);
	websitePref.setOnPreferenceClickListener(preference -> {
		// view the app's website in a web browser
		Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.SKYTUBE_WEBSITE));
		startActivity(browserIntent);
		return true;
	});

	// credits
	Preference creditsPref = findPreference(getString(R.string.pref_key_credits));
	creditsPref.setOnPreferenceClickListener(preference -> {
		displayCredits();
		return true;
	});

	// if the user clicks on the license, then open the display the actual license
	Preference licensePref = findPreference(getString(R.string.pref_key_license));
	licensePref.setOnPreferenceClickListener(preference -> {
		displayAppLicense();
		return true;
	});
}
 
Example 15
Source File: PrivacyPreferences.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the summaries for several preferences.
 */
public void updateSummaries() {
    PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();

    PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance();

    CharSequence textOn = getActivity().getResources().getText(R.string.text_on);
    CharSequence textOff = getActivity().getResources().getText(R.string.text_off);

    CheckBoxPreference navigationErrorPref = (CheckBoxPreference) findPreference(
            PREF_NAVIGATION_ERROR);
    if (navigationErrorPref != null) {
        navigationErrorPref.setChecked(
                prefServiceBridge.isResolveNavigationErrorEnabled());
    }

    CheckBoxPreference searchSuggestionsPref = (CheckBoxPreference) findPreference(
            PREF_SEARCH_SUGGESTIONS);
    if (searchSuggestionsPref != null) {
        searchSuggestionsPref.setChecked(prefServiceBridge.isSearchSuggestEnabled());
    }

    String extended_reporting_pref = prefServiceBridge.isSafeBrowsingScoutReportingActive()
            ? PREF_SAFE_BROWSING_SCOUT_REPORTING : PREF_SAFE_BROWSING_EXTENDED_REPORTING;
    CheckBoxPreference extendedReportingPref =
            (CheckBoxPreference) findPreference(extended_reporting_pref);
    if (extendedReportingPref != null) {
        extendedReportingPref.setChecked(
                prefServiceBridge.isSafeBrowsingExtendedReportingEnabled());
    }

    CheckBoxPreference safeBrowsingPref =
            (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING);
    if (safeBrowsingPref != null) {
        safeBrowsingPref.setChecked(prefServiceBridge.isSafeBrowsingEnabled());
    }

    Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK);
    if (doNotTrackPref != null) {
        doNotTrackPref.setSummary(prefServiceBridge.isDoNotTrackEnabled() ? textOn : textOff);
    }

    Preference contextualPref = findPreference(PREF_CONTEXTUAL_SEARCH);
    if (contextualPref != null) {
        boolean isContextualSearchEnabled = !prefServiceBridge.isContextualSearchDisabled();
        contextualPref.setSummary(isContextualSearchEnabled ? textOn : textOff);
    }

    Preference physicalWebPref = findPreference(PREF_PHYSICAL_WEB);
    if (physicalWebPref != null) {
        physicalWebPref.setSummary(privacyPrefManager.isPhysicalWebEnabled()
                ? textOn : textOff);
    }

    Preference usageAndCrashPref = findPreference(PREF_USAGE_AND_CRASH_REPORTING);
    if (usageAndCrashPref != null) {
        usageAndCrashPref.setSummary(
                privacyPrefManager.isUsageAndCrashReportingPermittedByUser() ? textOn
                                                                             : textOff);
    }
}
 
Example 16
Source File: SettingsActivity.java    From journaldev with MIT License 4 votes vote down vote up
@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) {
        // 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));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 17
Source File: SettingsFragment.java    From MicroReader with MIT License 4 votes vote down vote up
private void showCacheSize(Preference preference) {
    preference.setSummary(getActivity().getString(R.string.cache_size) + CacheUtil.getCacheSize(getActivity().getCacheDir()));
}
 
Example 18
Source File: SettingsActivity.java    From JayPS-AndroidApp with MIT License 4 votes vote down vote up
private void setLoginMmtSummary() {
    String login = _sharedPreferences.getString("LIVE_TRACKING_MMT_LOGIN", "");
    Preference loginPref = findPreference("LIVE_TRACKING_MMT_LOGIN");
    loginPref.setSummary(login);
}
 
Example 19
Source File: SuntimesSettingsActivity.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    Intent calendarIntent = new Intent();
    calendarIntent.setComponent(new ComponentName(calendarPackage, calendarActivity));
    calendarIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PackageManager packageManager = getActivity().getPackageManager();
    if (calendarIntent.resolveActivity(packageManager) != null)
    {
        try {
            startActivity(calendarIntent);
            getActivity().finish();
            getActivity().overridePendingTransition(R.anim.transition_next_in, R.anim.transition_next_out);
            return;

        } catch (Exception e) {
            Log.e("CalendarPrefs", "Unable to launch SuntimesCalendarActivity! " + e);
        }
    }

    AppSettings.initLocale(getActivity());
    addPreferencesFromResource(R.xml.preference_calendar);
    Preference calendarReadme = findPreference("appwidget_0_calendars_readme");
    if (calendarReadme != null)
    {
        calendarReadme.setSummary(SuntimesUtils.fromHtml(getString(R.string.help_calendar)));
        calendarReadme.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
        {
            @Override
            public boolean onPreferenceClick(Preference preference)
            {
                Activity activity = getActivity();
                if (activity != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(AboutDialog.ADDONS_URL));
                    if (intent.resolveActivity(activity.getPackageManager()) != null) {
                        activity.startActivity(intent);
                        activity.overridePendingTransition(R.anim.transition_next_in, R.anim.transition_next_out);
                    }
                }
                return false;
            }
        });
    }
    Log.i(LOG_TAG, "CalendarPrefsFragment: Arguments: " + getArguments());
}
 
Example 20
Source File: MainPreferences.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void setOnOffSummary(Preference pref, boolean isOn) {
    pref.setSummary(getResources().getString(isOn ? R.string.text_on : R.string.text_off));
}