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());
}
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();
}
});
}
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!"
*/
}
Aggregations