Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-Launcher3: Commit

packages/apps/Launcher3


Commit MetaInfo

Revisión2ab8482809109c7c202e12bcef083cc3783e852e (tree)
Tiempo2017-05-17 06:08:42
AutorTony Wickham <twickham@goog...>
CommiterTony

Log Message

Add setting to turn off icon badging

Redirects to system Notifications setting page.

Bug: 36815147
Change-Id: I5ee542f94ed51a73a57df3a726384944ff3ee71d

Cambiar Resumen

Diferencia incremental

--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -172,6 +172,12 @@
172172 <string name="allow_rotation_desc">When phone is rotated</string>
173173 <!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] -->
174174 <string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string>
175+ <!-- Title for Icon Badging setting. Tapping this will link to the system Notifications Settings screen where the user can turn off badging globally. [CHAR LIMIT=50] -->
176+ <string name="icon_badging_title">Icon badging</string>
177+ <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] -->
178+ <string name="icon_badging_desc_on">On for all apps</string>
179+ <!-- Text to indicate that the system icon badging setting is off [CHAR LIMIT=100] -->
180+ <string name="icon_badging_desc_off">Off for all apps</string>
175181
176182 <!-- Label for the setting that allows the automatic placement of launcher shortcuts for applications and games installed on the device [CHAR LIMIT=40] -->
177183 <string name="auto_add_shortcuts_label">Add icon to Home screen</string>
--- a/res/xml/launcher_preferences.xml
+++ b/res/xml/launcher_preferences.xml
@@ -17,13 +17,6 @@
1717 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
1818
1919 <SwitchPreference
20- android:key="pref_allowRotation"
21- android:title="@string/allow_rotation_title"
22- android:defaultValue="@bool/allow_rotation"
23- android:persistent="true"
24- />
25-
26- <SwitchPreference
2720 android:key="pref_add_icon_to_home"
2821 android:title="@string/auto_add_shortcuts_label"
2922 android:summary="@string/auto_add_shortcuts_description"
@@ -40,4 +33,23 @@
4033 android:defaultValue=""
4134 android:persistent="false" />
4235
36+ <Preference
37+ android:key="pref_icon_badging"
38+ android:title="@string/icon_badging_title"
39+ android:persistent="false">
40+ <intent android:action="android.settings.NOTIFICATION_SETTINGS">
41+ <!-- This extra highlights the "Allow icon badges" field in Notification settings -->
42+ <extra
43+ android:name=":settings:fragment_args_key"
44+ android:value="notification_badging" />
45+ </intent>
46+ </Preference>/>
47+
48+ <SwitchPreference
49+ android:key="pref_allowRotation"
50+ android:title="@string/allow_rotation_title"
51+ android:defaultValue="@bool/allow_rotation"
52+ android:persistent="true"
53+ />
54+
4355 </PreferenceScreen>
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -34,6 +34,11 @@ import com.android.launcher3.graphics.IconShapeOverride;
3434 * Settings activity for Launcher. Currently implements the following setting: Allow rotation
3535 */
3636 public class SettingsActivity extends Activity {
37+
38+ private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging";
39+ // TODO: use Settings.Secure.NOTIFICATION_BADGING
40+ private static final String NOTIFICATION_BADGING = "notification_badging";
41+
3742 @Override
3843 protected void onCreate(Bundle savedInstanceState) {
3944 super.onCreate(savedInstanceState);
@@ -50,6 +55,7 @@ public class SettingsActivity extends Activity {
5055 public static class LauncherSettingsFragment extends PreferenceFragment {
5156
5257 private SystemDisplayRotationLockObserver mRotationLockObserver;
58+ private IconBadgingObserver mIconBadgingObserver;
5359
5460 @Override
5561 public void onCreate(Bundle savedInstanceState) {
@@ -57,13 +63,14 @@ public class SettingsActivity extends Activity {
5763 getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
5864 addPreferencesFromResource(R.xml.launcher_preferences);
5965
66+ ContentResolver resolver = getActivity().getContentResolver();
67+
6068 // Setup allow rotation preference
6169 Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
6270 if (getResources().getBoolean(R.bool.allow_rotation)) {
6371 // Launcher supports rotation by default. No need to show this setting.
6472 getPreferenceScreen().removePreference(rotationPref);
6573 } else {
66- ContentResolver resolver = getActivity().getContentResolver();
6774 mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);
6875
6976 // Register a content observer to listen for system setting changes while
@@ -77,9 +84,18 @@ public class SettingsActivity extends Activity {
7784 rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity()));
7885 }
7986
87+ Preference iconBadgingPref = findPreference(ICON_BADGING_PREFERENCE_KEY);
8088 if (!BuildCompat.isAtLeastO()) {
8189 getPreferenceScreen().removePreference(
8290 findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY));
91+ getPreferenceScreen().removePreference(iconBadgingPref);
92+ } else {
93+ // Listen to system notification badge settings while this UI is active.
94+ mIconBadgingObserver = new IconBadgingObserver(iconBadgingPref, resolver);
95+ resolver.registerContentObserver(
96+ Settings.Secure.getUriFor(NOTIFICATION_BADGING),
97+ false, mIconBadgingObserver);
98+ mIconBadgingObserver.onChange(true);
8399 }
84100
85101 Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE);
@@ -98,6 +114,10 @@ public class SettingsActivity extends Activity {
98114 getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
99115 mRotationLockObserver = null;
100116 }
117+ if (mIconBadgingObserver != null) {
118+ getActivity().getContentResolver().unregisterContentObserver(mIconBadgingObserver);
119+ mIconBadgingObserver = null;
120+ }
101121 super.onDestroy();
102122 }
103123 }
@@ -127,4 +147,29 @@ public class SettingsActivity extends Activity {
127147 ? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc);
128148 }
129149 }
150+
151+ /**
152+ * Content observer which listens for system badging setting changes,
153+ * and updates the launcher badging setting subtext accordingly.
154+ */
155+ private static class IconBadgingObserver extends ContentObserver {
156+
157+ private final Preference mBadgingPref;
158+ private final ContentResolver mResolver;
159+
160+ public IconBadgingObserver(Preference badgingPref, ContentResolver resolver) {
161+ super(new Handler());
162+ mBadgingPref = badgingPref;
163+ mResolver = resolver;
164+ }
165+
166+ @Override
167+ public void onChange(boolean selfChange) {
168+ boolean enabled = Settings.Secure.getInt(mResolver, NOTIFICATION_BADGING, 1) == 1;
169+ mBadgingPref.setSummary(enabled
170+ ? R.string.icon_badging_desc_on
171+ : R.string.icon_badging_desc_off);
172+ }
173+ }
174+
130175 }
Show on old repository browser