Use adaptive icon shapes for settings homeepage
- Add AdaptiveIconShapeDrawable for the homepage icon backgrounds - Rename RoundedHomepageIcon -> AdaptiveHomepageIcon to reflect that the adaptive icon shape is used Bug: 123829919 Test: mp settings; manually viewing homepage icons Change-Id: I9fddfbf57461b300200f30f716d861878bbbcc38
This commit is contained in:
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_about_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_about_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_accessibility_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_accessibility_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_accounts_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_accounts_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_app_and_notification_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_app_and_notification_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_battery_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_battery_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_connected_device_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_connected_device_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_display_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_display_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2018 The Android Open Source 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.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_generic_icon_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_location_background"/>
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"/>
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_location_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_network_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_network_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_privacy_background"/>
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"/>
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_privacy_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_security_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_security_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_sound_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_sound_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_storage_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_storage_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_support_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_support_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -18,13 +18,10 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid
|
||||
android:color="@color/homepage_system_background" />
|
||||
<size
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size" />
|
||||
</shape>
|
||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/dashboard_tile_image_size"
|
||||
android:height="@dimen/dashboard_tile_image_size"
|
||||
android:color="@color/homepage_system_background" />
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
@@ -46,7 +46,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.RoundedHomepageIcon;
|
||||
import com.android.settings.widget.AdaptiveHomepageIcon;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
@@ -197,8 +197,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
Drawable iconDrawable = tileIcon.loadDrawable(preference.getContext());
|
||||
if (forceRoundedIcon
|
||||
&& !TextUtils.equals(mContext.getPackageName(), tile.getPackageName())) {
|
||||
iconDrawable = new RoundedHomepageIcon(mContext, iconDrawable);
|
||||
((RoundedHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
|
||||
iconDrawable = new AdaptiveHomepageIcon(mContext, iconDrawable);
|
||||
((AdaptiveHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
|
||||
}
|
||||
preference.setIcon(iconDrawable);
|
||||
} else if (tile.getMetaData() != null
|
||||
|
@@ -0,0 +1,43 @@
|
||||
package com.android.settings.homepage;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.PathShape;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.PathParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Draws a filled {@link ShapeDrawable} using the path from {@link AdaptiveIconDrawable}.
|
||||
*/
|
||||
public class AdaptiveIconShapeDrawable extends ShapeDrawable {
|
||||
public AdaptiveIconShapeDrawable() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AdaptiveIconShapeDrawable(Resources resources) {
|
||||
super();
|
||||
init(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
||||
throws XmlPullParserException, IOException {
|
||||
super.inflate(r, parser, attrs, theme);
|
||||
init(r);
|
||||
}
|
||||
|
||||
private void init(Resources resources) {
|
||||
final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
|
||||
final Path path = new Path(PathParser.createPathFromPathData(
|
||||
resources.getString(com.android.internal.R.string.config_icon_mask)));
|
||||
setShape(new PathShape(path, pathSize, pathSize));
|
||||
}
|
||||
}
|
@@ -32,18 +32,19 @@ import android.util.Log;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
public class RoundedHomepageIcon extends LayerDrawable {
|
||||
public class AdaptiveHomepageIcon extends LayerDrawable {
|
||||
|
||||
private static final String TAG = "RoundedHomepageIcon";
|
||||
private static final String TAG = "AdaptiveHomepageIcon";
|
||||
|
||||
@VisibleForTesting(otherwise = NONE)
|
||||
int mBackgroundColor = -1;
|
||||
|
||||
public RoundedHomepageIcon(Context context, Drawable foreground) {
|
||||
public AdaptiveHomepageIcon(Context context, Drawable foreground) {
|
||||
super(new Drawable[]{
|
||||
context.getDrawable(R.drawable.ic_homepage_generic_background),
|
||||
new AdaptiveIconShapeDrawable(context.getResources()),
|
||||
foreground
|
||||
});
|
||||
final int insetPx = context.getResources()
|
@@ -37,9 +37,9 @@ import android.graphics.drawable.ShapeDrawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.testutils.DrawableTestHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -48,7 +48,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class RoundedHomepageIconTest {
|
||||
public class AdaptiveHomepageIconTest {
|
||||
|
||||
private Context mContext;
|
||||
private ActivityInfo mActivityInfo;
|
||||
@@ -64,18 +64,17 @@ public class RoundedHomepageIconTest {
|
||||
|
||||
@Test
|
||||
public void createIcon_shouldSetBackgroundAndInset() {
|
||||
final RoundedHomepageIcon icon =
|
||||
new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
final AdaptiveHomepageIcon icon =
|
||||
new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
|
||||
assertThat(icon.getNumberOfLayers()).isEqualTo(2);
|
||||
DrawableTestHelper.assertDrawableResId(icon.getDrawable(0),
|
||||
R.drawable.ic_homepage_generic_background);
|
||||
assertThat(icon.getDrawable(0)).isInstanceOf(AdaptiveIconShapeDrawable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBackgroundColor_shouldUpdateColorFilter() {
|
||||
final RoundedHomepageIcon icon =
|
||||
spy(new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK)));
|
||||
final AdaptiveHomepageIcon icon =
|
||||
spy(new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK)));
|
||||
final ShapeDrawable background = mock(ShapeDrawable.class);
|
||||
when(icon.getDrawable(0)).thenReturn(background);
|
||||
|
||||
@@ -90,8 +89,8 @@ public class RoundedHomepageIconTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB, 0xff0000);
|
||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(mContext);
|
||||
final RoundedHomepageIcon icon =
|
||||
new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
final AdaptiveHomepageIcon icon =
|
||||
new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
|
||||
icon.setBackgroundColor(mContext, tile);
|
||||
assertThat(icon.mBackgroundColor).isEqualTo(0xff0000);
|
||||
@@ -105,8 +104,8 @@ public class RoundedHomepageIconTest {
|
||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(mContext);
|
||||
|
||||
final RoundedHomepageIcon icon =
|
||||
new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
final AdaptiveHomepageIcon icon =
|
||||
new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
icon.setBackgroundColor(mContext, tile);
|
||||
|
||||
assertThat(icon.mBackgroundColor)
|
Reference in New Issue
Block a user