diff --git a/res/drawable/ic_modes_time.xml b/res/drawable/ic_modes_time.xml deleted file mode 100644 index dff3c43933d..00000000000 --- a/res/drawable/ic_modes_time.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_bedtime.xml b/res/drawable/ic_zen_mode_type_bedtime.xml new file mode 100644 index 00000000000..7428a71b262 --- /dev/null +++ b/res/drawable/ic_zen_mode_type_bedtime.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_driving.xml b/res/drawable/ic_zen_mode_type_driving.xml new file mode 100644 index 00000000000..3cc0066c46b --- /dev/null +++ b/res/drawable/ic_zen_mode_type_driving.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_immersive.xml b/res/drawable/ic_zen_mode_type_immersive.xml new file mode 100644 index 00000000000..70913579b62 --- /dev/null +++ b/res/drawable/ic_zen_mode_type_immersive.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_managed.xml b/res/drawable/ic_zen_mode_type_managed.xml new file mode 100644 index 00000000000..5e224ebbf72 --- /dev/null +++ b/res/drawable/ic_zen_mode_type_managed.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_other.xml b/res/drawable/ic_zen_mode_type_other.xml new file mode 100644 index 00000000000..d236b0d7202 --- /dev/null +++ b/res/drawable/ic_zen_mode_type_other.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/drawable/ic_modes_event.xml b/res/drawable/ic_zen_mode_type_schedule_calendar.xml similarity index 100% rename from res/drawable/ic_modes_event.xml rename to res/drawable/ic_zen_mode_type_schedule_calendar.xml diff --git a/res/drawable/ic_zen_mode_type_schedule_time.xml b/res/drawable/ic_zen_mode_type_schedule_time.xml new file mode 100644 index 00000000000..57d596a98f6 --- /dev/null +++ b/res/drawable/ic_zen_mode_type_schedule_time.xml @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_theater.xml b/res/drawable/ic_zen_mode_type_theater.xml new file mode 100644 index 00000000000..cc66b32391a --- /dev/null +++ b/res/drawable/ic_zen_mode_type_theater.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_unknown.xml b/res/drawable/ic_zen_mode_type_unknown.xml new file mode 100644 index 00000000000..c1afd44ecfc --- /dev/null +++ b/res/drawable/ic_zen_mode_type_unknown.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/src/com/android/settings/notification/modes/IconLoader.java b/src/com/android/settings/notification/modes/IconLoader.java index b7a6c9526ac..8a02093633e 100644 --- a/src/com/android/settings/notification/modes/IconLoader.java +++ b/src/com/android/settings/notification/modes/IconLoader.java @@ -56,47 +56,42 @@ class IconLoader { @Nullable // Until first usage private static IconLoader sInstance; - private final Context mContext; private final LruCache mCache; private final ListeningExecutorService mBackgroundExecutor; - static IconLoader getInstance(Context context) { + static IconLoader getInstance() { if (sInstance == null) { - sInstance = new IconLoader(context); + sInstance = new IconLoader(); } return sInstance; } - private IconLoader(Context context) { - this(context, Executors.newFixedThreadPool(4)); + private IconLoader() { + this(Executors.newFixedThreadPool(4)); } @VisibleForTesting - IconLoader(Context context, ExecutorService backgroundExecutor) { - mContext = context.getApplicationContext(); + IconLoader(ExecutorService backgroundExecutor) { mCache = new LruCache<>(50); mBackgroundExecutor = MoreExecutors.listeningDecorator(backgroundExecutor); } - Context getContext() { - return mContext; - } - @NonNull - ListenableFuture getIcon(@NonNull AutomaticZenRule rule) { + ListenableFuture getIcon(Context context, @NonNull AutomaticZenRule rule) { if (rule.getIconResId() == 0) { - return Futures.immediateFuture(getFallbackIcon(rule.getType())); + return Futures.immediateFuture(getFallbackIcon(context, rule.getType())); } - return FluentFuture.from(loadIcon(rule.getPackageName(), rule.getIconResId())) + return FluentFuture.from(loadIcon(context, rule.getPackageName(), rule.getIconResId())) .transform(icon -> - icon != null ? icon : getFallbackIcon(rule.getType()), + icon != null ? icon : getFallbackIcon(context, rule.getType()), MoreExecutors.directExecutor()); } @NonNull - private ListenableFuture loadIcon(String pkg, int iconResId) { + private ListenableFuture loadIcon(Context context, String pkg, + int iconResId) { String cacheKey = pkg + ":" + iconResId; synchronized (mCache) { Drawable cachedValue = mCache.get(cacheKey); @@ -107,9 +102,9 @@ class IconLoader { return FluentFuture.from(mBackgroundExecutor.submit(() -> { if (TextUtils.isEmpty(pkg) || SystemZenRules.PACKAGE_ANDROID.equals(pkg)) { - return mContext.getDrawable(iconResId); + return context.getDrawable(iconResId); } else { - Context appContext = mContext.createPackageContext(pkg, 0); + Context appContext = context.createPackageContext(pkg, 0); Drawable appDrawable = AppCompatResources.getDrawable(appContext, iconResId); return getMonochromeIconIfPresent(appDrawable); } @@ -126,21 +121,21 @@ class IconLoader { }, MoreExecutors.directExecutor()); } - private Drawable getFallbackIcon(int ruleType) { + private static Drawable getFallbackIcon(Context context, int ruleType) { int iconResIdFromType = switch (ruleType) { - // TODO: b/333528437 - continue replacing with proper default icons - case AutomaticZenRule.TYPE_UNKNOWN -> R.drawable.ic_do_not_disturb_on_24dp; - case AutomaticZenRule.TYPE_OTHER -> R.drawable.ic_do_not_disturb_on_24dp; - case AutomaticZenRule.TYPE_SCHEDULE_TIME -> R.drawable.ic_modes_time; - case AutomaticZenRule.TYPE_SCHEDULE_CALENDAR -> R.drawable.ic_modes_event; - case AutomaticZenRule.TYPE_BEDTIME -> R.drawable.ic_do_not_disturb_on_24dp; - case AutomaticZenRule.TYPE_DRIVING -> R.drawable.ic_do_not_disturb_on_24dp; - case AutomaticZenRule.TYPE_IMMERSIVE -> R.drawable.ic_do_not_disturb_on_24dp; - case AutomaticZenRule.TYPE_THEATER -> R.drawable.ic_do_not_disturb_on_24dp; - case AutomaticZenRule.TYPE_MANAGED -> R.drawable.ic_do_not_disturb_on_24dp; - default -> R.drawable.ic_do_not_disturb_on_24dp; + case AutomaticZenRule.TYPE_UNKNOWN -> R.drawable.ic_zen_mode_type_unknown; + case AutomaticZenRule.TYPE_OTHER -> R.drawable.ic_zen_mode_type_other; + case AutomaticZenRule.TYPE_SCHEDULE_TIME -> R.drawable.ic_zen_mode_type_schedule_time; + case AutomaticZenRule.TYPE_SCHEDULE_CALENDAR -> + R.drawable.ic_zen_mode_type_schedule_calendar; + case AutomaticZenRule.TYPE_BEDTIME -> R.drawable.ic_zen_mode_type_bedtime; + case AutomaticZenRule.TYPE_DRIVING -> R.drawable.ic_zen_mode_type_driving; + case AutomaticZenRule.TYPE_IMMERSIVE -> R.drawable.ic_zen_mode_type_immersive; + case AutomaticZenRule.TYPE_THEATER -> R.drawable.ic_zen_mode_type_theater; + case AutomaticZenRule.TYPE_MANAGED -> R.drawable.ic_zen_mode_type_managed; + default -> R.drawable.ic_zen_mode_type_unknown; }; - return requireNonNull(mContext.getDrawable(iconResIdFromType)); + return requireNonNull(context.getDrawable(iconResIdFromType)); } private static Drawable getMonochromeIconIfPresent(Drawable icon) { diff --git a/src/com/android/settings/notification/modes/ZenMode.java b/src/com/android/settings/notification/modes/ZenMode.java index 058799b6225..1be7e5fda1e 100644 --- a/src/com/android/settings/notification/modes/ZenMode.java +++ b/src/com/android/settings/notification/modes/ZenMode.java @@ -118,14 +118,14 @@ class ZenMode { } @NonNull - public ListenableFuture getIcon(@NonNull IconLoader iconLoader) { - Context context = iconLoader.getContext(); + public ListenableFuture getIcon(@NonNull Context context, + @NonNull IconLoader iconLoader) { if (mIsManualDnd) { return Futures.immediateFuture(requireNonNull( context.getDrawable(R.drawable.ic_do_not_disturb_on_24dp))); } - return iconLoader.getIcon(mRule); + return iconLoader.getIcon(context, mRule); } @NonNull diff --git a/src/com/android/settings/notification/modes/ZenModeHeaderController.java b/src/com/android/settings/notification/modes/ZenModeHeaderController.java index fc20710ab78..ba6e9d9a22e 100644 --- a/src/com/android/settings/notification/modes/ZenModeHeaderController.java +++ b/src/com/android/settings/notification/modes/ZenModeHeaderController.java @@ -62,7 +62,7 @@ class ZenModeHeaderController extends AbstractZenModePreferenceController { } FutureUtil.whenDone( - zenMode.getIcon(IconLoader.getInstance(mContext)), + zenMode.getIcon(mContext, IconLoader.getInstance()), icon -> mHeaderController.setIcon(icon) .setLabel(zenMode.getRule().getName()) .done(false /* rebindActions */), diff --git a/src/com/android/settings/notification/modes/ZenModeListPreference.java b/src/com/android/settings/notification/modes/ZenModeListPreference.java index 0f4728f05de..c897d5b7f3e 100644 --- a/src/com/android/settings/notification/modes/ZenModeListPreference.java +++ b/src/com/android/settings/notification/modes/ZenModeListPreference.java @@ -24,6 +24,7 @@ import android.os.Bundle; import com.android.settings.core.SubSettingLauncher; import com.android.settings.notification.zen.ZenModeSettings; import com.android.settingslib.RestrictedPreference; +import com.android.settingslib.Utils; /** * Preference representing a single mode item on the modes aggregator page. Clicking on this @@ -64,10 +65,15 @@ class ZenModeListPreference extends RestrictedPreference { mZenMode = zenMode; setTitle(mZenMode.getRule().getName()); setSummary(mZenMode.getRule().getTriggerDescription()); + setIconSize(ICON_SIZE_SMALL); FutureUtil.whenDone( - mZenMode.getIcon(IconLoader.getInstance(mContext)), - icon -> setIcon(icon), + mZenMode.getIcon(mContext, IconLoader.getInstance()), + icon -> { + icon.setTintList( + Utils.getColorAttr(mContext, android.R.attr.colorControlNormal)); + setIcon(icon); + }, mContext.getMainExecutor()); } } diff --git a/tests/robotests/src/com/android/settings/notification/modes/IconLoaderTest.java b/tests/robotests/src/com/android/settings/notification/modes/IconLoaderTest.java index a92e6187aef..7d4a3679198 100644 --- a/tests/robotests/src/com/android/settings/notification/modes/IconLoaderTest.java +++ b/tests/robotests/src/com/android/settings/notification/modes/IconLoaderTest.java @@ -21,6 +21,7 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; import static com.google.common.truth.Truth.assertThat; import android.app.AutomaticZenRule; +import android.content.Context; import android.graphics.drawable.Drawable; import android.net.Uri; import android.service.notification.ZenPolicy; @@ -37,12 +38,13 @@ import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class IconLoaderTest { + private Context mContext; private IconLoader mLoader; @Before public void setUp() { - mLoader = new IconLoader(RuntimeEnvironment.application, - MoreExecutors.newDirectExecutorService()); + mContext = RuntimeEnvironment.application; + mLoader = new IconLoader(MoreExecutors.newDirectExecutorService()); } @Test @@ -52,7 +54,7 @@ public class IconLoaderTest { .setIconResId(android.R.drawable.ic_media_play) .build(); - ListenableFuture loadFuture = mLoader.getIcon(systemRule); + ListenableFuture loadFuture = mLoader.getIcon(mContext, systemRule); assertThat(loadFuture.isDone()).isTrue(); assertThat(loadFuture.get()).isNotNull(); } @@ -64,7 +66,7 @@ public class IconLoaderTest { .setPackage("com.blah") .build(); - ListenableFuture loadFuture = mLoader.getIcon(rule); + ListenableFuture loadFuture = mLoader.getIcon(mContext, rule); assertThat(loadFuture.isDone()).isTrue(); assertThat(loadFuture.get()).isNotNull(); } @@ -77,7 +79,7 @@ public class IconLoaderTest { .setIconResId(-123456) .build(); - ListenableFuture loadFuture = mLoader.getIcon(rule); + ListenableFuture loadFuture = mLoader.getIcon(mContext, rule); assertThat(loadFuture.get()).isNotNull(); }