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

Commit 88e3bfc0 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Merge "Revert "Making adapter child views in...

Merge "Merge "Revert "Making adapter child views in RemoteCollectionItemsAdapter size-aware"" into android14-tests-dev am: 679d9285" into main am: 6b55c28f

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



Change-Id: Ia66f9e4277a10b41e1b24aa8eda5957e61843c49
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 99d00ede 6b55c28f
Loading
Loading
Loading
Loading
+3 −33
Original line number Diff line number Diff line
@@ -155,22 +155,6 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW
        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
     * to widgets, as described in {@link #getDefaultPaddingForWidget(Context, ComponentName, Rect)}
@@ -937,31 +921,17 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW
        setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping));
    }

    private void setColorResourcesStates(RemoteViews.ColorResources colorResources) {
        mColorResources = colorResources;
        mColorMappingChanged = true;
        mViewMode = VIEW_MODE_NOINIT;
    }

    /** @hide **/
    public void setColorResources(RemoteViews.ColorResources colorResources) {
        if (colorResources == mColorResources) {
            return;
        }
        setColorResourcesStates(colorResources);
        mColorResources = colorResources;
        mColorMappingChanged = true;
        mViewMode = VIEW_MODE_NOINIT;
        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. */
    private boolean isSameColorMapping(SparseIntArray oldColors, SparseIntArray newColors) {
        if (oldColors.size() != newColors.size()) {
+36 −9
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.widget;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.appwidget.AppWidgetHostView;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
@@ -26,6 +25,8 @@ import android.widget.RemoteViews.ColorResources;
import android.widget.RemoteViews.InteractionHandler;
import android.widget.RemoteViews.RemoteCollectionItems;

import com.android.internal.R;

import java.util.stream.IntStream;

/**
@@ -177,14 +178,40 @@ class RemoteCollectionItemsAdapter extends BaseAdapter {

        RemoteViews item = mItems.getItemView(position);
        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;

        AppWidgetHostView newView = convertView instanceof AppWidgetHostView.AdapterChildHostView
                widgetChildView
                ? widgetChildView
                : new AppWidgetHostView.AdapterChildHostView(parent.getContext());
        newView.setInteractionHandler(mInteractionHandler);
        newView.setColorResourcesNoReapply(mColorResources);
        newView.updateAppWidget(item);
        return newView;
        return item.getLayoutId() == (Integer) layoutIdTag ? convertView : null;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -6913,13 +6913,13 @@ public class RemoteViews implements Parcelable, Filter {
            View parent = (View) view.getParent();
            // Break the for loop on the first encounter of:
            //    1) an AdapterView,
            //    2) an AppWidgetHostView that is not a child of an adapter view, or
            //    2) an AppWidgetHostView that is not a RemoteViewsFrameLayout, or
            //    3) a null parent.
            // 2) and 3) are unexpected and catch the case where a child is not
            // correctly parented in an AdapterView.
            while (parent != null && !(parent instanceof AdapterView<?>)
                    && !((parent instanceof AppWidgetHostView)
                            && !(parent instanceof AppWidgetHostView.AdapterChildHostView))) {
                    && !(parent instanceof RemoteViewsAdapter.RemoteViewsFrameLayout))) {
                parent = (View) parent.getParent();
            }

+6 −1
Original line number Diff line number Diff line
@@ -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
     * they are loaded.
     */
    static class RemoteViewsFrameLayout extends AppWidgetHostView.AdapterChildHostView {
    static class RemoteViewsFrameLayout extends AppWidgetHostView {
        private final FixedSizeRemoteViewsCache mCache;

        public int cacheIndex = -1;
@@ -407,6 +407,11 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
            return loadingTextView;
        }

        @Override
        protected Context getRemoteContextEnsuringCorrectCachedApkPath() {
            return null;
        }

        @Override
        protected View getErrorView() {
            // Use the default loading view as the error view.