Java Code Examples for android.support.v7.preference.Preference#getKey()

The following examples show how to use android.support.v7.preference.Preference#getKey() . 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: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();
    String key = preference.getKey();

    if (preference instanceof ListPreference) {
        /* For list preferences, look up the correct display value in */
        /* the preference's 'entries' list (since they have separate labels/values). */
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 2
Source File: SettingsFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(@NonNull Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    final String key = preference.getKey();
    if (preference instanceof MultiSelectListPreference) {
        Set<String> summary = SharedPreferencesCompat.getStringSet(
                PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
                key,
                new HashSet<>());
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
    } else if (preference instanceof ColorPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((ColorPreference) preference).getColor());
    } else if (preference instanceof SeekBarPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
    } else {
        String value = PreferenceManager
                .getDefaultSharedPreferences(preference.getContext())
                .getString(key, "");
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
    }
}
 
Example 3
Source File: BeaconEventPageFragment.java    From beaconloc with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {

    String key = preference.getKey();
    if (key.equals("be_event_enter_region")) {
        mActionBeacon.setEventType(ActionBeacon.EventType.EVENT_ENTERS_REGION);
    } else if (key.equals("be_event_leaves_region")) {
        mActionBeacon.setEventType(ActionBeacon.EventType.EVENT_LEAVES_REGION);
    } else {
        mActionBeacon.setEventType(ActionBeacon.EventType.EVENT_NEAR_YOU);
    }

    setData();

    return super.onPreferenceTreeClick(preference);
}
 
Example 4
Source File: SettingsActivity.java    From Stringlate with MIT License 6 votes vote down vote up
@Override
public Boolean onPreferenceClicked(Preference preference) {
    if (isAdded() && preference.hasKey()) {
        String key = preference.getKey();

        if (key.equals(getString(R.string.pref_key__github_authentication_request))) {
            Uri url = Uri.parse(GitHub.Authentication.getAuthRequestUrl());
            startActivity(new Intent(Intent.ACTION_VIEW, url));
        }

        if (key.equals(getString(R.string.pref_key__language))) {
            activityRetVal = RESULT.CHANGE_RESTART;
        }
    }
    return false;
}
 
Example 5
Source File: SettingsFragment.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
    boolean checked = (boolean) o;
    String key = preference.getKey();
    switch (key) {
        case KEY_FORCE_ENGLISH:
        case KEY_DARK_THEME:
            getActivity().finish();
            Intent intent = new Intent(getActivity(), MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(NavigationActivity.INTENT_SECTION,
                    SettingsFragment.class.getCanonicalName());
            startActivity(intent);
            return true;
        case KEY_MATERIAL_ICON:
            Utils.setStartActivity(checked, getActivity());
            return true;
        case KEY_HIDE_BANNER:
            if (!Utils.DONATED) {
                ViewUtils.dialogDonate(getActivity()).show();
                return false;
            }
            return true;
        case KEY_SECTIONS_ICON:
            if (key.equals(KEY_SECTIONS_ICON) && !Utils.DONATED) {
                ViewUtils.dialogDonate(getActivity()).show();
                return false;
            }
            ((NavigationActivity) getActivity()).appendFragments();
            return true;
        default:
            if (key.endsWith("_enabled")) {
                ((NavigationActivity) getActivity()).appendFragments();
                return true;
            }
            break;
    }
    return false;
}
 
Example 6
Source File: PrefsFragment.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    switch (preference.getKey()) {
        case AppSettings.APP_THEME_KEY:
            ActivityAlarmClock.activityAlarmClock.finish();

            startActivity(new Intent(getActivity(), ActivityAlarmClock.class));

            getActivity().finish();
            break;
        case AppSettings.NOTIFICATION_TEXT:
            final String customNotificationText = getResources().getStringArray(
                    R.array.notification_text_values)[3];

            if (newValue.equals(customNotificationText)) {
                DialogFragment dialog = new ActivityDialogFragment().newInstance(
                        CUSTOM_NOTIFICATION_TEXT);

                dialog.show(getFragmentManager(), "ActivityDialogFragment");
            } else {
                final Intent causeRefresh = new Intent(getActivity(),
                        AlarmClockService.class);

                causeRefresh.putExtra(AlarmClockService.COMMAND_EXTRA,
                        AlarmClockService.COMMAND_NOTIFICATION_REFRESH);

                getActivity().startService(causeRefresh);
            }
            break;
        default:
            break;
    }

    return true;
}
 
