use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingPref method init.
public Preference init(SettingsPreferenceFragment settings) {
final Context context = settings.getActivity();
Preference p = settings.getPreferenceScreen().findPreference(mKey);
if (p != null && !isApplicable(context)) {
settings.getPreferenceScreen().removePreference(p);
p = null;
}
if (p instanceof TwoStatePreference) {
mTwoState = (TwoStatePreference) p;
} else if (p instanceof DropDownPreference) {
mDropDown = (DropDownPreference) p;
CharSequence[] entries = new CharSequence[mValues.length];
CharSequence[] values = new CharSequence[mValues.length];
for (int i = 0; i < mValues.length; i++) {
entries[i] = getCaption(context.getResources(), mValues[i]);
values[i] = Integer.toString(mValues[i]);
}
mDropDown.setEntries(entries);
mDropDown.setEntryValues(values);
}
update(context);
if (mTwoState != null) {
p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setSetting(context, (Boolean) newValue ? 1 : 0);
return true;
}
});
return mTwoState;
}
if (mDropDown != null) {
p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return setSetting(context, Integer.parseInt((String) newValue));
}
});
return mDropDown;
}
return null;
}
use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DisplaySettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = getActivity();
final ContentResolver resolver = activity.getContentResolver();
addPreferencesFromResource(R.xml.display_settings);
PreferenceCategory displayPrefs = (PreferenceCategory) findPreference(KEY_CATEGORY_DISPLAY);
mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER);
if (mScreenSaverPreference != null && getResources().getBoolean(com.android.internal.R.bool.config_dreamsSupported) == false) {
getPreferenceScreen().removePreference(mScreenSaverPreference);
}
mScreenTimeoutPreference = (TimeoutListPreference) findPreference(KEY_SCREEN_TIMEOUT);
if (displayPrefs != null) {
mAutoBrightnessPreference = (SwitchPreference) findPreference(KEY_AUTO_BRIGHTNESS);
if (mAutoBrightnessPreference != null) {
if (isAutomaticBrightnessAvailable(getResources())) {
mAutoBrightnessPreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mAutoBrightnessPreference);
}
}
if (!NightDisplayController.isAvailable(activity)) {
removePreference(KEY_NIGHT_DISPLAY);
}
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
if (mLiftToWakePreference != null) {
if (isLiftToWakeAvailable(activity)) {
mLiftToWakePreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mLiftToWakePreference);
}
}
mTapToWakePreference = (SwitchPreference) findPreference(KEY_TAP_TO_WAKE);
if (mTapToWakePreference != null) {
if (isTapToWakeAvailable(getResources())) {
mTapToWakePreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mTapToWakePreference);
}
}
mCameraGesturePreference = (SwitchPreference) findPreference(KEY_CAMERA_GESTURE);
if (mCameraGesturePreference != null) {
if (isCameraGestureAvailable(getResources())) {
mCameraGesturePreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mCameraGesturePreference);
}
}
DropDownPreference rotatePreference = (DropDownPreference) findPreference(KEY_AUTO_ROTATE);
if (rotatePreference != null) {
if (RotationPolicy.isRotationLockToggleVisible(activity)) {
int rotateLockedResourceId;
// rotation), then we use a different string to include this information.
if (allowAllRotations(activity)) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
} else {
if (RotationPolicy.getRotationLockOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_portrait;
} else {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_landscape;
}
}
rotatePreference.setEntries(new CharSequence[] { activity.getString(R.string.display_auto_rotate_rotate), activity.getString(rotateLockedResourceId) });
rotatePreference.setEntryValues(new CharSequence[] { "0", "1" });
rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(activity) ? 1 : 0);
rotatePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean locked = Integer.parseInt((String) newValue) != 0;
MetricsLogger.action(getActivity(), MetricsEvent.ACTION_ROTATION_LOCK, locked);
RotationPolicy.setRotationLock(activity, locked);
return true;
}
});
} else {
displayPrefs.removePreference(rotatePreference);
}
}
DropDownPreference vrDisplayPref = (DropDownPreference) findPreference(KEY_VR_DISPLAY_PREF);
if (vrDisplayPref != null) {
if (isVrDisplayModeAvailable(activity)) {
vrDisplayPref.setEntries(new CharSequence[] { activity.getString(R.string.display_vr_pref_low_persistence), activity.getString(R.string.display_vr_pref_off) });
vrDisplayPref.setEntryValues(new CharSequence[] { "0", "1" });
final Context c = activity;
int currentUser = ActivityManager.getCurrentUser();
int current = Settings.Secure.getIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, /*default*/
Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE, currentUser);
vrDisplayPref.setValueIndex(current);
vrDisplayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int i = Integer.parseInt((String) newValue);
int u = ActivityManager.getCurrentUser();
if (!Settings.Secure.putIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, i, u)) {
Log.e(TAG, "Could not change setting for " + Settings.Secure.VR_DISPLAY_MODE);
}
return true;
}
});
} else {
displayPrefs.removePreference(vrDisplayPref);
}
}
}
mNightModePreference = (ListPreference) findPreference(KEY_NIGHT_MODE);
if (mNightModePreference != null) {
final UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
final int currentNightMode = uiManager.getNightMode();
mNightModePreference.setValue(String.valueOf(currentNightMode));
mNightModePreference.setOnPreferenceChangeListener(this);
}
}
use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppLaunchSettings method buildStateDropDown.
private void buildStateDropDown() {
if (mIsBrowser) {
// Browsers don't show the app-link prefs
mAppLinkState.setShouldDisableView(true);
mAppLinkState.setEnabled(false);
mAppDomainUrls.setShouldDisableView(true);
mAppDomainUrls.setEnabled(false);
} else {
// Designed order of states in the dropdown:
//
// * always
// * ask
// * never
mAppLinkState.setEntries(new CharSequence[] { getString(R.string.app_link_open_always), getString(R.string.app_link_open_ask), getString(R.string.app_link_open_never) });
mAppLinkState.setEntryValues(new CharSequence[] { Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS), Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK), Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER) });
mAppLinkState.setEnabled(mHasDomainUrls);
if (mHasDomainUrls) {
// Present 'undefined' as 'ask' because the OS treats them identically for
// purposes of the UI (and does the right thing around pending domain
// verifications that might arrive after the user chooses 'ask' in this UI).
final int state = mPm.getIntentVerificationStatusAsUser(mPackageName, UserHandle.myUserId());
mAppLinkState.setValue(Integer.toString((state == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) ? INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK : state));
// Set the callback only after setting the initial selected item
mAppLinkState.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return updateAppLinkState(Integer.parseInt((String) newValue));
}
});
}
}
}
use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ScreenPinningSettings method updateDisplay.
public void updateDisplay() {
PreferenceScreen root = getPreferenceScreen();
if (root != null) {
root.removeAll();
}
if (isLockToAppEnabled(getActivity())) {
addPreferencesFromResource(R.xml.screen_pinning_settings);
root = getPreferenceScreen();
mUseScreenLock = (SwitchPreference) root.findPreference(KEY_USE_SCREEN_LOCK);
mUseScreenLock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return setScreenLockUsed((boolean) newValue);
}
});
mUseScreenLock.setChecked(isScreenLockUsed());
mUseScreenLock.setTitle(getCurrentSecurityTitle());
}
}
use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ZenModeRuleSettingsBase method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mContext = getActivity();
final Intent intent = getActivity().getIntent();
if (DEBUG)
Log.d(TAG, "onCreate getIntent()=" + intent);
if (intent == null) {
Log.w(TAG, "No intent");
toastAndFinish();
return;
}
mId = intent.getStringExtra(ConditionProviderService.EXTRA_RULE_ID);
if (DEBUG)
Log.d(TAG, "mId=" + mId);
if (refreshRuleOrFinish()) {
return;
}
setHasOptionsMenu(true);
onCreateInternal();
final PreferenceScreen root = getPreferenceScreen();
mRuleName = root.findPreference(KEY_RULE_NAME);
mRuleName.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showRuleNameDialog();
return true;
}
});
mZenMode = (DropDownPreference) root.findPreference(KEY_ZEN_MODE);
mZenMode.setEntries(new CharSequence[] { getString(R.string.zen_mode_option_important_interruptions), getString(R.string.zen_mode_option_alarms), getString(R.string.zen_mode_option_no_interruptions) });
mZenMode.setEntryValues(new CharSequence[] { Integer.toString(NotificationManager.INTERRUPTION_FILTER_PRIORITY), Integer.toString(NotificationManager.INTERRUPTION_FILTER_ALARMS), Integer.toString(NotificationManager.INTERRUPTION_FILTER_NONE) });
mZenMode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return false;
final int zenMode = Integer.parseInt((String) newValue);
if (zenMode == mRule.getInterruptionFilter())
return false;
if (DEBUG)
Log.d(TAG, "onPrefChange zenMode=" + zenMode);
mRule.setInterruptionFilter(zenMode);
setZenRule(mId, mRule);
return true;
}
});
// sort at the bottom of the category
mZenMode.setOrder(10);
mZenMode.setDependency(getZenModeDependency());
}
Aggregations