Removing some unused actions from RemoteViews

Also removing parcelable implementation from Actions

Bug: 308191480
Test: Presubmit
Flag: None
Change-Id: I74186bc7a1d75025d8972dae49563d0c8fe63fb4
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index f19a2f9..3078801 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -104,7 +104,6 @@
 
 import com.android.internal.R;
 import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
-import com.android.internal.util.ContrastColorUtil;
 import com.android.internal.util.Preconditions;
 import com.android.internal.widget.IRemoteViewsFactory;
 
@@ -130,7 +129,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.Stack;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
@@ -225,10 +223,8 @@
     private static final int BITMAP_REFLECTION_ACTION_TAG = 12;
     private static final int TEXT_VIEW_SIZE_ACTION_TAG = 13;
     private static final int VIEW_PADDING_ACTION_TAG = 14;
-    private static final int SET_REMOTE_VIEW_ADAPTER_LIST_TAG = 15;
     private static final int SET_REMOTE_INPUTS_ACTION_TAG = 18;
     private static final int LAYOUT_PARAM_ACTION_TAG = 19;
-    private static final int OVERRIDE_TEXT_COLORS_TAG = 20;
     private static final int SET_RIPPLE_DRAWABLE_COLOR_TAG = 21;
     private static final int SET_INT_TAG_TAG = 22;
     private static final int REMOVE_FROM_PARENT_ACTION_TAG = 23;
@@ -494,17 +490,6 @@
     }
 
     /**
-     * Override all text colors in this layout and replace them by the given text color.
-     *
-     * @param textColor The color to use.
-     *
-     * @hide
-     */
-    public void overrideTextColors(int textColor) {
-        addAction(new OverrideTextColorsAction(textColor));
-    }
-
-    /**
      * Sets an integer tag to the view.
      *
      * @hide
@@ -640,7 +625,7 @@
      *
      * SUBCLASSES MUST BE IMMUTABLE SO CLONE WORKS!!!!!
      */