Example 7
Source File: PreferencesUi.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference.getKey() == null)
        return false;
    switch (preference.getKey()){
        case "enable_headset_detection":
            ((PreferencesActivity)getActivity()).detectHeadset(((TwoStatePreference) preference).isChecked());
            return true;
        case "enable_steal_remote_control":
            PlaybackService.Client.restartService(getActivity());
            return true;
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example 8
Source File: Developer.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    switch (preference.getKey()){
        case "debug_logs":
            Intent intent = new Intent(VLCApplication.getAppContext(), DebugLogActivity.class);
            startActivity(intent);
            return true;
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example 9
Source File: Advanced.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    switch (preference.getKey()) {
        case "clear_history":
            new AlertDialog.Builder(getActivity())
                    .setTitle(R.string.clear_history)
                    .setMessage(R.string.validation)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            MediaDatabase db = MediaDatabase.getInstance();
                            db.clearSearchHistory();
                        }
                    })

                    .setNegativeButton(android.R.string.cancel, null).show();
            return true;
        case "clear_media_db":
            MediaDatabase.getInstance().emptyDatabase();
            BitmapCache.getInstance().clear();
            AudioUtil.clearCacheFolders();
            getActivity().setResult(PreferencesActivity.RESULT_RESCAN);
            Util.snacker(getView(), R.string.media_db_cleared);
            return true;
        case "quit_app":
            android.os.Process.killProcess(android.os.Process.myPid());
            return true;
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example 10
Source File: PreferencesFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    switch (preference.getKey()){
        case "directories":
            Intent intent = new Intent(VLCApplication.getAppContext(), SecondaryActivity.class);
            intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER);
            startActivity(intent);
            getActivity().setResult(PreferencesActivity.RESULT_RESTART);
            return true;
        case "enable_black_theme":
            ((PreferencesActivity) getActivity()).exitAndRescan();
            return true;
        case "ui_category":
            loadFragment(new PreferencesUi());
            break;
        case "perf_category":
            loadFragment(new PreferencesPerformances());
            break;
        case "adv_category":
            loadFragment(new Advanced());
            break;
        case "dev_category":
            loadFragment(new Developer());
            break;
        default:
            return super.onPreferenceTreeClick(preference);
    }
    return true;
}
 
Example 11
Source File: SettingsFragment.java    From QuickNote with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(Preference preference) {
    String key = preference.getKey();
    if (key.equals(KEY_ABOUT)) {
        ((MainActivity) getActivity()).switchFragmentByTag(MainActivity.ABOUT_FRAGMENT);
    } else if (key.equals(KEY_RECOMMEND)) {

    } else if (key.equals(KEY_DONATE)) {
        ((MainActivity) getActivity()).switchFragmentByTag(MainActivity.PURCHASE_FRAGMENT);
    } else if (key.equals(KEY_HIGH_PRAISE)) {
        CommonUtil.jumpToMarket(getContext(), CommonUtil.getPackageName(getContext()), null);
    }
    return false;
}
 
Example 12
Source File: SettingsFragment.java    From QuickNote with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String key = preference.getKey();
    if (key.equals(KEY_THEME)) {
        if (value.equals(QuickNote.getString(R.string.theme_value_default))) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        } else if (value.equals(QuickNote.getString(R.string.theme_value_night))) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        }
        getActivity().recreate();
    } else if (key.equals(KEY_LANG)) {
        if (value.equals(QuickNote.getString(R.string.lang_value_chinese))) {
            CommonUtil.changeLocalLanguage(QuickNote.getAppContext(), Locale.SIMPLIFIED_CHINESE);
        } else if (value.equals(QuickNote.getString(R.string.lang_value_english))) {
            CommonUtil.changeLocalLanguage(QuickNote.getAppContext(), Locale.US);
        }
        getActivity().recreate();
    } else if (key.equals(KEY_AUTO_UPDATE)) {
        if (value.equals(false)) { // 提示用户如需更新可到关于界面进行手动更新
            CommonUtil.showSnackBarOnUiThread(getView(), R.string.prompt_close_auto_update);
        }
    } else if (key.equals(KEY_GESTURE_PWD)) {
        if (value.equals(true)) {
            if (TextUtils.isEmpty(QuickNote.getSavedPattern())) { // 如果是初次启用
                Intent intent = new Intent(getActivity(), LockActivity.class);
                startActivity(intent);
            }
        }
    }
    return true;
}
 
