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

Commit 3a83f0e9 authored by Willie Koomson's avatar Willie Koomson
Browse files

Make setRemoteAdapter() work for nested RemoteViews

This change adds applyNestedView() and reapplyNestedView() to
RemoteViews. This makes it possible to pass the top-level
"rootParent" view (usually AppWidgetHostView for widgets) to nested
RemoteViews that are added by addView(). This allows setRemoteAdapter
actions to work properly when they are used in nested RemoteViews.

Bug: 214288099
Test: RemoteViewsTest
Change-Id: I4fa3fe98d89bffdc0a5be46dabed12b9c217219e
parent e5c32305
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -2419,8 +2419,8 @@ public class RemoteViews implements Parcelable, Filter {
                            target.removeViews(nextChild, recycledViewIndex - nextChild);
                        }
                        setNextRecyclableChild(target, nextChild + 1, target.getChildCount());
                        rvToApply.reapply(context, child, handler, null /* size */, colorResources,
                                false /* topLevel */);
                        rvToApply.reapplyNestedViews(context, child, rootParent, handler,
                                null /* size */, colorResources);
                        return;
                    }
                    // If we cannot recycle the views, we still remove all views in between to
@@ -2431,8 +2431,8 @@ public class RemoteViews implements Parcelable, Filter {
            // If we cannot recycle, insert the new view before the next recyclable child.

            // Inflate nested views and add as children
            View nestedView = rvToApply.apply(context, target, handler, null /* size */,
                    colorResources);
            View nestedView = rvToApply.applyNestedViews(context, target, rootParent, handler,
                    null /* size */, colorResources);
            if (mStableId != NO_ID) {
                setStableId(nestedView, mStableId);
            }
@@ -3780,7 +3780,7 @@ public class RemoteViews implements Parcelable, Filter {
     * @param parcel
     */
    public RemoteViews(Parcel parcel) {
        this(parcel, /* rootParent= */ null, /* info= */ null, /* depth= */ 0);
        this(parcel, /* rootData= */ null, /* info= */ null, /* depth= */ 0);
    }

    private RemoteViews(@NonNull Parcel parcel, @Nullable HierarchyRootData rootData,
@@ -5580,6 +5580,16 @@ public class RemoteViews implements Parcelable, Filter {
        return result;
    }

    private View applyNestedViews(Context context, ViewGroup directParent,
            ViewGroup rootParent, InteractionHandler handler, SizeF size,
            ColorResources colorResources) {
        RemoteViews rvToApply = getRemoteViewsToApply(context, size);

        View result = inflateView(context, rvToApply, directParent, 0, colorResources);
        rvToApply.performApply(result, rootParent, handler, colorResources);
        return result;
    }

    private View inflateView(Context context, RemoteViews rv, ViewGroup parent) {
        return inflateView(context, rv, parent, 0, null);
    }
@@ -5895,6 +5905,12 @@ public class RemoteViews implements Parcelable, Filter {
        }
    }

    private void reapplyNestedViews(Context context, View v, ViewGroup rootParent,
            InteractionHandler handler, SizeF size, ColorResources colorResources) {
        RemoteViews rvToApply = getRemoteViewsToReapply(context, v, size);
        rvToApply.performApply(v, rootParent, handler, colorResources);
    }

    /**
     * Applies all the actions to the provided view, moving as much of the task on the background
     * thread as possible.
+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2008, 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.
*/
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2008, 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.
*/
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/themed_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/RelativeLayoutAlignTop25Alpha"/>
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2016 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
  -->
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
+10 −0
Original line number Diff line number Diff line
@@ -34,6 +34,16 @@
    <style name="LayoutInDisplayCutoutModeAlways">
        <item name="android:windowLayoutInDisplayCutoutMode">always</item>
    </style>
    <style name="RelativeLayoutAlignBottom50Alpha">
        <item name="android:layout_alignParentTop">false</item>
        <item name="android:layout_alignParentBottom">true</item>
        <item name="android:alpha">0.5</item>
    </style>
    <style name="RelativeLayoutAlignTop25Alpha">
        <item name="android:layout_alignParentTop">true</item>
        <item name="android:layout_alignParentBottom">false</item>
        <item name="android:alpha">0.25</item>
    </style>
    <style name="WindowBackgroundColorLiteral">
        <item name="android:windowBackground">#00FF00</item>
    </style>
Loading