-    private abstract static class Action implements Parcelable {
+    private abstract static class Action {
         @IdRes
         @UnsupportedAppUsage
         int mViewId;
@@ -652,10 +637,6 @@
         public static final int MERGE_APPEND = 1;
         public static final int MERGE_IGNORE = 2;
 
-        public int describeContents() {
-            return 0;
-        }
-
         public void setHierarchyRootData(HierarchyRootData root) {
             // Do nothing
         }
@@ -689,6 +670,8 @@
         public void visitUris(@NonNull Consumer<Uri> visitor) {
             // Nothing to visit by default.
         }
+
+        public abstract void writeToParcel(Parcel dest, int flags);
     }
 
     /**
@@ -1020,86 +1003,6 @@
         }
     }
 
-    private static class SetRemoteViewsAdapterList extends Action {
-        int mViewTypeCount;
-        ArrayList<RemoteViews> mList;
-
-        public SetRemoteViewsAdapterList(@IdRes int id, ArrayList<RemoteViews> list,
-                int viewTypeCount) {
-            this.mViewId = id;
-            this.mList = list;
-            this.mViewTypeCount = viewTypeCount;
-        }
-
-        public SetRemoteViewsAdapterList(Parcel parcel) {
-            mViewId = parcel.readInt();
-            mViewTypeCount = parcel.readInt();
-            mList = parcel.createTypedArrayList(RemoteViews.CREATOR);
-        }
-
-        public void writeToParcel(Parcel dest, int flags) {
-            dest.writeInt(mViewId);
-            dest.writeInt(mViewTypeCount);
-            dest.writeTypedList(mList, flags);
-        }
-
-        @Override
-        public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
-            final View target = root.findViewById(mViewId);
-            if (target == null) return;
-
-            // Ensure that we are applying to an AppWidget root
-            if (!(rootParent instanceof AppWidgetHostView)) {
-                Log.e(LOG_TAG, "SetRemoteViewsAdapterIntent action can only be used for " +
-                        "AppWidgets (root id: " + mViewId + ")");
-                return;
-            }
-            // Ensure that we are calling setRemoteAdapter on an AdapterView that supports it
-            if (!(target instanceof AbsListView) && !(target instanceof AdapterViewAnimator)) {
-                Log.e(LOG_TAG, "Cannot setRemoteViewsAdapter on a view which is not " +
-                        "an AbsListView or AdapterViewAnimator (id: " + mViewId + ")");
-                return;
-            }
-
-            if (target instanceof AbsListView) {
-                AbsListView v = (AbsListView) target;
-                Adapter a = v.getAdapter();
-                if (a instanceof RemoteViewsListAdapter && mViewTypeCount <= a.getViewTypeCount()) {
-                    ((RemoteViewsListAdapter) a).setViewsList(mList);
-                } else {
-                    v.setAdapter(new RemoteViewsListAdapter(v.getContext(), mList, mViewTypeCount,
-                            params.colorResources));
-                }
-            } else if (target instanceof AdapterViewAnimator) {
-                AdapterViewAnimator v = (AdapterViewAnimator) target;
-                Adapter a = v.getAdapter();
-                if (a instanceof RemoteViewsListAdapter && mViewTypeCount <= a.getViewTypeCount()) {
-                    ((RemoteViewsListAdapter) a).setViewsList(mList);
-                } else {
-                    v.setAdapter(new RemoteViewsListAdapter(v.getContext(), mList, mViewTypeCount,
-                            params.colorResources));
-                }
-            }
-        }
-
-        @Override
-        public int getActionTag() {
-            return SET_REMOTE_VIEW_ADAPTER_LIST_TAG;
-        }
-
-        @Override
-        public String getUniqueKey() {
-            return (SET_REMOTE_ADAPTER_TAG + "_" + mViewId);
-        }
-
-        @Override
-        public void visitUris(@NonNull Consumer<Uri> visitor) {
-            for (RemoteViews remoteViews : mList) {
-                remoteViews.visitUris(visitor);
-            }
-        }
-    }
-
     /**
      * Cache of {@link ApplicationInfo}s that can be used to ensure that the same
      * {@link ApplicationInfo} instance is used throughout the RemoteViews.
@@ -3491,51 +3394,6 @@
         }
     }
 
-    /**
-     * Helper action to override all textViewColors
-     */
-    private static class OverrideTextColorsAction extends Action {
-        private final int mTextColor;
-
-        public OverrideTextColorsAction(int textColor) {
-            this.mTextColor = textColor;
-        }
-
-        public OverrideTextColorsAction(Parcel parcel) {
-            mTextColor = parcel.readInt();
-        }
-
-        public void writeToParcel(Parcel dest, int flags) {
-            dest.writeInt(mTextColor);
-        }
-
-        @Override
-        public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
-            // Let's traverse the viewtree and override all textColors!
-            Stack<View> viewsToProcess = new Stack<>();
-            viewsToProcess.add(root);
-            while (!viewsToProcess.isEmpty()) {
-                View v = viewsToProcess.pop();
-                if (v instanceof TextView) {
-                    TextView textView = (TextView) v;
-                    textView.setText(ContrastColorUtil.clearColorSpans(textView.getText()));
-                    textView.setTextColor(mTextColor);
-                }
-                if (v instanceof ViewGroup) {
-                    ViewGroup viewGroup = (ViewGroup) v;
-                    for (int i = 0; i < viewGroup.getChildCount(); i++) {
-                        viewsToProcess.push(viewGroup.getChildAt(i));
-                    }
-                }
-            }
-        }
-
-        @Override
-        public int getActionTag() {
-            return OVERRIDE_TEXT_COLORS_TAG;
-        }
-    }
-
     private static class SetIntTagAction extends Action {
         @IdRes private final int mViewId;
         @IdRes private final int mKey;
@@ -4156,14 +4014,10 @@
                 return new ViewPaddingAction(parcel);
             case BITMAP_REFLECTION_ACTION_TAG:
                 return new BitmapReflectionAction(parcel);
-            case SET_REMOTE_VIEW_ADAPTER_LIST_TAG:
-                return new SetRemoteViewsAdapterList(parcel);
             case SET_REMOTE_INPUTS_ACTION_TAG:
                 return new SetRemoteInputsAction(parcel);
             case LAYOUT_PARAM_ACTION_TAG:
                 return new LayoutParamAction(parcel);
-            case OVERRIDE_TEXT_COLORS_TAG:
-                return new OverrideTextColorsAction(parcel);
             case SET_RIPPLE_DRAWABLE_COLOR_TAG:
                 return new SetRippleDrawableColor(parcel);
             case SET_INT_TAG_TAG:
@@ -4910,7 +4764,11 @@
     @Deprecated
     public void setRemoteAdapter(@IdRes int viewId, ArrayList<RemoteViews> list,
             int viewTypeCount) {
-        addAction(new SetRemoteViewsAdapterList(viewId, list, viewTypeCount));
+        RemoteCollectionItems.Builder b = new RemoteCollectionItems.Builder();
+        for (int i = 0; i < list.size(); i++) {
+            b.addItem(i, list.get(i));
+        }
+        setRemoteAdapter(viewId, b.setViewTypeCount(viewTypeCount).build());
     }
 
     /**
diff --git a/core/java/android/widget/RemoteViewsListAdapter.java b/core/java/android/widget/RemoteViewsListAdapter.java
deleted file mode 100644
index 46f80f3..0000000
--- a/core/java/android/widget/RemoteViewsListAdapter.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.widget;
-
-import android.content.Context;
-import android.view.View;
-import android.view.ViewGroup;
-
-import java.util.ArrayList;
-
-/**
- * @hide
- */
-public class RemoteViewsListAdapter extends BaseAdapter {
-
-    private Context mContext;
-    private ArrayList<RemoteViews> mRemoteViewsList;
-    private ArrayList<Integer> mViewTypes = new ArrayList<Integer>();
-    private int mViewTypeCount;
-    private RemoteViews.ColorResources mColorResources;
-
-    public RemoteViewsListAdapter(Context context, ArrayList<RemoteViews> remoteViews,
-            int viewTypeCount, RemoteViews.ColorResources colorResources) {
-        mContext = context;
-        mRemoteViewsList = remoteViews;
-        mViewTypeCount = viewTypeCount;
-        mColorResources = colorResources;
-        init();
-    }
-
-    public void setViewsList(ArrayList<RemoteViews> remoteViews) {
-        mRemoteViewsList = remoteViews;
-        init();
-        notifyDataSetChanged();
-    }
-
-    private void init() {
-        if (mRemoteViewsList == null) return;
-
-        mViewTypes.clear();
-        for (RemoteViews rv: mRemoteViewsList) {
-            if (!mViewTypes.contains(rv.getLayoutId())) {
-                mViewTypes.add(rv.getLayoutId());
-            }
-        }
-
-        if (mViewTypes.size() > mViewTypeCount || mViewTypeCount < 1) {
-            throw new RuntimeException("Invalid view type count -- view type count must be >= 1" +
-                    "and must be as large as the total number of distinct view types");
-        }
-    }
-
-    @Override
-    public int getCount() {
-        if (mRemoteViewsList != null) {
-            return mRemoteViewsList.size();
-        } else {
-            return 0;
-        }
-    }
-
-    @Override
-    public Object getItem(int position) {
-        return null;
-    }
-
-    @Override
-    public long getItemId(int position) {
-        return position;
-    }
-
-    @Override
-    public View getView(int position, View convertView, ViewGroup parent) {
-        if (position < getCount()) {
-            RemoteViews rv = mRemoteViewsList.get(position);
-            rv.addFlags(RemoteViews.FLAG_WIDGET_IS_COLLECTION_CHILD);
-            View v;
-            if (convertView != null && convertView.getId() == rv.getLayoutId()) {
-                v = convertView;
-                rv.reapply(mContext, v, null /* handler */, null /* size */, mColorResources);
-            } else {
-                v = rv.apply(mContext, parent, null /* handler */, null /* size */,
-                        mColorResources);
-            }
-            return v;
-        } else {
-            return null;
-        }
-    }
-
-    @Override
-    public int getItemViewType(int position) {
-        if (position < getCount()) {
-            int layoutId = mRemoteViewsList.get(position).getLayoutId();
-            return mViewTypes.indexOf(layoutId);
-        } else {
-            return 0;
-        }
-    }
-
-    public int getViewTypeCount() {
-        return mViewTypeCount;
-    }
-
-    @Override
-    public boolean hasStableIds() {
-        return false;
-    }
-}