Search in sources :

Example 1 with OnPreferenceChangeListener

use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureNotificationSettings method initLockscreenNotificationsForProfile.

// === Lockscreen (public / private) notifications ===
private void initLockscreenNotificationsForProfile() {
    mLockscreenProfile = (RestrictedDropDownPreference) getPreferenceScreen().findPreference(KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
    if (mLockscreenProfile == null) {
        Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
        return;
    }
    ArrayList<CharSequence> entries = new ArrayList<>();
    ArrayList<CharSequence> values = new ArrayList<>();
    entries.add(getString(R.string.lock_screen_notifications_summary_disable_profile));
    values.add(Integer.toString(R.string.lock_screen_notifications_summary_disable_profile));
    String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show_profile);
    String summaryShowEntryValue = Integer.toString(R.string.lock_screen_notifications_summary_show_profile);
    entries.add(summaryShowEntry);
    values.add(summaryShowEntryValue);
    setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
    if (mSecureProfile) {
        String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide_profile);
        String summaryHideEntryValue = Integer.toString(R.string.lock_screen_notifications_summary_hide_profile);
        entries.add(summaryHideEntry);
        values.add(summaryHideEntryValue);
        setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
    }
    mLockscreenProfile.setOnPreClickListener((Preference p) -> Utils.startQuietModeDialogIfNecessary(mContext, UserManager.get(mContext), mProfileChallengeUserId));
    mLockscreenProfile.setEntries(entries.toArray(new CharSequence[entries.size()]));
    mLockscreenProfile.setEntryValues(values.toArray(new CharSequence[values.size()]));
    updateLockscreenNotificationsForProfile();
    if (mLockscreenProfile.getEntries().length > 1) {
        mLockscreenProfile.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final int val = Integer.parseInt((String) newValue);
                if (val == mLockscreenSelectedValueProfile) {
                    return false;
                }
                final boolean enabled = val != R.string.lock_screen_notifications_summary_disable_profile;
                final boolean show = val == R.string.lock_screen_notifications_summary_show_profile;
                Settings.Secure.putIntForUser(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0, mProfileChallengeUserId);
                Settings.Secure.putIntForUser(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0, mProfileChallengeUserId);
                mLockscreenSelectedValueProfile = val;
                return true;
            }
        });
    } else {
        // There is one or less option for the user, disable the drop down.
        mLockscreenProfile.setEnabled(false);
    }
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 2 with OnPreferenceChangeListener

use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureNotificationSettings method initLockscreenNotifications.

private void initLockscreenNotifications() {
    mLockscreen = (RestrictedDropDownPreference) getPreferenceScreen().findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
    if (mLockscreen == null) {
        Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS);
        return;
    }
    ArrayList<CharSequence> entries = new ArrayList<>();
    ArrayList<CharSequence> values = new ArrayList<>();
    entries.add(getString(R.string.lock_screen_notifications_summary_disable));
    values.add(Integer.toString(R.string.lock_screen_notifications_summary_disable));
    String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show);
    String summaryShowEntryValue = Integer.toString(R.string.lock_screen_notifications_summary_show);
    entries.add(summaryShowEntry);
    values.add(summaryShowEntryValue);
    setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
    if (mSecure) {
        String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
        String summaryHideEntryValue = Integer.toString(R.string.lock_screen_notifications_summary_hide);
        entries.add(summaryHideEntry);
        values.add(summaryHideEntryValue);
        setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
    }
    mLockscreen.setEntries(entries.toArray(new CharSequence[entries.size()]));
    mLockscreen.setEntryValues(values.toArray(new CharSequence[values.size()]));
    updateLockscreenNotifications();
    if (mLockscreen.getEntries().length > 1) {
        mLockscreen.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final int val = Integer.parseInt((String) newValue);
                if (val == mLockscreenSelectedValue) {
                    return false;
                }
                final boolean enabled = val != R.string.lock_screen_notifications_summary_disable;
                final boolean show = val == R.string.lock_screen_notifications_summary_show;
                Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
                Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
                mLockscreenSelectedValue = val;
                return true;
            }
        });
    } else {
        // There is one or less option for the user, disable the drop down.
        mLockscreen.setEnabled(false);
    }
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 3 with OnPreferenceChangeListener

use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ApplicationSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.application_settings);
    mToggleAdvancedSettings = (CheckBoxPreference) findPreference(KEY_TOGGLE_ADVANCED_SETTINGS);
    mToggleAdvancedSettings.setChecked(isAdvancedSettingsEnabled());
    getPreferenceScreen().removePreference(mToggleAdvancedSettings);
    // not ready for prime time yet
    if (false) {
        getPreferenceScreen().removePreference(mInstallLocation);
    }
    mInstallLocation = (ListPreference) findPreference(KEY_APP_INSTALL_LOCATION);
    // Is app default install location set?
    boolean userSetInstLocation = (Settings.Global.getInt(getContentResolver(), Settings.Global.SET_INSTALL_LOCATION, 0) != 0);
    if (!userSetInstLocation) {
        getPreferenceScreen().removePreference(mInstallLocation);
    } else {
        mInstallLocation.setValue(getAppInstallLocation());
        mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String value = (String) newValue;
                handleUpdateAppInstallLocation(value);
                return false;
            }
        });
    }
}
Also used : Preference(android.support.v7.preference.Preference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 4 with OnPreferenceChangeListener

use of android.support.v7.preference.Preference.OnPreferenceChangeListener 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();
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) DropDownPreference(android.support.v7.preference.DropDownPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 5 with OnPreferenceChangeListener

use of android.support.v7.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SoundSettings method initVibrateWhenRinging.

// === Vibrate when ringing ===
private void initVibrateWhenRinging() {
    mVibrateWhenRinging = (TwoStatePreference) getPreferenceScreen().findPreference(KEY_VIBRATE_WHEN_RINGING);
    if (mVibrateWhenRinging == null) {
        Log.i(TAG, "Preference not found: " + KEY_VIBRATE_WHEN_RINGING);
        return;
    }
    if (!mVoiceCapable) {
        getPreferenceScreen().removePreference(mVibrateWhenRinging);
        mVibrateWhenRinging = null;
        return;
    }
    mVibrateWhenRinging.setPersistent(false);
    updateVibrateWhenRinging();
    mVibrateWhenRinging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final boolean val = (Boolean) newValue;
            return Settings.System.putInt(getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, val ? 1 : 0);
        }
    });
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) RingtonePreference(com.android.settings.RingtonePreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Aggregations

Preference (android.support.v7.preference.Preference)16 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 PreferenceScreen (android.support.v7.preference.PreferenceScreen)7 SwitchPreference (android.support.v14.preference.SwitchPreference)6 DropDownPreference (android.support.v7.preference.DropDownPreference)6 TwoStatePreference (android.support.v7.preference.TwoStatePreference)5 ListPreference (android.support.v7.preference.ListPreference)3 PreferenceCategory (android.support.v7.preference.PreferenceCategory)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 Intent (android.content.Intent)2 PackageItemInfo (android.content.pm.PackageItemInfo)2 View (android.view.View)2 RestrictedPreference (com.android.settingslib.RestrictedPreference)2 Activity (android.app.Activity)1 NotificationManager (android.app.NotificationManager)1 UiModeManager (android.app.UiModeManager)1 ComponentName (android.content.ComponentName)1 ContentResolver (android.content.ContentResolver)1 ApplicationInfo (android.content.pm.ApplicationInfo)1