Force externally injected tiles to use rounded icon.

Bug: 110405144
Change-Id: Ic65200fce5010ea8077254e7a67bbe4dae886ec3
Fixes: 79748104
Test: robotests
This commit is contained in:
Fan Zhang
2018-08-10 15:37:41 -07:00
parent 7d5a9eebb8
commit fde4f207ff
8 changed files with 116 additions and 99 deletions

View File

@@ -18,25 +18,31 @@ package com.android.settings.widget;
import static androidx.annotation.VisibleForTesting.NONE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.util.Log;
import com.android.settings.R;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settingslib.drawer.Tile;
public class RoundedHomepageIcon extends LayerDrawable {
private static final String TAG = "RoundedHomepageIcon";
@VisibleForTesting(otherwise = NONE)
public int mBackgroundColor = -1;
int mBackgroundColor = -1;
public RoundedHomepageIcon(Context context, Drawable foreground) {
super(new Drawable[] {
super(new Drawable[]{
context.getDrawable(R.drawable.ic_homepage_generic_background),
foreground
});
@@ -45,6 +51,33 @@ public class RoundedHomepageIcon extends LayerDrawable {
setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
}
public void setBackgroundColor(Context context, Tile tile) {
final Bundle metaData = tile.getMetaData();
try {
if (metaData != null) {
// Load from bg.argb first
int bgColor = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
0 /* default */);
// Not found, load from bg.hint
if (bgColor == 0) {
final int colorRes = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
0 /* default */);
if (colorRes != 0) {
bgColor = context.getPackageManager()
.getResourcesForApplication(tile.getPackageName())
.getColor(colorRes, null /* theme */);
}
}
// If found anything, use it.
if (bgColor != 0) {
setBackgroundColor(bgColor);
}
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to set background color for " + tile.getPackageName());
}
}
public void setBackgroundColor(int color) {
mBackgroundColor = color;
getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);