Search in sources :

Example 6 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project AndroidSDK-RecipeBook by gabu.

the class MyPreferenceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref);
    mContext = this;
    Resources r = getResources();
    mInputPasswordKey = r.getString(R.string.input_password_key);
    mRealPasswordKey = r.getString(R.string.real_password_key);
    // パスワード入力用のプリファレンスを取得
    Preference password = findPreference(mInputPasswordKey);
    // 変更を検知するリスナーをセット
    password.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // 本来のパスワードには空文字をセット
            ((EditTextPreference) preference).setText("");
            // SharedPreferencesを取得
            SharedPreferences sp;
            sp = PreferenceManager.getDefaultSharedPreferences(mContext);
            // 編集のためEditorを取得
            Editor editor = sp.edit();
            // key: real_password_key
            // value: SHA-1値
            // newValueに入力された値が入っています。
            editor.putString(mRealPasswordKey, sha256(newValue.toString()));
            // 保存
            editor.commit();
            return false;
        }
    });
}
Also used : EditTextPreference(android.preference.EditTextPreference) Preference(android.preference.Preference) SharedPreferences(android.content.SharedPreferences) Resources(android.content.res.Resources) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) Editor(android.content.SharedPreferences.Editor)

Example 7 with OnPreferenceChangeListener

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

the class DoNotTrackPreference method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.do_not_track_preferences);
    getActivity().setTitle(R.string.do_not_track_title);
    ChromeSwitchPreference doNotTrackSwitch = (ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);
    boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
    doNotTrackSwitch.setChecked(isDoNotTrackEnabled);
    doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
            return true;
        }
    });
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 8 with OnPreferenceChangeListener

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

the class SavePasswordsPreferences method createAutoSignInCheckbox.

private void createAutoSignInCheckbox() {
    if (!ChromeFeatureList.isEnabled(CREDENTIAL_MANAGER_API)) {
        return;
    }
    mAutoSignInSwitch = new ChromeBaseCheckBoxPreference(getActivity(), null);
    mAutoSignInSwitch.setKey(PREF_AUTOSIGNIN_SWITCH);
    mAutoSignInSwitch.setTitle(R.string.passwords_auto_signin_title);
    mAutoSignInSwitch.setOrder(ORDER_AUTO_SIGNIN_CHECKBOX);
    mAutoSignInSwitch.setSummary(R.string.passwords_auto_signin_description);
    mAutoSignInSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

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

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isPasswordManagerAutoSigninManaged();
        }
    });
    getPreferenceScreen().addPreference(mAutoSignInSwitch);
    mAutoSignInSwitch.setChecked(PrefServiceBridge.getInstance().isPasswordManagerAutoSigninEnabled());
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) 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) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 9 with OnPreferenceChangeListener

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

the class DataReductionPreferences method createDataReductionSwitch.

private void createDataReductionSwitch(boolean isEnabled) {
    final ChromeSwitchPreference dataReductionSwitch = new ChromeSwitchPreference(getActivity(), null);
    dataReductionSwitch.setKey(PREF_DATA_REDUCTION_SWITCH);
    dataReductionSwitch.setSummaryOn(R.string.text_on);
    dataReductionSwitch.setSummaryOff(R.string.text_off);
    dataReductionSwitch.setDrawDivider(true);
    dataReductionSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(dataReductionSwitch.getContext(), (boolean) newValue);
            DataReductionPreferences.this.updatePreferences((boolean) newValue);
            return true;
        }
    });
    dataReductionSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return CommandLine.getInstance().hasSwitch(ENABLE_DATA_REDUCTION_PROXY) || DataReductionProxySettings.getInstance().isDataReductionProxyManaged();
        }
    });
    getPreferenceScreen().addPreference(dataReductionSwitch);
    // 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 data reduction is really turned off), so
    // .setChecked() should be called after .addPreference()
    dataReductionSwitch.setChecked(isEnabled);
}
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 10 with OnPreferenceChangeListener

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

the class SyncCustomizationFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mProfileSyncService = ProfileSyncService.get();
    assert mProfileSyncService != null;
    mIsBackendInitialized = mProfileSyncService.isBackendInitialized();
    mIsPassphraseRequired = mIsBackendInitialized && mProfileSyncService.isPassphraseRequiredForDecryption();
    getActivity().setTitle(R.string.sign_in_sync);
    View view = super.onCreateView(inflater, container, savedInstanceState);
    addPreferencesFromResource(R.xml.sync_customization_preferences);
    mSyncEverything = (SwitchPreference) findPreference(PREFERENCE_SYNC_EVERYTHING);
    mSyncAutofill = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_AUTOFILL);
    mSyncBookmarks = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_BOOKMARKS);
    mSyncOmnibox = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_OMNIBOX);
    mSyncPasswords = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_PASSWORDS);
    mSyncRecentTabs = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_RECENT_TABS);
    mSyncSettings = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_SETTINGS);
    mPaymentsIntegration = (CheckBoxPreference) findPreference(PREFERENCE_PAYMENTS_INTEGRATION);
    mSyncEncryption = findPreference(PREFERENCE_ENCRYPTION);
    mSyncEncryption.setOnPreferenceClickListener(this);
    mManageSyncData = findPreference(PREFERENCE_SYNC_MANAGE_DATA);
    mManageSyncData.setOnPreferenceClickListener(this);
    mSyncErrorCard = findPreference(PREFERENCE_SYNC_ERROR_CARD);
    mSyncErrorCard.setOnPreferenceClickListener(this);
    mAllTypes = new CheckBoxPreference[] { mSyncAutofill, mSyncBookmarks, mSyncOmnibox, mSyncPasswords, mSyncRecentTabs, mSyncSettings, mPaymentsIntegration };
    mSyncEverything.setOnPreferenceChangeListener(this);
    for (CheckBoxPreference type : mAllTypes) {
        type.setOnPreferenceChangeListener(this);
    }
    mSyncSwitchPreference = (ChromeSwitchPreference) findPreference(PREF_SYNC_SWITCH);
    mSyncSwitchPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            assert canDisableSync();
            if ((boolean) newValue) {
                mProfileSyncService.requestStart();
            } else {
                stopSync();
            }
            // Must be done asynchronously because the switch state isn't updated
            // until after this function exits.
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    updateSyncStateFromSwitch();
                }
            });
            return true;
        }
    });
    mSyncedAccountPreference = (SyncedAccountPreference) findPreference(PREFERENCE_SYNC_ACCOUNT_LIST);
    mSyncedAccountPreference.setOnPreferenceChangeListener(new SyncAccountSwitcher(getActivity(), mSyncedAccountPreference));
    return view;
}
Also used : SyncAccountSwitcher(org.chromium.chrome.browser.sync.SyncAccountSwitcher) CheckBoxPreference(android.preference.CheckBoxPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) SyncedAccountPreference(org.chromium.chrome.browser.preferences.SyncedAccountPreference) SwitchPreference(android.preference.SwitchPreference) Handler(android.os.Handler) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View)

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