diff options
Diffstat (limited to 'src/com/android/settings/notification/AppNotificationSettings.java')
-rw-r--r-- | src/com/android/settings/notification/AppNotificationSettings.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index d54aced..2e76f92 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -27,6 +27,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.UserHandle; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; @@ -59,6 +60,9 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { private static final String KEY_PEEKABLE = "peekable"; private static final String KEY_SENSITIVE = "sensitive"; private static final String KEY_APP_SETTINGS = "app_settings"; + private static final String KEY_SHOW_ON_KEYGUARD = "show_on_keyguard"; + private static final String KEY_NO_ONGOING_ON_KEYGUARD = "no_ongoing_on_keyguard"; + private static final String KEY_SOUND_TIMEOUT = "sound_timeout"; private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT = new Intent(Intent.ACTION_MAIN) @@ -71,6 +75,9 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { private SwitchPreference mPriority; private SwitchPreference mPeekable; private SwitchPreference mSensitive; + private SwitchPreference mShowOnKeyguard; + private SwitchPreference mShowNoOngoingOnKeyguard; + private ListPreference mSoundTimeout; private AppRow mAppRow; private boolean mCreated; private boolean mIsSystemPackage; @@ -137,6 +144,9 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { mPriority = (SwitchPreference) findPreference(KEY_PRIORITY); mPeekable = (SwitchPreference) findPreference(KEY_PEEKABLE); mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE); + mShowOnKeyguard = (SwitchPreference) findPreference(KEY_SHOW_ON_KEYGUARD); + mShowNoOngoingOnKeyguard = (SwitchPreference) findPreference(KEY_NO_ONGOING_ON_KEYGUARD); + mSoundTimeout = (ListPreference) findPreference(KEY_SOUND_TIMEOUT); mAppRow = mBackend.loadAppRow(pm, info.applicationInfo); @@ -150,6 +160,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { mPriority.setChecked(mAppRow.priority); mPeekable.setChecked(mAppRow.peekable); mSensitive.setChecked(mAppRow.sensitive); + mSoundTimeout.setValue(Long.toString(mAppRow.soundTimeout)); + updateSoundTimeoutSummary(mAppRow.soundTimeout); mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override @@ -190,6 +202,18 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { } }); + mSoundTimeout.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + long value = Long.valueOf((String) newValue); + if (!mBackend.setNotificationSoundTimeout(pkg, mUid, value)) { + return false; + } + updateSoundTimeoutSummary(value); + return true; + } + }); + if (mAppRow.settingsIntent != null) { findPreference(KEY_APP_SETTINGS).setOnPreferenceClickListener( new OnPreferenceClickListener() { @@ -202,6 +226,47 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { } else { removePreference(KEY_APP_SETTINGS); } + + int keyguard = mBackend.getShowNotificationForPackageOnKeyguard(pkg, mUid); + mShowOnKeyguard.setChecked((keyguard & Notification.SHOW_ALL_NOTI_ON_KEYGUARD) != 0); + mShowNoOngoingOnKeyguard.setChecked( + (keyguard & Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD) != 0); + + mShowOnKeyguard.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean showOnKeyguard = (Boolean) newValue; + int keyguard = mBackend.getShowNotificationForPackageOnKeyguard(pkg, mUid); + + if (showOnKeyguard && (keyguard & Notification.SHOW_ALL_NOTI_ON_KEYGUARD) == 0) { + keyguard |= Notification.SHOW_ALL_NOTI_ON_KEYGUARD; + } else { + keyguard &= ~Notification.SHOW_ALL_NOTI_ON_KEYGUARD; + } + return mBackend.setShowNotificationForPackageOnKeyguard(pkg, mUid, keyguard); + } + }); + + mShowNoOngoingOnKeyguard.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean showNoOngoingOnKeyguard = (Boolean) newValue; + int keyguard = mBackend.getShowNotificationForPackageOnKeyguard(pkg, mUid); + if (showNoOngoingOnKeyguard + && (keyguard & Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD) == 0) { + keyguard |= Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD; + } else { + keyguard &= ~Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD; + } + return mBackend.setShowNotificationForPackageOnKeyguard(pkg, mUid, keyguard); + } + }); + + // Users cannot block notifications from system/signature packages + if (mIsSystemPackage || !getLockscreenNotificationsEnabled()) { + getPreferenceScreen().removePreference(mShowNoOngoingOnKeyguard); + getPreferenceScreen().removePreference(mShowOnKeyguard); + } } @Override @@ -213,6 +278,25 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { } } + private void updateSoundTimeoutSummary(long value) { + if (value == 0) { + mSoundTimeout.setSummary(R.string.app_notification_sound_timeout_value_none); + } else { + final CharSequence[] entries = mSoundTimeout.getEntries(); + final CharSequence[] values = mSoundTimeout.getEntryValues(); + CharSequence summary = null; + for (int i = 0; i < values.length; i++) { + long timeout = Long.parseLong(values[i].toString()); + if (timeout == value) { + summary = getString(R.string.app_notification_sound_timeout_summary_template, + entries[i]); + break; + } + } + mSoundTimeout.setSummary(summary); + } + } + private void updateDependents(boolean banned) { final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure( UserHandle.myUserId()); @@ -226,6 +310,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { setVisible(mPeekable, mIsSystemPackage || !banned && headsUpEnabled); setVisible(mSensitive, mIsSystemPackage || !banned && lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate); + setVisible(mShowOnKeyguard, mIsSystemPackage || !banned); + setVisible(mShowNoOngoingOnKeyguard, mIsSystemPackage || !banned); } private void setVisible(Preference p, boolean visible) { |