Java Code Examples for android.preference.Preference#OnPreferenceChangeListener

The following examples show how to use android.preference.Preference#OnPreferenceChangeListener . 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 KeyBlocker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_settings);
    mSp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mSpEditor = mSp.edit();
    mSpEditor.apply();
    launchService = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference p, Object o) {
            BaseMethod.RestartAccessibilityService(getActivity());
            return true;
        }
    };
    GeneralSettings();
    ActivityBlockSettings();
    NotificationSettings();
    RootSettings();
    NSettings();
    CustomSettings();
}
 
Example 2
Source File: SettingsFragment.java    From android-sholi with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    Preference.OnPreferenceChangeListener c = new Preference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object value) {
            return checkImportMarkers(preference.getKey(), (String)value);
        }
    };

    findPreference(SettingsActivity.KEY_IMPORT_SYMBOL_CHECKED).setOnPreferenceChangeListener(c);
    findPreference(SettingsActivity.KEY_IMPORT_SYMBOL_UNCHECKED).setOnPreferenceChangeListener(c);
    findPreference(SettingsActivity.KEY_IMPORT_SYMBOL_OFF_LIST).setOnPreferenceChangeListener(c);
}
 
Example 3
Source File: SettingsActivity.java    From mosmetro-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(getString(R.string.pref_debug));
    addPreferencesFromResource(R.xml.pref_debug);

    Preference.OnPreferenceChangeListener reload_logger = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PreferenceManager.getDefaultSharedPreferences(getActivity())
                    .edit()
                    .putBoolean(preference.getKey(), (Boolean) newValue)
                    .apply();
            Logger.configure(getActivity());
            return true;
        }
    };

    CheckBoxPreference pref_debug_logcat =
            (CheckBoxPreference) getPreferenceScreen().findPreference("pref_debug_logcat");
    pref_debug_logcat.setOnPreferenceChangeListener(reload_logger);
}
 
Example 4
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private void addRatingPreference(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateRatingListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_MAX_RATING))) {
                setMaxRating((String) newValue);
                return true;
            }
            return false;
        }
    };
    ListPreference ratingPref = new LazyPreferences.ListPreference(context);
    ratingPref.setTitle(R.string.dobrochan_prefs_max_rating);
    ratingPref.setSummary(preferences.getString(getSharedKey(PREF_KEY_MAX_RATING), "R-15"));
    ratingPref.setEntries(RATINGS);
    ratingPref.setEntryValues(RATINGS);
    ratingPref.setDefaultValue("R-15");
    ratingPref.setKey(getSharedKey(PREF_KEY_MAX_RATING));
    ratingPref.setOnPreferenceChangeListener(updateRatingListener);
    group.addPreference(ratingPref);
}
 
Example 6
Source File: AbstractPreferenceAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
public S hasPreferenceChangeListener(Preference.OnPreferenceChangeListener listener) {
  isNotNull();
  Preference.OnPreferenceChangeListener actualListener = actual.getOnPreferenceChangeListener();
  assertThat(actualListener) //
      .overridingErrorMessage("Expected preference change listener <%s> but was <%s>.", listener,
          actualListener) //
      .isSameAs(listener);
  return myself;
}
 
Example 7
Source File: Utils.java    From VIA-AI with MIT License 5 votes vote down vote up
public static void linkSwitch(final SwitchPreference switchPreference, final ArrayList<Pair<Preference, Integer > > ctls) {

        Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object o) {
                boolean b = (boolean) o;
                switchPreference.setChecked(b);

                for(int i = 0 ; i < ctls.size() ; i++) {
                    Pair<Preference, Integer> p = ctls.get(i);
                    switch (p.second) {
                        case Utils.LINK_DIRECT:
                            p.first.setEnabled(switchPreference.isChecked());
                            break;
                        case Utils.LINK_INVERSE:
                            p.first.setEnabled(!switchPreference.isChecked());
                            break;
                    }
                }
                return false;
            }
        };

        switchPreference.setOnPreferenceChangeListener(listener);


        // process immediately
        listener.onPreferenceChange(switchPreference, switchPreference.isChecked());
    }
 
Example 8
Source File: BaseSettingsActivity.java    From BetterWeather with Apache License 2.0 5 votes vote down vote up
/**
 * When the preference's value is changed, trigger the given listener. The listener is also
 * immediately called with the preference's current value upon calling this method.
 */
protected 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(), ""));
}
 
