Loading core/java/android/appwidget/AppWidgetHostView.java +24 −1 Original line number Diff line number Diff line Loading @@ -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 = Loading @@ -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; Loading Loading @@ -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. Loading @@ -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(); Loading Loading
core/java/android/appwidget/AppWidgetHostView.java +24 −1 Original line number Diff line number Diff line Loading @@ -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 = Loading @@ -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; Loading Loading @@ -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. Loading @@ -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(); Loading