Java Code Examples for android.support.v7.preference.ListPreference#setOnPreferenceChangeListener()

The following examples show how to use android.support.v7.preference.ListPreference#setOnPreferenceChangeListener() . 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: USBGpsSettingsFragment.java    From UsbGps4Droid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.main_prefs);

    devicePreference = (ListPreference) findPreference(USBGpsProviderService.PREF_GPS_DEVICE);
    deviceSpeedPreference = (ListPreference) findPreference(USBGpsProviderService.PREF_GPS_DEVICE_SPEED);
    devicePreference.setOnPreferenceChangeListener(this);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);

    usbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
    activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    mainHandler = new Handler(getActivity().getMainLooper());

    setupNestedPreferences();
}
 
Example 2
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeTheme(
        final Activity activity,
        final ListPreference theme)
{
    if (null != theme) {
        theme.setSummary(theme.getEntry());

        theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
        {
            @Override
            public boolean onPreferenceChange(
                    Preference preference,
                    Object newValue)
            {
                activity.startActivity(activity.getIntent());
                activity.finish();
                return true;
            }
        });
    }
}
 
Example 3
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeShowStatusPanel(final ListPreference listPreference)
{
    listPreference.setSummary(listPreference.getEntry());

    listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            preference.setSummary(listPreference.getEntries()[listPreference.findIndexOfValue(
                    (String) newValue)]);

            return true;
        }
    });
}
 
Example 4
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeShowCurrentLocation(
        final ListPreference listPreference)
{
    listPreference.setSummary(listPreference.getEntry());

    listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            preference.setSummary(listPreference.getEntries()[listPreference.findIndexOfValue(
                    (String) newValue)]);

            return true;
        }
    });
}
 
Example 5
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeMapBG(final ListPreference mapBG)
{
    mapBG.setSummary(mapBG.getEntry());

    mapBG.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            preference.setSummary(
                    mapBG.getEntries()[mapBG.findIndexOfValue((String) newValue)]);
            return true;
        }
    });
}
 
Example 6
Source File: SettingsFragment.java    From nevo-decorators-sms-captchas with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.main_setting);
    getPreferenceScreen().setEnabled(false);

    mCaptchaHideOnLocked           = (CheckBoxPreference) findPreference(Settings.SETTING_CAPTCHA_HIDE_ON_LOCKED);
    mCaptchaOverrideDefaultAction  = (CheckBoxPreference) findPreference(Settings.SETTING_CAPTCHA_OVERRIDE_DEFAULT_ACTION);
    mCaptchaPostCopyAction         = (ListPreference)     findPreference(Settings.SETTING_CAPTCHA_POST_COPY_ACTION);
    mCaptchaIdentifyPattern        = (EditTextPreference) findPreference(Settings.SETTING_CAPTCHA_IDENTIFY_PATTERN);
    mCaptchaParsePattern           = (EditTextPreference) findPreference(Settings.SETTING_CAPTCHA_PARSE_PATTERN);
    mSubscribeIdentityPattern      = (EditTextPreference) findPreference(Settings.SETTING_SUBSCRIBE_IDENTIFY_PATTERN);
    mSubscribePriority             =                      findPreference(Settings.SETTING_SUBSCRIBE_PRIORITY);
    mHideInLauncher                = (CheckBoxPreference) findPreference(KEY_HIDE_IN_LAUNCHER);

    mCaptchaHideOnLocked.setOnPreferenceChangeListener(this::onPreferenceChange);
    mCaptchaOverrideDefaultAction.setOnPreferenceChangeListener(this::onPreferenceChange);
    mCaptchaPostCopyAction.setOnPreferenceChangeListener(this::onPreferenceChange);
    mCaptchaIdentifyPattern.setOnPreferenceChangeListener(this::onPreferenceChange);
    mCaptchaParsePattern.setOnPreferenceChangeListener(this::onPreferenceChange);
    mSubscribeIdentityPattern.setOnPreferenceChangeListener(this::onPreferenceChange);
    mHideInLauncher.setOnPreferenceChangeListener(this::onPreferenceChange);
    mSubscribePriority.setOnPreferenceChangeListener(this::onPreferenceChange);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
        mSubscribePriority.setOnPreferenceClickListener((Preference p) -> {
            startActivity(
                    new Intent("android.settings.APP_NOTIFICATION_SETTINGS").
                            putExtra("android.provider.extra.APP_PACKAGE" , Global.NEVOLUTION_PACKAGE_NAME));
            return false;
        });
    }

    new Thread(this::loadSettingsAndUpdateViews).start();
}
 
