Loading core/java/android/appwidget/AppWidgetHostView.java +33 −3 Original line number Original line Diff line number Diff line Loading @@ -155,6 +155,22 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW mInteractionHandler = getHandler(handler); mInteractionHandler = getHandler(handler); } } /** * @hide */ public static class AdapterChildHostView extends AppWidgetHostView { public AdapterChildHostView(Context context) { super(context); } @Override public Context getRemoteContextEnsuringCorrectCachedApkPath() { // To reduce noise in error messages return null; } } /** /** * Set the AppWidget that will be displayed by this view. This method also adds default padding * Set the AppWidget that will be displayed by this view. This method also adds default padding * to widgets, as described in {@link #getDefaultPaddingForWidget(Context, ComponentName, Rect)} * to widgets, as described in {@link #getDefaultPaddingForWidget(Context, ComponentName, Rect)} Loading Loading @@ -921,17 +937,31 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping)); setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping)); } } private void setColorResourcesStates(RemoteViews.ColorResources colorResources) { mColorResources = colorResources; mColorMappingChanged = true; mViewMode = VIEW_MODE_NOINIT; } /** @hide **/ /** @hide **/ public void setColorResources(RemoteViews.ColorResources colorResources) { public void setColorResources(RemoteViews.ColorResources colorResources) { if (colorResources == mColorResources) { if (colorResources == mColorResources) { return; return; } } mColorResources = colorResources; setColorResourcesStates(colorResources); mColorMappingChanged = true; mViewMode = VIEW_MODE_NOINIT; reapplyLastRemoteViews(); reapplyLastRemoteViews(); } } /** * @hide */ public void setColorResourcesNoReapply(RemoteViews.ColorResources colorResources) { if (colorResources == mColorResources) { return; } setColorResourcesStates(colorResources); } /** Check if, in the current context, the two color mappings are equivalent. */ /** Check if, in the current context, the two color mappings are equivalent. */ private boolean isSameColorMapping(SparseIntArray oldColors, SparseIntArray newColors) { private boolean isSameColorMapping(SparseIntArray oldColors, SparseIntArray newColors) { if (oldColors.size() != newColors.size()) { if (oldColors.size() != newColors.size()) { Loading core/java/android/widget/RemoteCollectionItemsAdapter.java +9 −36 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.widget; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.appwidget.AppWidgetHostView; import android.util.SparseIntArray; import android.util.SparseIntArray; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; Loading @@ -25,8 +26,6 @@ import android.widget.RemoteViews.ColorResources; import android.widget.RemoteViews.InteractionHandler; import android.widget.RemoteViews.InteractionHandler; import android.widget.RemoteViews.RemoteCollectionItems; import android.widget.RemoteViews.RemoteCollectionItems; import com.android.internal.R; import java.util.stream.IntStream; import java.util.stream.IntStream; /** /** Loading Loading @@ -178,40 +177,14 @@ class RemoteCollectionItemsAdapter extends BaseAdapter { RemoteViews item = mItems.getItemView(position); RemoteViews item = mItems.getItemView(position); item.addFlags(RemoteViews.FLAG_WIDGET_IS_COLLECTION_CHILD); item.addFlags(RemoteViews.FLAG_WIDGET_IS_COLLECTION_CHILD); View reapplyView = getViewToReapply(convertView, item); // Reapply the RemoteViews if we can. if (reapplyView != null) { try { item.reapply( parent.getContext(), reapplyView, mInteractionHandler, null /* size */, mColorResources); return reapplyView; } catch (RuntimeException e) { // We can't reapply for some reason, we'll fallback to an apply and inflate a // new view. } } return item.apply( parent.getContext(), parent, mInteractionHandler, null /* size */, mColorResources); } /** Returns {@code convertView} if it can be used to reapply {@code item}, or null otherwise. */ @Nullable private static View getViewToReapply(@Nullable View convertView, @NonNull RemoteViews item) { if (convertView == null) return null; Object layoutIdTag = convertView.getTag(R.id.widget_frame); if (!(layoutIdTag instanceof Integer)) return null; return item.getLayoutId() == (Integer) layoutIdTag ? convertView : null; AppWidgetHostView newView = convertView instanceof AppWidgetHostView.AdapterChildHostView widgetChildView ? widgetChildView : new AppWidgetHostView.AdapterChildHostView(parent.getContext()); newView.setInteractionHandler(mInteractionHandler); newView.setColorResourcesNoReapply(mColorResources); newView.updateAppWidget(item); return newView; } } } } core/java/android/widget/RemoteViews.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -6958,13 +6958,13 @@ public class RemoteViews implements Parcelable, Filter { View parent = (View) view.getParent(); View parent = (View) view.getParent(); // Break the for loop on the first encounter of: // Break the for loop on the first encounter of: // 1) an AdapterView, // 1) an AdapterView, // 2) an AppWidgetHostView that is not a RemoteViewsFrameLayout, or // 2) an AppWidgetHostView that is not a child of an adapter view, or // 3) a null parent. // 3) a null parent. // 2) and 3) are unexpected and catch the case where a child is not // 2) and 3) are unexpected and catch the case where a child is not // correctly parented in an AdapterView. // correctly parented in an AdapterView. while (parent != null && !(parent instanceof AdapterView<?>) while (parent != null && !(parent instanceof AdapterView<?>) && !((parent instanceof AppWidgetHostView) && !((parent instanceof AppWidgetHostView) && !(parent instanceof RemoteViewsAdapter.RemoteViewsFrameLayout))) { && !(parent instanceof AppWidgetHostView.AdapterChildHostView))) { parent = (View) parent.getParent(); parent = (View) parent.getParent(); } } Loading core/java/android/widget/RemoteViewsAdapter.java +1 −6 Original line number Original line Diff line number Diff line Loading @@ -368,7 +368,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback * A FrameLayout which contains a loading view, and manages the re/applying of RemoteViews when * A FrameLayout which contains a loading view, and manages the re/applying of RemoteViews when * they are loaded. * they are loaded. */ */ static class RemoteViewsFrameLayout extends AppWidgetHostView { static class RemoteViewsFrameLayout extends AppWidgetHostView.AdapterChildHostView { private final FixedSizeRemoteViewsCache mCache; private final FixedSizeRemoteViewsCache mCache; public int cacheIndex = -1; public int cacheIndex = -1; Loading Loading @@ -407,11 +407,6 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback return loadingTextView; return loadingTextView; } } @Override protected Context getRemoteContextEnsuringCorrectCachedApkPath() { return null; } @Override @Override protected View getErrorView() { protected View getErrorView() { // Use the default loading view as the error view. // Use the default loading view as the error view. Loading Loading
core/java/android/appwidget/AppWidgetHostView.java +33 −3 Original line number Original line Diff line number Diff line Loading @@ -155,6 +155,22 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW mInteractionHandler = getHandler(handler); mInteractionHandler = getHandler(handler); } } /** * @hide */ public static class AdapterChildHostView extends AppWidgetHostView { public AdapterChildHostView(Context context) { super(context); } @Override public Context getRemoteContextEnsuringCorrectCachedApkPath() { // To reduce noise in error messages return null; } } /** /** * Set the AppWidget that will be displayed by this view. This method also adds default padding * Set the AppWidget that will be displayed by this view. This method also adds default padding * to widgets, as described in {@link #getDefaultPaddingForWidget(Context, ComponentName, Rect)} * to widgets, as described in {@link #getDefaultPaddingForWidget(Context, ComponentName, Rect)} Loading Loading @@ -921,17 +937,31 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping)); setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping)); } } private void setColorResourcesStates(RemoteViews.ColorResources colorResources) { mColorResources = colorResources; mColorMappingChanged = true; mViewMode = VIEW_MODE_NOINIT; } /** @hide **/ /** @hide **/ public void setColorResources(RemoteViews.ColorResources colorResources) { public void setColorResources(RemoteViews.ColorResources colorResources) { if (colorResources == mColorResources) { if (colorResources == mColorResources) { return; return; } } mColorResources = colorResources; setColorResourcesStates(colorResources); mColorMappingChanged = true; mViewMode = VIEW_MODE_NOINIT; reapplyLastRemoteViews(); reapplyLastRemoteViews(); } } /** * @hide */ public void setColorResourcesNoReapply(RemoteViews.ColorResources colorResources) { if (colorResources == mColorResources) { return; } setColorResourcesStates(colorResources); } /** Check if, in the current context, the two color mappings are equivalent. */ /** Check if, in the current context, the two color mappings are equivalent. */ private boolean isSameColorMapping(SparseIntArray oldColors, SparseIntArray newColors) { private boolean isSameColorMapping(SparseIntArray oldColors, SparseIntArray newColors) { if (oldColors.size() != newColors.size()) { if (oldColors.size() != newColors.size()) { Loading
core/java/android/widget/RemoteCollectionItemsAdapter.java +9 −36 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.widget; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.appwidget.AppWidgetHostView; import android.util.SparseIntArray; import android.util.SparseIntArray; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; Loading @@ -25,8 +26,6 @@ import android.widget.RemoteViews.ColorResources; import android.widget.RemoteViews.InteractionHandler; import android.widget.RemoteViews.InteractionHandler; import android.widget.RemoteViews.RemoteCollectionItems; import android.widget.RemoteViews.RemoteCollectionItems; import com.android.internal.R; import java.util.stream.IntStream; import java.util.stream.IntStream; /** /** Loading Loading @@ -178,40 +177,14 @@ class RemoteCollectionItemsAdapter extends BaseAdapter { RemoteViews item = mItems.getItemView(position); RemoteViews item = mItems.getItemView(position); item.addFlags(RemoteViews.FLAG_WIDGET_IS_COLLECTION_CHILD); item.addFlags(RemoteViews.FLAG_WIDGET_IS_COLLECTION_CHILD); View reapplyView = getViewToReapply(convertView, item); // Reapply the RemoteViews if we can. if (reapplyView != null) { try { item.reapply( parent.getContext(), reapplyView, mInteractionHandler, null /* size */, mColorResources); return reapplyView; } catch (RuntimeException e) { // We can't reapply for some reason, we'll fallback to an apply and inflate a // new view. } } return item.apply( parent.getContext(), parent, mInteractionHandler, null /* size */, mColorResources); } /** Returns {@code convertView} if it can be used to reapply {@code item}, or null otherwise. */ @Nullable private static View getViewToReapply(@Nullable View convertView, @NonNull RemoteViews item) { if (convertView == null) return null; Object layoutIdTag = convertView.getTag(R.id.widget_frame); if (!(layoutIdTag instanceof Integer)) return null; return item.getLayoutId() == (Integer) layoutIdTag ? convertView : null; AppWidgetHostView newView = convertView instanceof AppWidgetHostView.AdapterChildHostView widgetChildView ? widgetChildView : new AppWidgetHostView.AdapterChildHostView(parent.getContext()); newView.setInteractionHandler(mInteractionHandler); newView.setColorResourcesNoReapply(mColorResources); newView.updateAppWidget(item); return newView; } } } }
core/java/android/widget/RemoteViews.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -6958,13 +6958,13 @@ public class RemoteViews implements Parcelable, Filter { View parent = (View) view.getParent(); View parent = (View) view.getParent(); // Break the for loop on the first encounter of: // Break the for loop on the first encounter of: // 1) an AdapterView, // 1) an AdapterView, // 2) an AppWidgetHostView that is not a RemoteViewsFrameLayout, or // 2) an AppWidgetHostView that is not a child of an adapter view, or // 3) a null parent. // 3) a null parent. // 2) and 3) are unexpected and catch the case where a child is not // 2) and 3) are unexpected and catch the case where a child is not // correctly parented in an AdapterView. // correctly parented in an AdapterView. while (parent != null && !(parent instanceof AdapterView<?>) while (parent != null && !(parent instanceof AdapterView<?>) && !((parent instanceof AppWidgetHostView) && !((parent instanceof AppWidgetHostView) && !(parent instanceof RemoteViewsAdapter.RemoteViewsFrameLayout))) { && !(parent instanceof AppWidgetHostView.AdapterChildHostView))) { parent = (View) parent.getParent(); parent = (View) parent.getParent(); } } Loading
core/java/android/widget/RemoteViewsAdapter.java +1 −6 Original line number Original line Diff line number Diff line Loading @@ -368,7 +368,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback * A FrameLayout which contains a loading view, and manages the re/applying of RemoteViews when * A FrameLayout which contains a loading view, and manages the re/applying of RemoteViews when * they are loaded. * they are loaded. */ */ static class RemoteViewsFrameLayout extends AppWidgetHostView { static class RemoteViewsFrameLayout extends AppWidgetHostView.AdapterChildHostView { private final FixedSizeRemoteViewsCache mCache; private final FixedSizeRemoteViewsCache mCache; public int cacheIndex = -1; public int cacheIndex = -1; Loading Loading @@ -407,11 +407,6 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback return loadingTextView; return loadingTextView; } } @Override protected Context getRemoteContextEnsuringCorrectCachedApkPath() { return null; } @Override @Override protected View getErrorView() { protected View getErrorView() { // Use the default loading view as the error view. // Use the default loading view as the error view. Loading