use of android.support.v7.preference.DropDownPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ZenModePrioritySettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.zen_mode_priority_settings);
final PreferenceScreen root = getPreferenceScreen();
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
mReminders = (SwitchPreference) root.findPreference(KEY_REMINDERS);
mReminders.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return true;
final boolean val = (Boolean) newValue;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REMINDERS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowReminders=" + val);
savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_REMINDERS), mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
mEvents = (SwitchPreference) root.findPreference(KEY_EVENTS);
mEvents.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return true;
final boolean val = (Boolean) newValue;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_EVENTS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowEvents=" + val);
savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_EVENTS), mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
mMessages = (DropDownPreference) root.findPreference(KEY_MESSAGES);
addSources(mMessages);
mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return false;
final int val = Integer.parseInt((String) newValue);
final boolean allowMessages = val != SOURCE_NONE;
final int allowMessagesFrom = val == SOURCE_NONE ? mPolicy.priorityMessageSenders : val;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_MESSAGES, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowMessages=" + allowMessages + " allowMessagesFrom=" + ZenModeConfig.sourceToString(allowMessagesFrom));
savePolicy(getNewPriorityCategories(allowMessages, Policy.PRIORITY_CATEGORY_MESSAGES), mPolicy.priorityCallSenders, allowMessagesFrom, mPolicy.suppressedVisualEffects);
return true;
}
});
mCalls = (DropDownPreference) root.findPreference(KEY_CALLS);
addSources(mCalls);
mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return false;
final int val = Integer.parseInt((String) newValue);
final boolean allowCalls = val != SOURCE_NONE;
final int allowCallsFrom = val == SOURCE_NONE ? mPolicy.priorityCallSenders : val;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_CALLS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowCalls=" + allowCalls + " allowCallsFrom=" + ZenModeConfig.sourceToString(allowCallsFrom));
savePolicy(getNewPriorityCategories(allowCalls, Policy.PRIORITY_CATEGORY_CALLS), allowCallsFrom, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
mRepeatCallers = (SwitchPreference) root.findPreference(KEY_REPEAT_CALLERS);
mRepeatCallers.setSummary(mContext.getString(R.string.zen_mode_repeat_callers_summary, mContext.getResources().getInteger(com.android.internal.R.integer.config_zen_repeat_callers_threshold)));
mRepeatCallers.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners)
return true;
final boolean val = (Boolean) newValue;
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REPEAT_CALLS, val);
if (DEBUG)
Log.d(TAG, "onPrefChange allowRepeatCallers=" + val);
int priorityCategories = getNewPriorityCategories(val, NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS);
savePolicy(priorityCategories, mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
updateControls();
}
use of android.support.v7.preference.DropDownPreference 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.DropDownPreference 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.DropDownPreference 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());
}
use of android.support.v7.preference.DropDownPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ZenModeEventRuleSettings method onCreateInternal.
@Override
protected void onCreateInternal() {
mCreate = true;
addPreferencesFromResource(R.xml.zen_mode_event_rule_settings);
final PreferenceScreen root = getPreferenceScreen();
mCalendar = (DropDownPreference) root.findPreference(KEY_CALENDAR);
mCalendar.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String calendarKey = (String) newValue;
if (calendarKey.equals(key(mEvent)))
return false;
final int i = calendarKey.indexOf(':');
mEvent.userId = Integer.parseInt(calendarKey.substring(0, i));
mEvent.calendar = calendarKey.substring(i + 1);
if (mEvent.calendar.isEmpty()) {
mEvent.calendar = null;
}
updateRule(ZenModeConfig.toEventConditionId(mEvent));
return true;
}
});
mReply = (DropDownPreference) root.findPreference(KEY_REPLY);
mReply.setEntries(new CharSequence[] { getString(R.string.zen_mode_event_rule_reply_any_except_no), getString(R.string.zen_mode_event_rule_reply_yes_or_maybe), getString(R.string.zen_mode_event_rule_reply_yes) });
mReply.setEntryValues(new CharSequence[] { Integer.toString(EventInfo.REPLY_ANY_EXCEPT_NO), Integer.toString(EventInfo.REPLY_YES_OR_MAYBE), Integer.toString(EventInfo.REPLY_YES) });
mReply.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final int reply = Integer.parseInt((String) newValue);
if (reply == mEvent.reply)
return false;
mEvent.reply = reply;
updateRule(ZenModeConfig.toEventConditionId(mEvent));
return true;
}
});
reloadCalendar();
updateControlsInternal();
}
Aggregations