Example 7
Source File: EditCustomThemeActivity.java    From NumberPadTimePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);
    mShowFabPolicyPreference = (ListPreference) findPreference(PREF_SHOW_FAB_POLICY);
    mAnimateFabEntryPreference = (CheckBoxPreference) findPreference(PREF_ANIMATE_FAB_ENTRY);
    mAnimateFabColorPreference = (CheckBoxPreference) findPreference(PREF_ANIMATE_FAB_COLOR);

    mShowFabAlwaysValue = getResources().getString(R.string.show_fab_policy_default_value);

    mShowFabPolicyPreference.setOnPreferenceChangeListener(
            new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean dependentPrefEnabled = isShowFabAlways(newValue);
            if (!dependentPrefEnabled) {
                // These preferences do not apply for the new PREF_SHOW_FAB_POLICY value.
                // Save the preferences' checked states before we clear them, in case
                // the user sets the correct value again in this Fragment instance.
                mInitialAnimateFabEntryValue = mAnimateFabEntryPreference.isChecked();
                mInitialAnimateFabColorValue = mAnimateFabColorPreference.isChecked();
                mAnimateFabEntryPreference.setChecked(false);
                mAnimateFabColorPreference.setChecked(false);
            } else {
                mAnimateFabEntryPreference.setChecked(mInitialAnimateFabEntryValue);
                mAnimateFabColorPreference.setChecked(mInitialAnimateFabColorValue);
            }
            setPreferencesDependentOnShowFabPolicyEnabled(dependentPrefEnabled);
            return true;  // Write to storage
        }
    });
    // Initialize the enabled states of the dependent Preferences.
    setPreferencesDependentOnShowFabPolicyEnabled(isShowFabAlways(
            mShowFabPolicyPreference.getValue()));
}
 
Example 8
Source File: SettingsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private void initThemePref(String theme) {
    ListPreference themePref = (ListPreference)
            findPreference(getString(R.string.pref_key_theme));

    String theme_name = Settings.Utils.getThemeName(getActivity(), theme);
    themePref.setSummary(theme_name);
    themePref.setOnPreferenceChangeListener(this);
}
 
Example 9
Source File: SettingsActivity.java    From video-quickstart-android with MIT License 5 votes vote down vote up
private void setupCodecListPreference(Class codecClass,
                                      String key,
                                      String defaultValue,
                                      ListPreference preference) {
    List<String> codecEntries = new ArrayList<>();
    if(codecClass == AudioCodec.class){
        Collections.addAll(codecEntries, AUDIO_CODEC_NAMES);
    }else{
        Collections.addAll(codecEntries, VIDEO_CODEC_NAMES);
    }

    // Remove H264 if not supported
    if (!MediaCodecVideoDecoder.isH264HwSupported() ||
            !MediaCodecVideoEncoder.isH264HwSupported()) {
        codecEntries.remove(H264Codec.NAME);
    }
    String[] codecStrings = codecEntries.toArray(new String[codecEntries.size()]);

    // Saved value
    final String value = sharedPreferences.getString(key, defaultValue);

    // Bind values
    preference.setEntries(codecStrings);
    preference.setEntryValues(codecStrings);
    preference.setValue(value);
    preference.setSummary(value);
    preference.setOnPreferenceChangeListener((preference1, newValue) -> {
        preference1.setSummary(newValue.toString());
        return true;
    });
}
 
Example 10
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeUnits(final ListPreference lpUnits) {
    lpUnits.setSummary(lpUnits.getEntry());
    lpUnits.setOnPreferenceChangeListener(
            new Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean metric = newValue.equals("metric");
                    preference.setSummary(lpUnits.getEntries()[metric ? 0 : 1]);
                    return true;
                }
            });
}
 
Example 11
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeLocationAccuracy(
        final ListPreference listPreference,
        final boolean isTracks)
{
    if (listPreference != null) {
        CharSequence[] entries = getAccuracyEntries(listPreference.getContext());
        listPreference.setEntries(entries);
        listPreference.setSummary(listPreference.getEntry());

        listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
        {
            @Override
            public boolean onPreferenceChange(
                    Preference preference,
                    Object newValue)
            {
                int value = Integer.parseInt(newValue.toString());
                CharSequence summary = ((ListPreference) preference).getEntries()[value - 1];
                preference.setSummary(summary);

                sectionWork(preference.getContext(), isTracks);

                return true;
            }
        });
    }
}
 
Example 12
Source File: PanicPreferencesFragment.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences_panic);

    pm = getActivity().getPackageManager();
    prefExit = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_EXIT);
    prefApp = (ListPreference) findPreference(PREF_APP);
    prefHide = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_HIDE);
    prefHide.setTitle(getString(R.string.panic_hide_title, getString(R.string.app_name)));
    prefResetRepos = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_RESET_REPOS);
    categoryAppsToUninstall = (PreferenceCategory) findPreference("pref_panic_apps_to_uninstall");

    if (PanicResponder.checkForDisconnectIntent(getActivity())) {
        // the necessary action should have been performed by the check already
        getActivity().finish();
        return;
    }
    String connectIntentSender = PanicResponder.getConnectIntentSender(getActivity());
    // if there's a connecting app and it is not the old one
    if (!TextUtils.isEmpty(connectIntentSender) && !TextUtils.equals(connectIntentSender, PanicResponder
            .getTriggerPackageName(getActivity()))) {
        // Show dialog allowing the user to opt-in
        showOptInDialog();
    }

    prefApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String packageName = (String) newValue;
            PanicResponder.setTriggerPackageName(getActivity(), packageName);
            if (packageName.equals(Panic.PACKAGE_NAME_NONE)) {
                prefHide.setChecked(false);
                prefHide.setEnabled(false);
                prefResetRepos.setChecked(false);
                prefResetRepos.setEnabled(false);
                getActivity().setResult(Activity.RESULT_CANCELED);
            } else {
                prefHide.setEnabled(true);
                prefResetRepos.setEnabled(true);
            }
            showPanicApp(packageName);
            return true;
        }
    });
    showPanicApp(PanicResponder.getTriggerPackageName(getActivity()));
}