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

Commit 8b63d6a9 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Use the new ColorResources.createWithOverlay API

When overriding colors, use the new createWithOverlay method if available

Bug: 413669302
Flag: android.content.res.self_targeting_android_resource_frro
Test: Verified that widget colors get updated properly on preview
(see bug for video)

Change-Id: I6c47e5523aee76e5762d2c930cb8c1b2a8cbcf09
parent 16e34e9b
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.appwidget;

import static android.appwidget.flags.Flags.FLAG_ENGAGEMENT_METRICS;
import static android.appwidget.flags.Flags.engagementMetrics;
import static android.content.res.Flags.selfTargetingAndroidResourceFrro;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
@@ -961,17 +962,23 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW
     *
     * Calling this method will trigger a full re-inflation of the App Widget.
     *
     * The color resources that can be overloaded are the ones whose name is prefixed with
     * {@code system_neutral} or {@code system_accent}, for example
     * {@link android.R.color#system_neutral1_500}.
     * If flag {@code android.content.res.self_targeting_android_resource_frro} is set, any colors
     * in {@code colorMapping} will be overloaded, otherwise the color resources that can
     * be overloaded are the ones whose name is prefixed with {@code system_neutral} or
     * {@code system_accent}, for example {@link android.R.color#system_neutral1_500}.
     */
    public void setColorResources(@NonNull SparseIntArray colorMapping) {
        if (mColorResources != null
                && isSameColorMapping(mColorResources.getColorMapping(), colorMapping)) {
            return;
        }
        if (selfTargetingAndroidResourceFrro()) {
            setColorResources(
                    RemoteViews.ColorResources.createWithOverlay(mContext, colorMapping));
        } else {
            setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping));
        }
    }

    private void setColorResourcesStates(RemoteViews.ColorResources colorResources) {
        mColorResources = colorResources;