Search in sources :

Example 21 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project AndroidChromium by JackyAndroid.

the class SavePasswordsPreferences method createSavePasswordsSwitch.

private void createSavePasswordsSwitch() {
    mSavePasswordsSwitch = new ChromeSwitchPreference(getActivity(), null);
    mSavePasswordsSwitch.setKey(PREF_SAVE_PASSWORDS_SWITCH);
    mSavePasswordsSwitch.setTitle(R.string.prefs_saved_passwords);
    mSavePasswordsSwitch.setOrder(ORDER_SWITCH);
    mSavePasswordsSwitch.setSummaryOn(R.string.text_on);
    mSavePasswordsSwitch.setSummaryOff(R.string.text_off);
    mSavePasswordsSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setRememberPasswordsEnabled((boolean) newValue);
            return true;
        }
    });
    mSavePasswordsSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isRememberPasswordsManaged();
        }
    });
    getPreferenceScreen().addPreference(mSavePasswordsSwitch);
    // Note: setting the switch state before the preference is added to the screen results in
    // some odd behavior where the switch state doesn't always match the internal enabled state
    // (e.g. the switch will say "On" when save passwords is really turned off), so
    // .setChecked() should be called after .addPreference()
    mSavePasswordsSwitch.setChecked(PrefServiceBridge.getInstance().isRememberPasswordsEnabled());
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 22 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project AndroidChromium by JackyAndroid.

the class ContextualSearchPreferenceFragment method initContextualSearchSwitch.

private void initContextualSearchSwitch() {
    ChromeSwitchPreference contextualSearchSwitch = (ChromeSwitchPreference) findPreference(PREF_CONTEXTUAL_SEARCH_SWITCH);
    boolean isContextualSearchEnabled = !PrefServiceBridge.getInstance().isContextualSearchDisabled();
    contextualSearchSwitch.setChecked(isContextualSearchEnabled);
    contextualSearchSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setContextualSearchState((boolean) newValue);
            ContextualSearchUma.logPreferenceChange((boolean) newValue);
            return true;
        }
    });
    contextualSearchSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isContextualSearchDisabledByPolicy();
        }
    });
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 23 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project Roundr by MohammadAdib.

the class SettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    /**
		 * Handle Preference Changes
		 */
    // Enable/Disable
    ((Preference) findPreference("enable")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isChecked = (Boolean) newValue;
            if (isChecked) {
                StandOutWindow.show(SettingsActivity.this, Corner.class, 0);
                StandOutWindow.show(SettingsActivity.this, Corner.class, 1);
                StandOutWindow.show(SettingsActivity.this, Corner.class, 2);
                StandOutWindow.show(SettingsActivity.this, Corner.class, 3);
            } else {
                StandOutWindow.closeAll(SettingsActivity.this, Corner.class);
            }
            return true;
        }
    });
    // Notification
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 16) {
        ((Preference) findPreference("notification")).setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                new AlertDialog.Builder(SettingsActivity.this).setTitle("Notification").setMessage("The notification prevents Android from killing RoundR in low memory situations.\n\nOn Android 4.1+ devices, it can be disabled via the App Info.").setPositiveButton("Continue", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        showInstalledAppDetails("mohammad.adib.roundr");
                    }
                }).show();
                return true;
            }
        });
    } else {
        ((Preference) findPreference("notification")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                StandOutWindow.sendData(SettingsActivity.this, Corner.class, Corner.wildcard, Corner.NOTIFICATION_CODE, new Bundle(), Corner.class, StandOutWindow.DISREGARD_ID);
                return true;
            }
        });
    }
    // Enable specific corners
    for (int i = 0; i < 4; i++) {
        ((Preference) findPreference("corner" + i)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                refresh();
                return true;
            }
        });
    }
    /**
		 * Overlap Settings TODO: These are messy
		 */
    ((Preference) findPreference("overlap1")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isChecked = (Boolean) newValue;
            if (isChecked) {
                prefs.edit().putInt("type", LayoutParams.TYPE_SYSTEM_OVERLAY).commit();
                if (prefs.getBoolean("overlap2", false))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED).commit();
            } else {
                prefs.edit().putInt("type", LayoutParams.TYPE_SYSTEM_ALERT).commit();
                if (prefs.getBoolean("overlap2", false))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL).commit();
            }
            new Thread(new Runnable() {

                @Override
                public void run() {
                    // Disable and Re-enable the corners
                    StandOutWindow.closeAll(SettingsActivity.this, Corner.class);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 0);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 1);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 2);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 3);
                }
            }).start();
            return true;
        }
    });
    ((Preference) findPreference("overlap2")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isChecked = (Boolean) newValue;
            if (isChecked) {
                if (prefs.getBoolean("overlap", true))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | LayoutParams.FLAG_LAYOUT_IN_SCREEN).commit();
            } else {
                if (prefs.getBoolean("overlap", true))
                    prefs.edit().putInt("flags", LayoutParams.FLAG_SHOW_WHEN_LOCKED).commit();
                else
                    prefs.edit().putInt("flags", LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH).commit();
            }
            new Thread(new Runnable() {

                @Override
                public void run() {
                    // Disable and Reenable the corners
                    StandOutWindow.closeAll(SettingsActivity.this, Corner.class);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 0);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 1);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 2);
                    StandOutWindow.show(SettingsActivity.this, Corner.class, 3);
                }
            }).start();
            return true;
        }
    });
/**
		 * TODO: Figure out if Developer Options is enabled. If so, show a
		 * GitHub Source Code Link preference:
		 * "Seems like you are a developer? Check out the RoundR source code on GitHub!"
		 */
}
Also used : AlertDialog(android.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) SuppressLint(android.annotation.SuppressLint) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) Preference(android.preference.Preference)

Aggregations

Preference (android.preference.Preference)23 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)10 CheckBoxPreference (android.preference.CheckBoxPreference)7 EditTextPreference (android.preference.EditTextPreference)7 SharedPreferences (android.content.SharedPreferences)6 ListPreference (android.preference.ListPreference)6 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)6 ManagedPreferenceDelegate (org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate)6 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 AlertDialog (android.app.AlertDialog)2 Intent (android.content.Intent)2 Editor (android.content.SharedPreferences.Editor)2 Resources (android.content.res.Resources)2 Uri (android.net.Uri)2 Map (java.util.Map)2 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)2 ChromeBaseCheckBoxPreference (org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference)2 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)2