Merge "Add a way to set the View ID of the top-level view on a RemoteViews." into sc-dev

This commit is contained in:
TreeHugger Robot
2021-03-08 08:53:12 +00:00
committed by Android (Google) Code Review
2 changed files with 33 additions and 0 deletions

View File

@@ -54884,6 +54884,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);
@@ -54944,6 +54945,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);

View File

@@ -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;
@@ -4799,6 +4806,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;
}
@@ -5746,4 +5756,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;
}
}