From 18cb6feee443cb95dce8fd1e067a424c9113a8a7 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Tue, 12 Feb 2019 15:39:46 -0800 Subject: [PATCH] Set default background color for home icon. - the previous change to update the adaptive home page icon has removed the default background color for the icon. Set it back to the correct default if we do not find any background color set from the tile. Fixes: 124183074 Test: make RunSettingsRoboTests Change-Id: Idafc08ff1a3b20659c5f275d1a6c404f6c7ef2c0 --- .../settings/widget/AdaptiveHomepageIcon.java | 2 ++ .../settings/widget/AdaptiveHomepageIconTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/com/android/settings/widget/AdaptiveHomepageIcon.java b/src/com/android/settings/widget/AdaptiveHomepageIcon.java index bec5d8da2c6..bc7aaa7f22e 100644 --- a/src/com/android/settings/widget/AdaptiveHomepageIcon.java +++ b/src/com/android/settings/widget/AdaptiveHomepageIcon.java @@ -72,11 +72,13 @@ public class AdaptiveHomepageIcon extends LayerDrawable { // If found anything, use it. if (bgColor != 0) { setBackgroundColor(bgColor); + return; } } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Failed to set background color for " + tile.getPackageName()); } + setBackgroundColor(context.getColor(R.color.homepage_generic_icon_background)); } public void setBackgroundColor(int color) { diff --git a/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java b/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java index 32690a3d6aa..594ea36c803 100644 --- a/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java +++ b/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java @@ -96,6 +96,20 @@ public class AdaptiveHomepageIconTest { assertThat(icon.mBackgroundColor).isEqualTo(0xff0000); } + @Test + public void setBackgroundColor_tileWithoutBackgroundColor_shouldSetDefaultBackgroundColor() { + final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE)); + doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings)) + .when(tile).getIcon(mContext); + final AdaptiveHomepageIcon icon = + new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK)); + + icon.setBackgroundColor(mContext, tile); + + assertThat(icon.mBackgroundColor).isEqualTo( + mContext.getColor(R.color.homepage_generic_icon_background)); + } + @Test public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() { final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));