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

Commit 60a50d23 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille Committed by Automerger Merge Worker
Browse files

Merge "Check colors actually change for App Widget" into sc-dev am: d8b2952b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14519412

Change-Id: Iabd608e63232ebb888b509a8818670492ac6c4e3
parents e4084ac0 d8b2952b
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ public class AppWidgetHostView extends FrameLayout {
    static final int VIEW_MODE_ERROR = 2;
    static final int VIEW_MODE_DEFAULT = 3;

    // Set of valid colors resources.
    private static final int FIRST_RESOURCE_COLOR_ID = android.R.color.system_neutral1_0;
    private static final int LAST_RESOURCE_COLOR_ID = android.R.color.system_accent3_1000;

    // When we're inflating the initialLayout for a AppWidget, we only allow
    // views that are allowed in RemoteViews.
    private static final LayoutInflater.Filter INFLATER_FILTER =
@@ -97,6 +101,7 @@ public class AppWidgetHostView extends FrameLayout {
    private boolean mOnLightBackground;
    private SizeF mCurrentSize = null;
    private RemoteViews.ColorResources mColorResources = null;
    private SparseIntArray mColorMapping = null;
    // Stores the last remote views last inflated.
    private RemoteViews mLastInflatedRemoteViews = null;
    private long mLastInflatedRemoteViewsId = -1;
@@ -888,12 +893,29 @@ public class AppWidgetHostView extends FrameLayout {
     * {@link android.R.color#system_neutral1_500}.
     */
    public void setColorResources(@NonNull SparseIntArray colorMapping) {
        mColorResources = RemoteViews.ColorResources.create(mContext, colorMapping);
        if (mColorMapping != null && isSameColorMapping(mColorMapping, colorMapping)) {
            return;
        }
        mColorMapping = colorMapping.clone();
        mColorResources = RemoteViews.ColorResources.create(mContext, mColorMapping);
        mLayoutId = -1;
        mViewMode = VIEW_MODE_NOINIT;
        reapplyLastRemoteViews();
    }

    /** Check if, in the current context, the two color mappings are equivalent. */
    private boolean isSameColorMapping(SparseIntArray oldColors, SparseIntArray newColors) {
        if (oldColors.size() != newColors.size()) {
            return false;
        }
        for (int i = 0; i < oldColors.size(); i++) {
            if (oldColors.valueAt(i) != newColors.get(oldColors.keyAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * Reset the dynamically overloaded resources, reverting to the default values for
     * all the colors.
@@ -904,6 +926,7 @@ public class AppWidgetHostView extends FrameLayout {
    public void resetColorResources() {
        if (mColorResources != null) {
            mColorResources = null;
            mColorMapping = null;
            mLayoutId = -1;
            mViewMode = VIEW_MODE_NOINIT;
            reapplyLastRemoteViews();