Tint dashboard items coming from external tiles

So they can match the Settings theme.

Bug: 20449897
Change-Id: I33ad0d78dad6fbc9dae35552246a559b6508deaf
This commit is contained in:
Jason Monk
2015-04-21 13:26:36 -04:00
parent f62f1db70f
commit 47d16e9bf6

View File

@@ -22,11 +22,13 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -174,8 +176,16 @@ public class DashboardSummary extends InstrumentedFragment {
if (!TextUtils.isEmpty(tile.iconPkg)) {
try {
tileIcon.setImageDrawable(context.getPackageManager()
.getResourcesForApplication(tile.iconPkg).getDrawable(tile.iconRes, null));
Drawable drawable = context.getPackageManager()
.getResourcesForApplication(tile.iconPkg).getDrawable(tile.iconRes, null);
if (!tile.iconPkg.equals(context.getPackageName()) && drawable != null) {
// If this drawable is coming from outside Settings, tint it to match the color.
TypedValue tintColor = new TypedValue();
context.getTheme().resolveAttribute(com.android.internal.R.attr.colorAccent,
tintColor, true);
drawable.setTint(tintColor.data);
}
tileIcon.setImageDrawable(drawable);
} catch (NameNotFoundException | Resources.NotFoundException e) {
tileIcon.setImageDrawable(null);
tileIcon.setBackground(null);