Example 13
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
@Deprecated
public boolean onPreferenceTreeClick(Preference preference) {
    if (isAdded()) {
        String key = preference.hasKey() ? preference.getKey() : "";
        int keyResId = keyToStringResId(preference);
        Boolean ret = onPreferenceClicked(preference, key, keyResId);
        if (ret != null) {
            return ret;
        }
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example 14
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Deprecated
public boolean onPreferenceTreeClick(Preference preference) {
    if (isAdded()) {
        String key = preference.hasKey() ? preference.getKey() : "";
        int keyResId = keyToStringResId(preference);
        Boolean ret = onPreferenceClicked(preference, key, keyResId);
        if (ret != null) {
            return ret;
        }
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example 15
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 5 votes vote down vote up
@Override
@Deprecated
public boolean onPreferenceTreeClick(Preference preference) {
    if (isAdded()) {
        String key = preference.hasKey() ? preference.getKey() : "";
        int keyResId = keyToStringResId(preference);
        Boolean ret = onPreferenceClicked(preference, key, keyResId);
        if (ret != null) {
            return ret;
        }
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example 16
Source File: SettingsActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat preferenceFragmentCompat, @NonNull Preference preference) {
    final String key = preference.getKey();
    DialogFragment f;
    if (preference instanceof ColorPreference) {
        f = XpColorPreferenceDialogFragment.newInstance(key);
    } else {
        return false;
    }

    f.setTargetFragment(preferenceFragmentCompat, 0);
    f.show(this.getSupportFragmentManager(), key);
    return true;
}
 
Example 17
Source File: SettingsFragmentView.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
@Override public boolean onPreferenceClick(Preference preference) {
    switch (preference.getKey()) {
        case "fa_background_alpha":
            IconSizeTransparencyDialog.newInstance(true).show(getChildFragmentManager(), "IconSizeTransparencyDialog");
            return true;
        case "icon_pack":
            IconPackHelper.pickIconPack(this, false);
            return true;
        case "custom_icon":
            new CustomIconChooserDialog().show(getChildFragmentManager(), "CustomIconChooserDialog");
            return true;
        case "icon_alpha":
            IconSizeTransparencyDialog.newInstance(false).show(getChildFragmentManager(), "IconSizeTransparencyDialog");
            return true;
        case "manual_size":
            IconSizeTransparencyDialog.newInstance(false, true).show(getChildFragmentManager(), "IconSizeTransparencyDialog");
            return true;
        case "version":
            return true;
        case "sourceCode":
            ActivityHelper.startCustomTab(getActivity());
            return true;
        case "libraries":
            ActivityHelper.startLibs(getActivity());
            return true;
        case "about_me":
            startActivity(new Intent(getContext(), AboutMeView.class));
            return true;
        case "email_us":
            ShareCompat.IntentBuilder.from(getActivity())
                    .setType("message/rfc822")
                    .setEmailTo(new String[]{"[email protected]"})
                    .setSubject(getString(R.string.email_subject))
                    .setText(AppHelper.getEmailBody())
                    .setChooserTitle(getString(R.string.choose_email))
                    .startChooser();
            return true;
        case "whats_new":
            startActivity(new Intent(getContext(), WhatsNewView.class));
            return true;
        case "intro":
            startActivity(new Intent(getContext(), IntroPagerView.class));
            return true;
    }
    return false;
}
 
Example 18
Source File: SettingsActivity.java    From home-assistant-Android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    View preferenceView = getListView().findViewHolderForAdapterPosition(preference.getOrder()).itemView;

    switch (preference.getKey()) {
        case Common.PREF_LOCATION_UPDATE_INTERVAL:
            ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
            listPopupWindow.setAnchorView(preferenceView);
            listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), android.support.design.R.layout.support_simple_spinner_dropdown_item, getResources().getStringArray(R.array.location_update_interval_summaries)));
            listPopupWindow.setContentWidth(getResources().getDimensionPixelSize(R.dimen.popup_window_width));
            listPopupWindow.setHorizontalOffset(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin));
            listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
                Log.d("Selected", String.valueOf(position));
                prefs.edit().putInt(Common.PREF_LOCATION_UPDATE_INTERVAL,
                        getResources().getIntArray(R.array.location_update_interval_values)[position]).apply();
                listPopupWindow.dismiss();
                updatePreferenceSummaries();
                updateLocationTracker();
            });
            listPopupWindow.show();
            return true;
        case Common.PREF_RESET_HOST_MISMATCHES:
            prefs.edit().remove(Common.PREF_ALLOWED_HOST_MISMATCHES_KEY).apply();
            Toast.makeText(getActivity(), R.string.toast_ignored_ssl_mismatches_cleared, Toast.LENGTH_SHORT).show();
            updatePreferenceSummaries();
            return true;
        case Common.HELP_TRANSLATE:
            CustomTabsSession session = ((SettingsActivity) getActivity()).getCustomTabsSession();
            if (session != null) {
                @SuppressWarnings("deprecation") CustomTabsIntent intent = new CustomTabsIntent.Builder(session)
                        .setShowTitle(true)
                        .enableUrlBarHiding()
                        .setToolbarColor(getResources().getColor(R.color.primary))
                        .build();
                intent.launchUrl(getActivity(), Uri.parse(Common.CROWDIN_URL));
            }
            return true;
        default:
            return super.onPreferenceTreeClick(preference);
    }
}
 
