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

Commit a4f7b7b1 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Add a way to set the View ID of the top-level view on a RemoteViews.

Bug: 181985606
Test: atest CtsWidgetTestCases:android.widget.cts.RemoteViewsTest
Change-Id: I2bcd16bef6cfa9a1461c519239dd6a31558eca64
parent db7aecbc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -54853,6 +54853,7 @@ package android.widget {
    method public int describeContents();
    method public int getLayoutId();
    method public String getPackage();
    method @IdRes public int getViewId();
    method @Deprecated public boolean onLoadClass(Class);
    method public void reapply(android.content.Context, android.view.View);
    method public void removeAllViews(@IdRes int);
@@ -54913,6 +54914,7 @@ package android.widget {
    method public void setTextViewText(@IdRes int, CharSequence);
    method public void setTextViewTextSize(@IdRes int, int, float);
    method public void setUri(@IdRes int, String, android.net.Uri);
    method public void setViewId(@IdRes int);
    method public void setViewLayoutHeight(@IdRes int, float, int);
    method public void setViewLayoutHeightDimen(@IdRes int, @DimenRes int);
    method public void setViewLayoutMargin(@IdRes int, int, float, int);
+31 −0
Original line number Diff line number Diff line
@@ -358,6 +358,13 @@ public class RemoteViews implements Parcelable, Filter {
    @ApplyFlags
    private int mApplyFlags = 0;

    /**
     * Id to use to override the ID of the top-level view in this RemoteViews.
     *
     * Only used if this RemoteViews is defined from a XML layout value.
     */
    private int mViewId = View.NO_ID;

    /** Class cookies of the Parcel this instance was read from. */
    private Map<Class, Object> mClassCookies;

@@ -4768,6 +4775,9 @@ public class RemoteViews implements Parcelable, Filter {
        inflater = inflater.cloneInContext(inflationContext);
        inflater.setFilter(shouldUseStaticFilter() ? INFLATER_FILTER : this);
        View v = inflater.inflate(rv.getLayoutId(), parent, false);
        if (mViewId != View.NO_ID) {
            v.setId(mViewId);
        }
        v.setTagInternal(R.id.widget_frame, rv.getLayoutId());
        return v;
    }
@@ -5715,4 +5725,25 @@ public class RemoteViews implements Parcelable, Filter {
        }
        return true;
    }

    /**
     *  Set the ID of the top-level view of the XML layout.
     *
     *  Set to {@link View#NO_ID} to reset and simply keep the id defined in the XML layout.
     *
     * @throws UnsupportedOperationException if the method is called on a RemoteViews defined in
     * term of other RemoteViews (e.g. {@link #RemoteViews(RemoteViews, RemoteViews)}).
     */
    public void setViewId(@IdRes int viewId) {
        if (hasMultipleLayouts()) {
            throw new UnsupportedOperationException(
                    "The viewId can only be set on RemoteViews defined from a XML layout.");
        }
        mViewId = viewId;
    }

    /** Get the ID of the top-level view of the XML layout, as set by {@link #setViewId}. */
    public @IdRes int getViewId() {
        return mViewId;
    }
}