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;
}
});
}
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;
}
});
}
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());
}
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);
}
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;
}
Aggregations