Example 19
Source File: AboutFragment.java    From NanoIconPack with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onPreferenceClick(Preference preference) {
        switch (preference.getKey()) {
//            case PREFERENCE_ICONS_NOTE:
//                break;
            case PREFERENCE_ICONS_AUTHOR:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_icons_summary_author));
                break;
            case PREFERENCE_ICONS_CONTACT:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_icons_summary_contact));
                break;
            case PREFERENCE_ICONS_TODO_1:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_icons_summary_todo_1));
                break;
            case PREFERENCE_ICONS_COPYRIGHT:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_icons_summary_copyright));
                break;
            case PREFERENCE_SUPPORT_DONATE:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_support_summary_donate));
                break;
            case PREFERENCE_SUPPORT_TODO_1:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_support_summary_todo_1));
                break;
            case PREFERENCE_SUPPORT_SPONSORS:
                showDonate();
                break;
//            case PREFERENCE_APP_APP:
//                executeCode(preference.getTitle().toString(), preference.getSummary().toString());
//                break;
            case PREFERENCE_APP_TODO_1:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_app_summary_todo_1));
                break;
            case PREFERENCE_APP_DASHBOARD:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_app_summary_dashboard));
                break;
            case PREFERENCE_DEV_STATS:
                enterStats();
                break;
            case PREFERENCE_DEV_QUERY:
                executeCode(preference.getTitle().toString(),
                        getString(R.string.preference_dev_summary_query));
                break;
        }
        return true;
    }
 
Example 20
Source File: SettingsFragment.java    From nevo-decorators-sms-captchas with GNU General Public License v3.0 4 votes vote down vote up
private boolean onPreferenceChange(Preference preference, Object value) {
    String key = preference.getKey();
    int valueInteger = 0;

    switch (key) {
        case Settings.SETTING_CAPTCHA_HIDE_ON_LOCKED:
            mSettings.setCaptchaHideOnLocked((Boolean) value);
            mAppPreferences.put(key, (Boolean) value);
            break;
        case Settings.SETTING_CAPTCHA_OVERRIDE_DEFAULT_ACTION :
            mSettings.setCaptchaOverrideDefaultAction((Boolean) value);
            mAppPreferences.put(key ,(Boolean) value);
            break;
        case Settings.SETTING_CAPTCHA_USE_DEFAULT_PATTERN :
            mSettings.setCaptchaUseDefaultPattern((Boolean) value);
            mAppPreferences.put(key ,(Boolean) value);
            break;
        case Settings.SETTING_CAPTCHA_POST_COPY_ACTION :
            valueInteger = Integer.parseInt((String) value);
            mSettings.setCaptchaPostCopyAction(valueInteger);
            mAppPreferences.put(key ,valueInteger);
            showPermissionTips(valueInteger);
            break;
        case Settings.SETTING_CAPTCHA_IDENTIFY_PATTERN:
            if (checkPatternInvalidAndMakeToast((String) value)) return false;
            mSettings.setCaptchaIdentifyPattern((String) value);
            mAppPreferences.put(key, (String) value);
            break;
        case Settings.SETTING_CAPTCHA_PARSE_PATTERN:
            if (checkPatternInvalidAndMakeToast((String) value)) return false;
            mSettings.setCaptchaParsePattern((String) value);
            mAppPreferences.put(key, (String) value);
            break;
        case Settings.SETTING_SUBSCRIBE_IDENTIFY_PATTERN:
            if (checkPatternInvalidAndMakeToast((String) value)) return false;
            mSettings.setSubscribeIdentifyPattern((String) value);
            mAppPreferences.put(key, (String) value);
            break;
        case Settings.SETTING_SUBSCRIBE_PRIORITY:
            valueInteger = Integer.parseInt((String) value);
            mSettings.setSubscribePriority(valueInteger);
            mAppPreferences.put(key, valueInteger);
            break;
        case KEY_HIDE_IN_LAUNCHER:
            new Thread(() -> updateMainActivityEnabled(!(Boolean)value)).start();
            break;
    }

    return true;
}