Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9b4a688 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Treat icon color metadata as raw value instead of reference"

parents 27747685 58543721
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash

    @VisibleForTesting
    static final String STATE_CONDITION_EXPANDED = "condition_expanded";

    static final String META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB = "com.android.settings.bg.argb";
    private final IconCache mCache;
    private final Context mContext;
    private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -320,15 +320,25 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
        if (!TextUtils.equals(tileIcon.getResPackage(), mContext.getPackageName())
                && !(icon instanceof RoundedHomepageIcon)) {
            icon = new RoundedHomepageIcon(mContext, icon);
            try {
            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(
                            TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT, 0 /* default */);
                                TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
                                0 /* default */);
                        if (colorRes != 0) {
                        final int bgColor = mContext.getPackageManager()
                            bgColor = mContext.getPackageManager()
                                    .getResourcesForApplication(tileIcon.getResPackage())
                                    .getColor(colorRes, null /* theme */);
                        }
                    }
                    // If found anything, use it.
                    if (bgColor != 0) {
                        ((RoundedHomepageIcon) icon).setBackgroundColor(bgColor);
                    }
                }
+24 −0
Original line number Diff line number Diff line
@@ -241,6 +241,30 @@ public class DashboardAdapterTest {
                .isInstanceOf(RoundedHomepageIcon.class);
    }

    @Test
    public void onBindTile_externalTileWithBackgroundColorRawValue_shouldUpdateIcon() {
        final Context context = spy(RuntimeEnvironment.application);
        final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
        final DashboardAdapter.DashboardItemHolder holder =
                new DashboardAdapter.DashboardItemHolder(view);
        final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
        tile.getMetaData().putInt(DashboardAdapter.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
                0xff0000);
        doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
                .when(tile).getIcon(context);
        final IconCache iconCache = new IconCache(context);
        mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
                null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
        ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);

        doReturn("another.package").when(context).getPackageName();
        mDashboardAdapter.onBindTile(holder, tile);

        final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
                tile.getIcon(context));
        assertThat(homepageIcon.mBackgroundColor).isEqualTo(0xff0000);
    }

    @Test
    public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
        final Context context = spy(RuntimeEnvironment.application);