diff options
author | Danesh M <daneshm90@gmail.com> | 2015-12-02 16:08:08 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2015-12-08 15:34:41 -0800 |
commit | 9e4ebaf5d1f746565f099269f9fb3674696bedbe (patch) | |
tree | 341736ec505d6084581fae7134417cab5a0e8ff5 /src/com/android/settings/notification | |
parent | b5500240eb1f5685ce5ea22eb195a16b1832be76 (diff) | |
download | packages_apps_Settings-9e4ebaf5d1f746565f099269f9fb3674696bedbe.zip packages_apps_Settings-9e4ebaf5d1f746565f099269f9fb3674696bedbe.tar.gz packages_apps_Settings-9e4ebaf5d1f746565f099269f9fb3674696bedbe.tar.bz2 |
Settings : Port over reorganization from 12.1
Change-Id: I3d77bb96aba4a501d3223e72be60403694828a34
Diffstat (limited to 'src/com/android/settings/notification')
-rw-r--r-- | src/com/android/settings/notification/NotificationManagerSettings.java | 136 | ||||
-rw-r--r-- | src/com/android/settings/notification/SoundSettings.java (renamed from src/com/android/settings/notification/NotificationSettings.java) | 151 | ||||
-rw-r--r-- | src/com/android/settings/notification/VolumeSeekBarPreference.java | 8 |
3 files changed, 169 insertions, 126 deletions
diff --git a/src/com/android/settings/notification/NotificationManagerSettings.java b/src/com/android/settings/notification/NotificationManagerSettings.java new file mode 100644 index 0000000..d25d186 --- /dev/null +++ b/src/com/android/settings/notification/NotificationManagerSettings.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2015 The CyanogenMod project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.notification; + +import android.content.Context; +import android.os.Bundle; +import android.os.UserHandle; +import android.preference.PreferenceCategory; +import android.provider.SearchIndexableResource; +import android.provider.Settings; +import android.util.Log; + +import com.android.internal.logging.MetricsLogger; +import com.android.internal.widget.LockPatternUtils; +import com.android.settings.DropDownPreference; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; + +import java.util.ArrayList; +import java.util.List; + +public class NotificationManagerSettings extends SettingsPreferenceFragment + implements Indexable { + + private static final String TAG = NotificationManagerSettings.class.getSimpleName(); + + private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications"; + + private boolean mSecure; + private int mLockscreenSelectedValue; + private DropDownPreference mLockscreen; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + addPreferencesFromResource(R.xml.notification_manager_settings); + mSecure = new LockPatternUtils(getActivity()).isSecure(UserHandle.myUserId()); + initLockscreenNotifications(); + } + + // === Lockscreen (public / private) notifications === + + private void initLockscreenNotifications() { + mLockscreen = (DropDownPreference) findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS); + if (mLockscreen == null) { + Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS); + return; + } + + mLockscreen.addItem(R.string.lock_screen_notifications_summary_show, + R.string.lock_screen_notifications_summary_show); + if (mSecure) { + mLockscreen.addItem(R.string.lock_screen_notifications_summary_hide, + R.string.lock_screen_notifications_summary_hide); + } + mLockscreen.addItem(R.string.lock_screen_notifications_summary_disable, + R.string.lock_screen_notifications_summary_disable); + updateLockscreenNotifications(); + mLockscreen.setCallback(new DropDownPreference.Callback() { + @Override + public boolean onItemSelected(int pos, Object value) { + final int val = (Integer) value; + if (val == mLockscreenSelectedValue) { + return true; + } + 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; + } + }); + } + + private void updateLockscreenNotifications() { + if (mLockscreen == null) { + return; + } + final boolean enabled = getLockscreenNotificationsEnabled(); + final boolean allowPrivate = !mSecure || getLockscreenAllowPrivateNotifications(); + mLockscreenSelectedValue = !enabled ? R.string.lock_screen_notifications_summary_disable : + allowPrivate ? R.string.lock_screen_notifications_summary_show : + R.string.lock_screen_notifications_summary_hide; + mLockscreen.setSelectedValue(mLockscreenSelectedValue); + } + + private boolean getLockscreenNotificationsEnabled() { + return Settings.Secure.getInt(getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; + } + + private boolean getLockscreenAllowPrivateNotifications() { + return Settings.Secure.getInt(getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; + } + + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, + boolean enabled) { + ArrayList<SearchIndexableResource> result = + new ArrayList<SearchIndexableResource>(); + + SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.notification_manager_settings; + result.add(sir); + + return result; + } + }; + + @Override + protected int getMetricsCategory() { + return MetricsLogger.DONT_TRACK_ME_BRO; + } +} diff --git a/src/com/android/settings/notification/NotificationSettings.java b/src/com/android/settings/notification/SoundSettings.java index df4305d..f265bd3 100644 --- a/src/com/android/settings/notification/NotificationSettings.java +++ b/src/com/android/settings/notification/SoundSettings.java @@ -44,6 +44,7 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceCategory; import android.preference.SeekBarVolumizer; +import android.preference.SwitchPreference; import android.preference.TwoStatePreference; import android.provider.MediaStore; import android.provider.OpenableColumns; @@ -57,6 +58,7 @@ import com.android.settings.DropDownPreference; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.Utils; +import com.android.settings.hardware.VibratorIntensity; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import cyanogenmod.providers.CMSettings; @@ -66,10 +68,12 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -public class NotificationSettings extends SettingsPreferenceFragment implements Indexable { - private static final String TAG = "NotificationSettings"; +public class SoundSettings extends SettingsPreferenceFragment implements Indexable { + private static final String TAG = SoundSettings.class.getSimpleName(); - private static final String KEY_SOUND = "sound"; + private static final String KEY_SOUND = "sounds"; + private static final String KEY_VOLUMES = "volumes"; + private static final String KEY_VIBRATE = "vibrate"; private static final String KEY_MEDIA_VOLUME = "media_volume"; private static final String KEY_ALARM_VOLUME = "alarm_volume"; private static final String KEY_RING_VOLUME = "ring_volume"; @@ -80,11 +84,9 @@ public class NotificationSettings extends SettingsPreferenceFragment implements private static final String KEY_WIFI_DISPLAY = "wifi_display"; private static final String KEY_NOTIFICATION = "notification"; private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; - private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications"; private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access"; private static final String KEY_INCREASING_RING_VOLUME = "increasing_ring_volume"; - private static final String KEY_NOTIFICATION_LIGHT = "notification_light"; - private static final String KEY_BATTERY_LIGHT = "battery_light"; + private static final String KEY_VIBRATION_INTENSITY = "vibration_intensity"; private static final String KEY_ZEN_ACCESS = "manage_zen_access"; private static final String KEY_ZEN_MODE = "zen_mode"; @@ -125,8 +127,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements private Preference mPhoneRingtonePreference; private Preference mNotificationRingtonePreference; private TwoStatePreference mVibrateWhenRinging; - private TwoStatePreference mNotificationPulse; - private DropDownPreference mLockscreen; private Preference mNotificationAccess; private Preference mZenAccess; private boolean mSecure; @@ -148,7 +148,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements mPM = mContext.getPackageManager(); mUserManager = UserManager.get(getContext()); mVoiceCapable = Utils.isVoiceCapable(mContext); - mSecure = new LockPatternUtils(getActivity()).isSecure(UserHandle.myUserId()); mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); @@ -156,9 +155,11 @@ public class NotificationSettings extends SettingsPreferenceFragment implements mVibrator = null; } - addPreferencesFromResource(R.xml.notification_settings); + addPreferencesFromResource(R.xml.sounds); - final PreferenceCategory sound = (PreferenceCategory) findPreference(KEY_SOUND); + final PreferenceCategory volumes = (PreferenceCategory) findPreference(KEY_VOLUMES); + final PreferenceCategory sounds = (PreferenceCategory) findPreference(KEY_SOUND); + final PreferenceCategory vibrate = (PreferenceCategory) findPreference(KEY_VIBRATE); initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC, com.android.internal.R.drawable.ic_audio_media_mute); initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM, @@ -167,21 +168,21 @@ public class NotificationSettings extends SettingsPreferenceFragment implements mRingOrNotificationPreference = initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING, com.android.internal.R.drawable.ic_audio_ring_notif_mute); - sound.removePreference(sound.findPreference(KEY_NOTIFICATION_VOLUME)); + volumes.removePreference(volumes.findPreference(KEY_NOTIFICATION_VOLUME)); } else { mRingOrNotificationPreference = initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION, com.android.internal.R.drawable.ic_audio_ring_notif_mute); - sound.removePreference(sound.findPreference(KEY_RING_VOLUME)); + volumes.removePreference(volumes.findPreference(KEY_RING_VOLUME)); } - initRingtones(sound); - initVibrateWhenRinging(sound); - initIncreasingRing(sound); - final PreferenceCategory notification = (PreferenceCategory) - findPreference(KEY_NOTIFICATION); - initPulse(notification); - initLockscreenNotifications(notification); + if (!VibratorIntensity.isSupported(mContext)) { + removePreference(KEY_VIBRATION_INTENSITY); + } + + initRingtones(sounds); + initIncreasingRing(sounds); + initVibrateWhenRinging(vibrate); mNotificationAccess = findPreference(KEY_NOTIFICATION_ACCESS); refreshNotificationListeners(); @@ -225,6 +226,7 @@ public class NotificationSettings extends SettingsPreferenceFragment implements private VolumeSeekBarPreference initVolumePreference(String key, int stream, int muteIcon) { final VolumeSeekBarPreference volumePref = (VolumeSeekBarPreference) findPreference(key); + if (volumePref == null) return null; volumePref.setCallback(mVolumeCallback); volumePref.setStream(stream); mVolumePrefs.add(volumePref); @@ -397,7 +399,7 @@ public class NotificationSettings extends SettingsPreferenceFragment implements mIncreasingRingVolume = (IncreasingRingVolumePreference) root.findPreference(KEY_INCREASING_RING_VOLUME); - if (mIncreasingRing == null || mIncreasingRingVolume == null || !mVoiceCapable) { + if (!mVoiceCapable) { if (mIncreasingRing != null) { root.removePreference(mIncreasingRing); mIncreasingRing = null; @@ -407,7 +409,9 @@ public class NotificationSettings extends SettingsPreferenceFragment implements mIncreasingRingVolume = null; } } else { - mIncreasingRingVolume.setCallback(mIncreasingRingVolumeCallback); + if (mIncreasingRingVolume != null) { + mIncreasingRingVolume.setCallback(mIncreasingRingVolumeCallback); + } } } @@ -443,79 +447,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements Settings.System.VIBRATE_WHEN_RINGING, 0) != 0); } - // === Pulse notification light === - - private void initPulse(PreferenceCategory parent) { - if (!getResources().getBoolean( - com.android.internal.R.bool.config_intrusiveNotificationLed)) { - parent.removePreference(parent.findPreference(KEY_NOTIFICATION_LIGHT)); - } - if (!getResources().getBoolean( - com.android.internal.R.bool.config_intrusiveBatteryLed) - || UserHandle.myUserId() != UserHandle.USER_OWNER) { - parent.removePreference(parent.findPreference(KEY_BATTERY_LIGHT)); - } - } - - private void updatePulse() { - if (mNotificationPulse == null) { - return; - } - try { - mNotificationPulse.setChecked(Settings.System.getInt(getContentResolver(), - Settings.System.NOTIFICATION_LIGHT_PULSE) == 1); - } catch (Settings.SettingNotFoundException snfe) { - Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found"); - } - } - - // === Lockscreen (public / private) notifications === - - private void initLockscreenNotifications(PreferenceCategory parent) { - mLockscreen = (DropDownPreference) parent.findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS); - if (mLockscreen == null) { - Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS); - return; - } - - boolean isSecureNotificationsDisabled = isSecureNotificationsDisabled(); - boolean isUnredactedNotificationsDisabled = isUnredactedNotificationsDisabled(); - if (!isSecureNotificationsDisabled && !isUnredactedNotificationsDisabled) { - mLockscreen.addItem(R.string.lock_screen_notifications_summary_show, - R.string.lock_screen_notifications_summary_show); - } - if (mSecure && !isSecureNotificationsDisabled) { - mLockscreen.addItem(R.string.lock_screen_notifications_summary_hide, - R.string.lock_screen_notifications_summary_hide); - } - mLockscreen.addItem(R.string.lock_screen_notifications_summary_disable, - R.string.lock_screen_notifications_summary_disable); - updateLockscreenNotifications(); - if (mLockscreen.getItemCount() > 1) { - mLockscreen.setCallback(new DropDownPreference.Callback() { - @Override - public boolean onItemSelected(int pos, Object value) { - final int val = (Integer) value; - if (val == mLockscreenSelectedValue) { - return true; - } - 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); - } - } - private boolean isSecureNotificationsDisabled() { final DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); @@ -530,28 +461,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements & DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) != 0; } - private void updateLockscreenNotifications() { - if (mLockscreen == null) { - return; - } - final boolean enabled = getLockscreenNotificationsEnabled(); - final boolean allowPrivate = !mSecure || getLockscreenAllowPrivateNotifications(); - mLockscreenSelectedValue = !enabled ? R.string.lock_screen_notifications_summary_disable : - allowPrivate ? R.string.lock_screen_notifications_summary_show : - R.string.lock_screen_notifications_summary_hide; - mLockscreen.setSelectedValue(mLockscreenSelectedValue); - } - - private boolean getLockscreenNotificationsEnabled() { - return Settings.Secure.getInt(getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; - } - - private boolean getLockscreenAllowPrivateNotifications() { - return Settings.Secure.getInt(getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; - } - // === Notification listeners === private void refreshNotificationListeners() { @@ -608,12 +517,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements if (VIBRATE_WHEN_RINGING_URI.equals(uri)) { updateVibrateWhenRinging(); } - if (NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) { - updatePulse(); - } - if (LOCK_SCREEN_PRIVATE_URI.equals(uri) || LOCK_SCREEN_SHOW_URI.equals(uri)) { - updateLockscreenNotifications(); - } } } @@ -685,7 +588,7 @@ public class NotificationSettings extends SettingsPreferenceFragment implements public List<SearchIndexableResource> getXmlResourcesToIndex( Context context, boolean enabled) { final SearchIndexableResource sir = new SearchIndexableResource(context); - sir.xmlResId = R.xml.notification_settings; + sir.xmlResId = R.xml.sounds; return Arrays.asList(sir); } diff --git a/src/com/android/settings/notification/VolumeSeekBarPreference.java b/src/com/android/settings/notification/VolumeSeekBarPreference.java index cb2fa90..49bd815 100644 --- a/src/com/android/settings/notification/VolumeSeekBarPreference.java +++ b/src/com/android/settings/notification/VolumeSeekBarPreference.java @@ -138,7 +138,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference mVolumizer.start(); mVolumizer.setSeekBar(mSeekBar); updateIconView(); - mCallback.onStreamValueChanged(mStream, mSeekBar.getProgress()); + if (mCallback != null) { + mCallback.onStreamValueChanged(mStream, mSeekBar.getProgress()); + } updateSuppressionText(); if (!isEnabled()) { mSeekBar.setEnabled(false); @@ -150,7 +152,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { super.onProgressChanged(seekBar, progress, fromTouch); - mCallback.onStreamValueChanged(mStream, progress); + if (mCallback != null) { + mCallback.onStreamValueChanged(mStream, progress); + } } private void updateIconView() { |