Example 9
Source File: SettingsActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
private void setPreferenceCategoryChangeListener(
        Preference category, Preference.OnPreferenceChangeListener listener) {
    PreferenceScreen ps = (PreferenceScreen) category;
    for (int i = 0; i < ps.getPreferenceCount(); i++) {
        Preference p = ps.getPreference(i);
        p.setOnPreferenceChangeListener(listener);
    }
}
 
Example 10
Source File: U.java    From SecondScreen with Apache License 2.0 5 votes vote down vote up
public static void bindPreferenceSummaryToValue(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(), ""));
}
 
Example 11
Source File: SuntimesSettingsActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private static Preference.OnPreferenceChangeListener onOverrideThemeChanged(final Activity activity, final ThemePreference overridePref, final int requestCode)
{
    return new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            overridePref.setThemePreferenceListener(createThemeListPreferenceListener(activity, (String)newValue, requestCode));
            return true;
        }
    };
}
 
Example 12
Source File: MakabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/** Добавить категорию настроек домена (в т.ч. https) */
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))) {
                updateDomain((String) newValue, preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA), true));
                return true;
            } else if (preference.getKey().equals(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA))) {
                updateDomain(preferences.getString(getSharedKey(PREF_KEY_DOMAIN), DEFAULT_DOMAIN), (boolean)newValue);
                return true;
            }
            return false;
        }
    };
    PreferenceCategory domainCat = new PreferenceCategory(context);
    domainCat.setTitle(R.string.makaba_prefs_domain_category);
    group.addPreference(domainCat);
    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);
    domainCat.addPreference(domainPref);
    CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context); //чекбокс "использовать https"
    httpsPref.setTitle(R.string.pref_use_https);
    httpsPref.setSummary(R.string.pref_use_https_summary);
    httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA));
    httpsPref.setDefaultValue(true);
    httpsPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(httpsPref);
}
 
Example 13
Source File: VideoBlockerPreferenceFragment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	addPreferencesFromResource(R.xml.preference_video_blocker);

	final Preference channelBlacklistPreference = findPreference(getString(R.string.pref_key_channel_blacklist));
	final Preference channelWhitelistPreference = findPreference(getString(R.string.pref_key_channel_whitelist));

	// enable/disable the video blocker
	enablePreferences(isVideoBlockerEnabled(), channelBlacklistPreference, channelWhitelistPreference);
	findPreference(getString(R.string.pref_key_enable_video_blocker)).setOnPreferenceChangeListener((preference, newValue) -> {
		enablePreferences((boolean) newValue, channelBlacklistPreference, channelWhitelistPreference);
		Toast.makeText(getActivity(), R.string.setting_updated, Toast.LENGTH_LONG).show();
		return true;
	});

	// initialize the channel filtering UI
	findPreference(getString(R.string.pref_key_channel_filter_method)).setOnPreferenceChangeListener((preference, newValue) -> {
		initChannelFilteringPreferences((String) newValue, channelBlacklistPreference, channelWhitelistPreference);
		Toast.makeText(getActivity(), R.string.setting_updated, Toast.LENGTH_LONG).show();
		return true;
	});

	final Preference.OnPreferenceChangeListener settingUpdatesPreferenceChange = (preference, newValue) -> {
		Toast.makeText(getActivity(), R.string.setting_updated, Toast.LENGTH_LONG).show();
		return true;
	};

	// preferred region
	findPreference(getString(R.string.pref_key_preferred_region)).setOnPreferenceChangeListener(settingUpdatesPreferenceChange);

	// preferred language(s)
	findPreference(getString(R.string.pref_key_preferred_languages)).setOnPreferenceClickListener(preference -> {
		new PreferredLanguageDialog(getActivity()).show();
		return true;
	});
	findPreference(getString(R.string.pref_key_lang_detection_video_filtering)).setOnPreferenceChangeListener(settingUpdatesPreferenceChange);
	findPreference(getString(R.string.pref_key_low_views_filter)).setOnPreferenceChangeListener(settingUpdatesPreferenceChange);
	findPreference(getString(R.string.pref_key_dislikes_filter)).setOnPreferenceChangeListener(settingUpdatesPreferenceChange);
}
 
Example 14
Source File: PreferenceFragment.java    From AndroidBottomSheet with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the app's theme, when the value of the
 * corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * Preference.OnPreferenceChangeListener}
 */
private Preference.OnPreferenceChangeListener createThemeChangeListener() {
    return new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            getActivity().recreate();
            return true;
        }

    };
}
 
