Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d315d07a authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Add setting to turn off icon badging" into ub-launcher3-dorval

parents 8ffddbb7 2ab84828
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -172,6 +172,12 @@
    <string name="allow_rotation_desc">When phone is rotated</string>
    <!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] -->
    <string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string>
    <!-- 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] -->
    <string name="icon_badging_title">Icon badging</string>
    <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] -->
    <string name="icon_badging_desc_on">On for all apps</string>
    <!-- Text to indicate that the system icon badging setting is off [CHAR LIMIT=100] -->
    <string name="icon_badging_desc_off">Off for all apps</string>

    <!-- Label for the setting that allows the automatic placement of launcher shortcuts for applications and games installed on the device [CHAR LIMIT=40] -->
    <string name="auto_add_shortcuts_label">Add icon to Home screen</string>
+19 −7
Original line number Diff line number Diff line
@@ -16,13 +16,6 @@

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <SwitchPreference
            android:key="pref_allowRotation"
            android:title="@string/allow_rotation_title"
            android:defaultValue="@bool/allow_rotation"
            android:persistent="true"
    />

    <SwitchPreference
        android:key="pref_add_icon_to_home"
        android:title="@string/auto_add_shortcuts_label"
@@ -40,4 +33,23 @@
        android:defaultValue=""
        android:persistent="false" />

    <Preference
        android:key="pref_icon_badging"
        android:title="@string/icon_badging_title"
        android:persistent="false">
        <intent android:action="android.settings.NOTIFICATION_SETTINGS">
            <!-- This extra highlights the "Allow icon badges" field in Notification settings -->
            <extra
                android:name=":settings:fragment_args_key"
                android:value="notification_badging" />
        </intent>
    </Preference>/>

    <SwitchPreference
        android:key="pref_allowRotation"
        android:title="@string/allow_rotation_title"
        android:defaultValue="@bool/allow_rotation"
        android:persistent="true"
        />

</PreferenceScreen>
+46 −1
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ import com.android.launcher3.graphics.IconShapeOverride;
 * Settings activity for Launcher. Currently implements the following setting: Allow rotation
 */
public class SettingsActivity extends Activity {

    private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging";
    // TODO: use Settings.Secure.NOTIFICATION_BADGING
    private static final String NOTIFICATION_BADGING = "notification_badging";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -50,6 +55,7 @@ public class SettingsActivity extends Activity {
    public static class LauncherSettingsFragment extends PreferenceFragment {

        private SystemDisplayRotationLockObserver mRotationLockObserver;
        private IconBadgingObserver mIconBadgingObserver;

        @Override
        public void onCreate(Bundle savedInstanceState) {
@@ -57,13 +63,14 @@ public class SettingsActivity extends Activity {
            getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
            addPreferencesFromResource(R.xml.launcher_preferences);

            ContentResolver resolver = getActivity().getContentResolver();

            // Setup allow rotation preference
            Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
            if (getResources().getBoolean(R.bool.allow_rotation)) {
                // Launcher supports rotation by default. No need to show this setting.
                getPreferenceScreen().removePreference(rotationPref);
            } else {
                ContentResolver resolver = getActivity().getContentResolver();
                mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);

                // Register a content observer to listen for system setting changes while
@@ -77,9 +84,18 @@ public class SettingsActivity extends Activity {
                rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity()));
            }

            Preference iconBadgingPref = findPreference(ICON_BADGING_PREFERENCE_KEY);
            if (!BuildCompat.isAtLeastO()) {
                getPreferenceScreen().removePreference(
                        findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY));
                getPreferenceScreen().removePreference(iconBadgingPref);
            } else {
                // Listen to system notification badge settings while this UI is active.
                mIconBadgingObserver = new IconBadgingObserver(iconBadgingPref, resolver);
                resolver.registerContentObserver(
                        Settings.Secure.getUriFor(NOTIFICATION_BADGING),
                        false, mIconBadgingObserver);
                mIconBadgingObserver.onChange(true);
            }

            Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE);
@@ -98,6 +114,10 @@ public class SettingsActivity extends Activity {
                getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
                mRotationLockObserver = null;
            }
            if (mIconBadgingObserver != null) {
                getActivity().getContentResolver().unregisterContentObserver(mIconBadgingObserver);
                mIconBadgingObserver = null;
            }
            super.onDestroy();
        }
    }
@@ -127,4 +147,29 @@ public class SettingsActivity extends Activity {
                    ? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc);
        }
    }

    /**
     * Content observer which listens for system badging setting changes,
     * and updates the launcher badging setting subtext accordingly.
     */
    private static class IconBadgingObserver extends ContentObserver {

        private final Preference mBadgingPref;
        private final ContentResolver mResolver;

        public IconBadgingObserver(Preference badgingPref, ContentResolver resolver) {
            super(new Handler());
            mBadgingPref = badgingPref;
            mResolver = resolver;
        }

        @Override
        public void onChange(boolean selfChange) {
            boolean enabled = Settings.Secure.getInt(mResolver, NOTIFICATION_BADGING, 1) == 1;
            mBadgingPref.setSummary(enabled
                    ? R.string.icon_badging_desc_on
                    : R.string.icon_badging_desc_off);
        }
    }

}