Example 15
Source File: InterfaceFragment.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_interface);
    SettingsActivity.bindPreferenceSummaryToValue(findPreference("prayer_highlight"));
    SettingsActivity.bindPreferenceSummaryToValue(findPreference("ui_theme"));

    Preference showAmPm = findPreference("show_ampm");
    Preference widgetBackground = findPreference("widget_background_color");
    Preference widgetImsak = findPreference("widget_show_imsak");
    Preference widgetSyuruk = findPreference("widget_show_syuruk");
    Preference widgetDhuha = findPreference("widget_show_dhuha");
    Preference widgetMasihi = findPreference("widget_show_masihi");
    Preference widgetHijri = findPreference("widget_show_hijri");

    Preference.OnPreferenceChangeListener widgetChange = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            WidgetService.start(getActivity());
            return true;
        }
    };

    showAmPm.setEnabled(!DateFormat.is24HourFormat(getActivity()));
    widgetBackground.setOnPreferenceChangeListener(widgetChange);
    widgetImsak.setOnPreferenceChangeListener(widgetChange);
    widgetSyuruk.setOnPreferenceChangeListener(widgetChange);
    widgetDhuha.setOnPreferenceChangeListener(widgetChange);
    widgetMasihi.setOnPreferenceChangeListener(widgetChange);
    widgetHijri.setOnPreferenceChangeListener(widgetChange);

    Dagger.getGraph(getActivity())
            .getAnalyticsProvider()
            .trackViewedScreen(AnalyticsProvider.SCREEN_SETTINGS_INTERFACE);
}
 
Example 16
Source File: Blacklist.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void draw() {
    AppListTask task = new AppListTask(appList);
    task.setIncludeSystemApps(true);
    task.execute();

    Preference.OnPreferenceChangeListener listener = new BlackListOnPreferenceChangeListener(appList, autoWhitelist);
    blackOrWhite.setOnPreferenceChangeListener(listener);
    listener.onPreferenceChange(blackOrWhite, blackOrWhite.getValue());
}
 
Example 17
Source File: Theme.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void draw() {
    Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, final Object newValue) {
            preference.setSummary(activity.getString(getThemeSummaryStringId((String) newValue)));
            return true;
        }
    };
    listener.onPreferenceChange(themePreference, themePreference.getValue());
    themePreference.setOnPreferenceChangeListener(listener);
}
 
Example 18
Source File: PreferenceFragment.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the app's theme, when the value of the
 * corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * Preference.OnPreferenceChangeListener}
 */
@NonNull
private Preference.OnPreferenceChangeListener createThemeChangeListener() {
    return new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            getActivity().recreate();
            return true;
        }

    };
}
 
Example 19
Source File: SettingsFragment.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);

   // Load the preferences from an XML resource
   addPreferencesFromResource(R.xml.preferences);

   // setup listener to be used by all EditTextPreferences
   Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {
      @Override
      public boolean onPreferenceChange(Preference preference, Object newValue) {
         Boolean rtnval = true;

         // don't touch non string preferences and just return true
         if (!(newValue instanceof String)) {
            return true;
         }

         String value = (String)newValue;
         if (value.contains(" ")) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(preference.getTitle() + " validation error");
            builder.setMessage("Should not contain space(s); edit was canceled");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.show();
            rtnval = false;
         }
         return rtnval;
      }
   };

   getPreferenceScreen().findPreference(RCDevice.ParameterKeys.SIGNALING_USERNAME).setOnPreferenceChangeListener(listener);
   getPreferenceScreen().findPreference(RCDevice.ParameterKeys.SIGNALING_DOMAIN).setOnPreferenceChangeListener(listener);

   /*
   pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

      @Override
      public boolean onPreferenceChange(Preference preference, Object newValue) {
         Boolean rtnval = true;

         // don't touch non string preferences and just return true
         if (!(newValue instanceof String)) {
            return true;
         }

         String value = (String)newValue;
         if (value.startsWith(" ") || value.endsWith(" ")) {
            //value = value.trim();
            final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle("Validation Error");
            builder.setMessage("String preference should not start or end with space. Please edit it again");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.show();
            rtnval = false;
         }
         return rtnval;
      }
   });
   */
}
 
Example 20
Source File: InstallationMethod.java    From YalpStore with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void draw() {
    Preference.OnPreferenceChangeListener listener = new OnInstallationMethodChangeListener(activity);
    listener.onPreferenceChange(installationMethod, installationMethod.getValue());
    installationMethod.setOnPreferenceChangeListener(listener);
}