Merge "Wrapping various apply parameters into a separate class" into tm-qpr-dev am: b4b3a8bdeb
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19531583 Change-Id: I1c24d06db68910c8a99028eca57b233c7e6c5b0d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -103,7 +103,6 @@ public class AppWidgetHostView extends FrameLayout {
|
|||||||
private boolean mOnLightBackground;
|
private boolean mOnLightBackground;
|
||||||
private SizeF mCurrentSize = null;
|
private SizeF mCurrentSize = null;
|
||||||
private RemoteViews.ColorResources mColorResources = null;
|
private RemoteViews.ColorResources mColorResources = null;
|
||||||
private SparseIntArray mColorMapping = null;
|
|
||||||
// Stores the last remote views last inflated.
|
// Stores the last remote views last inflated.
|
||||||
private RemoteViews mLastInflatedRemoteViews = null;
|
private RemoteViews mLastInflatedRemoteViews = null;
|
||||||
private long mLastInflatedRemoteViewsId = -1;
|
private long mLastInflatedRemoteViewsId = -1;
|
||||||
@@ -900,11 +899,19 @@ public class AppWidgetHostView extends FrameLayout {
|
|||||||
* {@link android.R.color#system_neutral1_500}.
|
* {@link android.R.color#system_neutral1_500}.
|
||||||
*/
|
*/
|
||||||
public void setColorResources(@NonNull SparseIntArray colorMapping) {
|
public void setColorResources(@NonNull SparseIntArray colorMapping) {
|
||||||
if (mColorMapping != null && isSameColorMapping(mColorMapping, colorMapping)) {
|
if (mColorResources != null
|
||||||
|
&& isSameColorMapping(mColorResources.getColorMapping(), colorMapping)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mColorMapping = colorMapping.clone();
|
setColorResources(RemoteViews.ColorResources.create(mContext, colorMapping));
|
||||||
mColorResources = RemoteViews.ColorResources.create(mContext, mColorMapping);
|
}
|
||||||
|
|
||||||
|
/** @hide **/
|
||||||
|
public void setColorResources(RemoteViews.ColorResources colorResources) {
|
||||||
|
if (colorResources == mColorResources) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mColorResources = colorResources;
|
||||||
mColorMappingChanged = true;
|
mColorMappingChanged = true;
|
||||||
mViewMode = VIEW_MODE_NOINIT;
|
mViewMode = VIEW_MODE_NOINIT;
|
||||||
reapplyLastRemoteViews();
|
reapplyLastRemoteViews();
|
||||||
@@ -934,7 +941,6 @@ public class AppWidgetHostView extends FrameLayout {
|
|||||||
public void resetColorResources() {
|
public void resetColorResources() {
|
||||||
if (mColorResources != null) {
|
if (mColorResources != null) {
|
||||||
mColorResources = null;
|
mColorResources = null;
|
||||||
mColorMapping = null;
|
|
||||||
mColorMappingChanged = true;
|
mColorMappingChanged = true;
|
||||||
mViewMode = VIEW_MODE_NOINIT;
|
mViewMode = VIEW_MODE_NOINIT;
|
||||||
reapplyLastRemoteViews();
|
reapplyLastRemoteViews();
|
||||||
|
|||||||
@@ -594,8 +594,8 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
* SUBCLASSES MUST BE IMMUTABLE SO CLONE WORKS!!!!!
|
* SUBCLASSES MUST BE IMMUTABLE SO CLONE WORKS!!!!!
|
||||||
*/
|
*/
|
||||||
private abstract static class Action implements Parcelable {
|
private abstract static class Action implements Parcelable {
|
||||||
public abstract void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public abstract void apply(View root, ViewGroup rootParent, ActionApplyParams params)
|
||||||
ColorResources colorResources) throws ActionException;
|
throws ActionException;
|
||||||
|
|
||||||
public static final int MERGE_REPLACE = 0;
|
public static final int MERGE_REPLACE = 0;
|
||||||
public static final int MERGE_APPEND = 1;
|
public static final int MERGE_APPEND = 1;
|
||||||
@@ -626,7 +626,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
* Override this if some of the tasks can be performed async.
|
* Override this if some of the tasks can be performed async.
|
||||||
*/
|
*/
|
||||||
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,9 +661,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
// Constant used during async execution. It is not parcelable.
|
// Constant used during async execution. It is not parcelable.
|
||||||
private static final Action ACTION_NOOP = new RuntimeAction() {
|
private static final Action ACTION_NOOP = new RuntimeAction() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) { }
|
||||||
ColorResources colorResources) {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -798,8 +796,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View view = root.findViewById(viewId);
|
final View view = root.findViewById(viewId);
|
||||||
if (!(view instanceof AdapterView<?>)) return;
|
if (!(view instanceof AdapterView<?>)) return;
|
||||||
|
|
||||||
@@ -834,8 +831,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, final InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -846,7 +842,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
OnItemClickListener listener = (parent, view, position, id) -> {
|
OnItemClickListener listener = (parent, view, position, id) -> {
|
||||||
RemoteResponse response = findRemoteResponseTag(view);
|
RemoteResponse response = findRemoteResponseTag(view);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
response.handleViewInteraction(view, handler);
|
response.handleViewInteraction(view, params.handler);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
av.setOnItemClickListener(listener);
|
av.setOnItemClickListener(listener);
|
||||||
@@ -910,8 +906,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -935,7 +930,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
((RemoteViewsListAdapter) a).setViewsList(list);
|
((RemoteViewsListAdapter) a).setViewsList(list);
|
||||||
} else {
|
} else {
|
||||||
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list, viewTypeCount,
|
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list, viewTypeCount,
|
||||||
colorResources));
|
params.colorResources));
|
||||||
}
|
}
|
||||||
} else if (target instanceof AdapterViewAnimator) {
|
} else if (target instanceof AdapterViewAnimator) {
|
||||||
AdapterViewAnimator v = (AdapterViewAnimator) target;
|
AdapterViewAnimator v = (AdapterViewAnimator) target;
|
||||||
@@ -944,7 +939,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
((RemoteViewsListAdapter) a).setViewsList(list);
|
((RemoteViewsListAdapter) a).setViewsList(list);
|
||||||
} else {
|
} else {
|
||||||
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list, viewTypeCount,
|
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list, viewTypeCount,
|
||||||
colorResources));
|
params.colorResources));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1025,8 +1020,8 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params)
|
||||||
ColorResources colorResources) throws ActionException {
|
throws ActionException {
|
||||||
View target = root.findViewById(viewId);
|
View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -1053,7 +1048,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
&& adapter.getViewTypeCount() >= mItems.getViewTypeCount()) {
|
&& adapter.getViewTypeCount() >= mItems.getViewTypeCount()) {
|
||||||
try {
|
try {
|
||||||
((RemoteCollectionItemsAdapter) adapter).setData(
|
((RemoteCollectionItemsAdapter) adapter).setData(
|
||||||
mItems, handler, colorResources);
|
mItems, params.handler, params.colorResources);
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
// setData should never failed with the validation in the items builder, but if
|
// setData should never failed with the validation in the items builder, but if
|
||||||
// it does, catch and rethrow.
|
// it does, catch and rethrow.
|
||||||
@@ -1063,8 +1058,8 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
adapterView.setAdapter(
|
adapterView.setAdapter(new RemoteCollectionItemsAdapter(mItems,
|
||||||
new RemoteCollectionItemsAdapter(mItems, handler, colorResources));
|
params.handler, params.colorResources));
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
// This could throw if the AdapterView somehow doesn't accept BaseAdapter due to
|
// This could throw if the AdapterView somehow doesn't accept BaseAdapter due to
|
||||||
// a type error.
|
// a type error.
|
||||||
@@ -1095,8 +1090,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -1124,17 +1118,17 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
if (target instanceof AbsListView) {
|
if (target instanceof AbsListView) {
|
||||||
AbsListView v = (AbsListView) target;
|
AbsListView v = (AbsListView) target;
|
||||||
v.setRemoteViewsAdapter(intent, isAsync);
|
v.setRemoteViewsAdapter(intent, isAsync);
|
||||||
v.setRemoteViewsInteractionHandler(handler);
|
v.setRemoteViewsInteractionHandler(params.handler);
|
||||||
} else if (target instanceof AdapterViewAnimator) {
|
} else if (target instanceof AdapterViewAnimator) {
|
||||||
AdapterViewAnimator v = (AdapterViewAnimator) target;
|
AdapterViewAnimator v = (AdapterViewAnimator) target;
|
||||||
v.setRemoteViewsAdapter(intent, isAsync);
|
v.setRemoteViewsAdapter(intent, isAsync);
|
||||||
v.setRemoteViewsOnClickHandler(handler);
|
v.setRemoteViewsOnClickHandler(params.handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
SetRemoteViewsAdapterIntent copy = new SetRemoteViewsAdapterIntent(viewId, intent);
|
SetRemoteViewsAdapterIntent copy = new SetRemoteViewsAdapterIntent(viewId, intent);
|
||||||
copy.isAsync = true;
|
copy.isAsync = true;
|
||||||
return copy;
|
return copy;
|
||||||
@@ -1173,8 +1167,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, final InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -1215,7 +1208,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
target.setTagInternal(com.android.internal.R.id.fillInIntent, null);
|
target.setTagInternal(com.android.internal.R.id.fillInIntent, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
target.setOnClickListener(v -> mResponse.handleViewInteraction(v, handler));
|
target.setOnClickListener(v -> mResponse.handleViewInteraction(v, params.handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1253,8 +1246,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, final InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
if (!(target instanceof CompoundButton)) {
|
if (!(target instanceof CompoundButton)) {
|
||||||
@@ -1287,7 +1279,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OnCheckedChangeListener onCheckedChangeListener =
|
OnCheckedChangeListener onCheckedChangeListener =
|
||||||
(v, isChecked) -> mResponse.handleViewInteraction(v, handler);
|
(v, isChecked) -> mResponse.handleViewInteraction(v, params.handler);
|
||||||
button.setTagInternal(R.id.remote_checked_change_listener_tag, onCheckedChangeListener);
|
button.setTagInternal(R.id.remote_checked_change_listener_tag, onCheckedChangeListener);
|
||||||
button.setOnCheckedChangeListener(onCheckedChangeListener);
|
button.setOnCheckedChangeListener(onCheckedChangeListener);
|
||||||
}
|
}
|
||||||
@@ -1459,8 +1451,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -1517,8 +1508,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -1561,8 +1551,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View view = root.findViewById(viewId);
|
final View view = root.findViewById(viewId);
|
||||||
if (view == null) return;
|
if (view == null) return;
|
||||||
|
|
||||||
@@ -1675,12 +1664,12 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params)
|
||||||
ColorResources colorResources) throws ActionException {
|
throws ActionException {
|
||||||
ReflectionAction ra = new ReflectionAction(viewId, methodName,
|
ReflectionAction ra = new ReflectionAction(viewId, methodName,
|
||||||
BaseReflectionAction.BITMAP,
|
BaseReflectionAction.BITMAP,
|
||||||
bitmap);
|
bitmap);
|
||||||
ra.apply(root, rootParent, handler, colorResources);
|
ra.apply(root, rootParent, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1756,8 +1745,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
protected abstract Object getParameterValue(@Nullable View view) throws ActionException;
|
protected abstract Object getParameterValue(@Nullable View view) throws ActionException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public final void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View view = root.findViewById(viewId);
|
final View view = root.findViewById(viewId);
|
||||||
if (view == null) return;
|
if (view == null) return;
|
||||||
|
|
||||||
@@ -1775,7 +1763,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public final Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
final View view = root.findViewById(viewId);
|
final View view = root.findViewById(viewId);
|
||||||
if (view == null) return ACTION_NOOP;
|
if (view == null) return ACTION_NOOP;
|
||||||
|
|
||||||
@@ -2307,8 +2295,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
mRunnable.run();
|
mRunnable.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2421,8 +2408,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final Context context = root.getContext();
|
final Context context = root.getContext();
|
||||||
final ViewGroup target = root.findViewById(viewId);
|
final ViewGroup target = root.findViewById(viewId);
|
||||||
|
|
||||||
@@ -2451,8 +2437,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
target.removeViews(nextChild, recycledViewIndex - nextChild);
|
target.removeViews(nextChild, recycledViewIndex - nextChild);
|
||||||
}
|
}
|
||||||
setNextRecyclableChild(target, nextChild + 1, target.getChildCount());
|
setNextRecyclableChild(target, nextChild + 1, target.getChildCount());
|
||||||
rvToApply.reapplyNestedViews(context, child, rootParent, handler,
|
rvToApply.reapplyNestedViews(context, child, rootParent, params);
|
||||||
null /* size */, colorResources);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If we cannot recycle the views, we still remove all views in between to
|
// If we cannot recycle the views, we still remove all views in between to
|
||||||
@@ -2463,8 +2448,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
// If we cannot recycle, insert the new view before the next recyclable child.
|
// If we cannot recycle, insert the new view before the next recyclable child.
|
||||||
|
|
||||||
// Inflate nested views and add as children
|
// Inflate nested views and add as children
|
||||||
View nestedView = rvToApply.applyNestedViews(context, target, rootParent, handler,
|
View nestedView = rvToApply.apply(context, target, rootParent, null /* size */, params);
|
||||||
null /* size */, colorResources);
|
|
||||||
if (mStableId != NO_ID) {
|
if (mStableId != NO_ID) {
|
||||||
setStableId(nestedView, mStableId);
|
setStableId(nestedView, mStableId);
|
||||||
}
|
}
|
||||||
@@ -2477,7 +2461,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
// In the async implementation, update the view tree so that subsequent calls to
|
// In the async implementation, update the view tree so that subsequent calls to
|
||||||
// findViewById return the current view.
|
// findViewById return the current view.
|
||||||
root.createTree();
|
root.createTree();
|
||||||
@@ -2511,8 +2495,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
setNextRecyclableChild(targetVg, nextChild + 1, target.mChildren.size());
|
setNextRecyclableChild(targetVg, nextChild + 1, target.mChildren.size());
|
||||||
final AsyncApplyTask reapplyTask = rvToApply.getInternalAsyncApplyTask(
|
final AsyncApplyTask reapplyTask = rvToApply.getInternalAsyncApplyTask(
|
||||||
context,
|
context,
|
||||||
targetVg, null /* listener */, handler, null /* size */,
|
targetVg, null /* listener */, params, null /* size */,
|
||||||
colorResources,
|
|
||||||
recycled.mRoot);
|
recycled.mRoot);
|
||||||
final ViewTree tree = reapplyTask.doInBackground();
|
final ViewTree tree = reapplyTask.doInBackground();
|
||||||
if (tree == null) {
|
if (tree == null) {
|
||||||
@@ -2521,8 +2504,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
return new RuntimeAction() {
|
return new RuntimeAction() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent,
|
public void apply(View root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources)
|
ActionApplyParams params) throws ActionException {
|
||||||
throws ActionException {
|
|
||||||
reapplyTask.onPostExecute(tree);
|
reapplyTask.onPostExecute(tree);
|
||||||
if (recycledViewIndex > nextChild) {
|
if (recycledViewIndex > nextChild) {
|
||||||
targetVg.removeViews(nextChild, recycledViewIndex - nextChild);
|
targetVg.removeViews(nextChild, recycledViewIndex - nextChild);
|
||||||
@@ -2533,23 +2515,22 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
// If the layout id is different, still remove the children as if we recycled
|
// If the layout id is different, still remove the children as if we recycled
|
||||||
// the view, to insert at the same place.
|
// the view, to insert at the same place.
|
||||||
target.removeChildren(nextChild, recycledViewIndex - nextChild + 1);
|
target.removeChildren(nextChild, recycledViewIndex - nextChild + 1);
|
||||||
return insertNewView(context, target, handler, colorResources,
|
return insertNewView(context, target, params,
|
||||||
() -> targetVg.removeViews(nextChild,
|
() -> targetVg.removeViews(nextChild,
|
||||||
recycledViewIndex - nextChild + 1));
|
recycledViewIndex - nextChild + 1));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we cannot recycle, simply add the view at the same available slot.
|
// If we cannot recycle, simply add the view at the same available slot.
|
||||||
return insertNewView(context, target, handler, colorResources, () -> {});
|
return insertNewView(context, target, params, () -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Action insertNewView(Context context, ViewTree target, InteractionHandler handler,
|
private Action insertNewView(Context context, ViewTree target,
|
||||||
ColorResources colorResources, Runnable finalizeAction) {
|
ActionApplyParams params, Runnable finalizeAction) {
|
||||||
ViewGroup targetVg = (ViewGroup) target.mRoot;
|
ViewGroup targetVg = (ViewGroup) target.mRoot;
|
||||||
int nextChild = getNextRecyclableChild(targetVg);
|
int nextChild = getNextRecyclableChild(targetVg);
|
||||||
final AsyncApplyTask task = mNestedViews.getInternalAsyncApplyTask(context, targetVg,
|
final AsyncApplyTask task = mNestedViews.getInternalAsyncApplyTask(context, targetVg,
|
||||||
null /* listener */, handler, null /* size */, colorResources,
|
null /* listener */, params, null /* size */, null /* result */);
|
||||||
null /* result */);
|
|
||||||
final ViewTree tree = task.doInBackground();
|
final ViewTree tree = task.doInBackground();
|
||||||
|
|
||||||
if (tree == null) {
|
if (tree == null) {
|
||||||
@@ -2569,8 +2550,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
return new RuntimeAction() {
|
return new RuntimeAction() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) throws ActionException {
|
|
||||||
task.onPostExecute(tree);
|
task.onPostExecute(tree);
|
||||||
finalizeAction.run();
|
finalizeAction.run();
|
||||||
targetVg.addView(task.mResult, insertIndex);
|
targetVg.addView(task.mResult, insertIndex);
|
||||||
@@ -2627,8 +2607,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final ViewGroup target = root.findViewById(viewId);
|
final ViewGroup target = root.findViewById(viewId);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
@@ -2652,7 +2631,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
// In the async implementation, update the view tree so that subsequent calls to
|
// In the async implementation, update the view tree so that subsequent calls to
|
||||||
// findViewById return the current view.
|
// findViewById return the current view.
|
||||||
root.createTree();
|
root.createTree();
|
||||||
@@ -2676,8 +2655,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
return new RuntimeAction() {
|
return new RuntimeAction() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) throws ActionException {
|
|
||||||
if (mViewIdToKeep == REMOVE_ALL_VIEWS_ID) {
|
if (mViewIdToKeep == REMOVE_ALL_VIEWS_ID) {
|
||||||
for (int i = targetVg.getChildCount() - 1; i >= 0; i--) {
|
for (int i = targetVg.getChildCount() - 1; i >= 0; i--) {
|
||||||
if (!hasStableId(targetVg.getChildAt(i))) {
|
if (!hasStableId(targetVg.getChildAt(i))) {
|
||||||
@@ -2736,8 +2714,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
|
|
||||||
if (target == null || target == root) {
|
if (target == null || target == root) {
|
||||||
@@ -2752,7 +2729,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
// In the async implementation, update the view tree so that subsequent calls to
|
// In the async implementation, update the view tree so that subsequent calls to
|
||||||
// findViewById return the correct view.
|
// findViewById return the correct view.
|
||||||
root.createTree();
|
root.createTree();
|
||||||
@@ -2771,8 +2748,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
parent.mChildren.remove(target);
|
parent.mChildren.remove(target);
|
||||||
return new RuntimeAction() {
|
return new RuntimeAction() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) throws ActionException {
|
|
||||||
parentVg.removeView(target.mRoot);
|
parentVg.removeView(target.mRoot);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2851,8 +2827,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final TextView target = root.findViewById(viewId);
|
final TextView target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
if (drawablesLoaded) {
|
if (drawablesLoaded) {
|
||||||
@@ -2883,7 +2858,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
public Action initActionAsync(ViewTree root, ViewGroup rootParent,
|
||||||
InteractionHandler handler, ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
final TextView target = root.findViewById(viewId);
|
final TextView target = root.findViewById(viewId);
|
||||||
if (target == null) return ACTION_NOOP;
|
if (target == null) return ACTION_NOOP;
|
||||||
|
|
||||||
@@ -2961,8 +2936,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final TextView target = root.findViewById(viewId);
|
final TextView target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
target.setTextSize(units, size);
|
target.setTextSize(units, size);
|
||||||
@@ -3007,8 +2981,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
target.setPadding(left, top, right, bottom);
|
target.setPadding(left, top, right, bottom);
|
||||||
@@ -3084,8 +3057,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return;
|
return;
|
||||||
@@ -3230,8 +3202,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -3266,8 +3237,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
// Let's traverse the viewtree and override all textColors!
|
// Let's traverse the viewtree and override all textColors!
|
||||||
Stack<View> viewsToProcess = new Stack<>();
|
Stack<View> viewsToProcess = new Stack<>();
|
||||||
viewsToProcess.add(root);
|
viewsToProcess.add(root);
|
||||||
@@ -3317,8 +3287,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
|
||||||
final View target = root.findViewById(mViewId);
|
final View target = root.findViewById(mViewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -3352,8 +3321,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params)
|
||||||
ColorResources colorResources)
|
|
||||||
throws ActionException {
|
throws ActionException {
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
@@ -3404,8 +3372,8 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params)
|
||||||
ColorResources colorResources) throws ActionException {
|
throws ActionException {
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -3483,8 +3451,8 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(View root, ViewGroup rootParent, InteractionHandler handler,
|
public void apply(View root, ViewGroup rootParent, ActionApplyParams params)
|
||||||
ColorResources colorResources) throws ActionException {
|
throws ActionException {
|
||||||
final View target = root.findViewById(viewId);
|
final View target = root.findViewById(viewId);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
@@ -5578,52 +5546,39 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
public View apply(@NonNull Context context, @NonNull ViewGroup parent,
|
public View apply(@NonNull Context context, @NonNull ViewGroup parent,
|
||||||
@Nullable InteractionHandler handler, @Nullable SizeF size) {
|
@Nullable InteractionHandler handler, @Nullable SizeF size) {
|
||||||
RemoteViews rvToApply = getRemoteViewsToApply(context, size);
|
return apply(context, parent, size, new ActionApplyParams()
|
||||||
|
.withInteractionHandler(handler));
|
||||||
View result = inflateView(context, rvToApply, parent);
|
|
||||||
rvToApply.performApply(result, parent, handler, null);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public View applyWithTheme(@NonNull Context context, @NonNull ViewGroup parent,
|
public View applyWithTheme(@NonNull Context context, @NonNull ViewGroup parent,
|
||||||
@Nullable InteractionHandler handler, @StyleRes int applyThemeResId) {
|
@Nullable InteractionHandler handler, @StyleRes int applyThemeResId) {
|
||||||
return applyWithTheme(context, parent, handler, applyThemeResId, null);
|
return apply(context, parent, null, new ActionApplyParams()
|
||||||
}
|
.withInteractionHandler(handler)
|
||||||
|
.withThemeResId(applyThemeResId));
|
||||||
/** @hide */
|
|
||||||
public View applyWithTheme(@NonNull Context context, @NonNull ViewGroup parent,
|
|
||||||
@Nullable InteractionHandler handler, @StyleRes int applyThemeResId,
|
|
||||||
@Nullable SizeF size) {
|
|
||||||
RemoteViews rvToApply = getRemoteViewsToApply(context, size);
|
|
||||||
|
|
||||||
View result = inflateView(context, rvToApply, parent, applyThemeResId, null);
|
|
||||||
rvToApply.performApply(result, parent, handler, null);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public View apply(Context context, ViewGroup parent, InteractionHandler handler,
|
public View apply(Context context, ViewGroup parent, InteractionHandler handler,
|
||||||
@Nullable SizeF size, @Nullable ColorResources colorResources) {
|
@Nullable SizeF size, @Nullable ColorResources colorResources) {
|
||||||
RemoteViews rvToApply = getRemoteViewsToApply(context, size);
|
return apply(context, parent, size, new ActionApplyParams()
|
||||||
|
.withInteractionHandler(handler)
|
||||||
View result = inflateView(context, rvToApply, parent, 0, colorResources);
|
.withColorResources(colorResources));
|
||||||
rvToApply.performApply(result, parent, handler, colorResources);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View applyNestedViews(Context context, ViewGroup directParent,
|
/** @hide **/
|
||||||
ViewGroup rootParent, InteractionHandler handler, SizeF size,
|
public View apply(Context context, ViewGroup parent, @Nullable SizeF size,
|
||||||
ColorResources colorResources) {
|
ActionApplyParams params) {
|
||||||
RemoteViews rvToApply = getRemoteViewsToApply(context, size);
|
return apply(context, parent, parent, size, params);
|
||||||
|
|
||||||
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) {
|
private View apply(Context context, ViewGroup directParent, ViewGroup rootParent,
|
||||||
return inflateView(context, rv, parent, 0, null);
|
@Nullable SizeF size, ActionApplyParams params) {
|
||||||
|
RemoteViews rvToApply = getRemoteViewsToApply(context, size);
|
||||||
|
View result = inflateView(context, rvToApply, directParent,
|
||||||
|
params.applyThemeResId, params.colorResources);
|
||||||
|
rvToApply.performApply(result, rootParent, params);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private View inflateView(Context context, RemoteViews rv, @Nullable ViewGroup parent,
|
private View inflateView(Context context, RemoteViews rv, @Nullable ViewGroup parent,
|
||||||
@@ -5704,7 +5659,6 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
return applyAsync(context, parent, executor, listener, null /* handler */);
|
return applyAsync(context, parent, executor, listener, null /* handler */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public CancellationSignal applyAsync(Context context, ViewGroup parent,
|
public CancellationSignal applyAsync(Context context, ViewGroup parent,
|
||||||
Executor executor, OnViewAppliedListener listener, InteractionHandler handler) {
|
Executor executor, OnViewAppliedListener listener, InteractionHandler handler) {
|
||||||
@@ -5723,16 +5677,19 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
public CancellationSignal applyAsync(Context context, ViewGroup parent, Executor executor,
|
public CancellationSignal applyAsync(Context context, ViewGroup parent, Executor executor,
|
||||||
OnViewAppliedListener listener, InteractionHandler handler, SizeF size,
|
OnViewAppliedListener listener, InteractionHandler handler, SizeF size,
|
||||||
ColorResources colorResources) {
|
ColorResources colorResources) {
|
||||||
|
|
||||||
|
ActionApplyParams params = new ActionApplyParams()
|
||||||
|
.withInteractionHandler(handler)
|
||||||
|
.withColorResources(colorResources)
|
||||||
|
.withExecutor(executor);
|
||||||
return new AsyncApplyTask(getRemoteViewsToApply(context, size), parent, context, listener,
|
return new AsyncApplyTask(getRemoteViewsToApply(context, size), parent, context, listener,
|
||||||
handler, colorResources, null /* result */,
|
params, null /* result */, true /* topLevel */).startTaskOnExecutor(executor);
|
||||||
true /* topLevel */).startTaskOnExecutor(executor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AsyncApplyTask getInternalAsyncApplyTask(Context context, ViewGroup parent,
|
private AsyncApplyTask getInternalAsyncApplyTask(Context context, ViewGroup parent,
|
||||||
OnViewAppliedListener listener, InteractionHandler handler, SizeF size,
|
OnViewAppliedListener listener, ActionApplyParams params, SizeF size, View result) {
|
||||||
ColorResources colorResources, View result) {
|
|
||||||
return new AsyncApplyTask(getRemoteViewsToApply(context, size), parent, context, listener,
|
return new AsyncApplyTask(getRemoteViewsToApply(context, size), parent, context, listener,
|
||||||
handler, colorResources, result, false /* topLevel */);
|
params, result, false /* topLevel */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AsyncApplyTask extends AsyncTask<Void, Void, ViewTree>
|
private class AsyncApplyTask extends AsyncTask<Void, Void, ViewTree>
|
||||||
@@ -5742,8 +5699,8 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
final ViewGroup mParent;
|
final ViewGroup mParent;
|
||||||
final Context mContext;
|
final Context mContext;
|
||||||
final OnViewAppliedListener mListener;
|
final OnViewAppliedListener mListener;
|
||||||
final InteractionHandler mHandler;
|
final ActionApplyParams mApplyParams;
|
||||||
final ColorResources mColorResources;
|
|
||||||
/**
|
/**
|
||||||
* Whether the remote view is the top-level one (i.e. not within an action).
|
* Whether the remote view is the top-level one (i.e. not within an action).
|
||||||
*
|
*
|
||||||
@@ -5758,16 +5715,13 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
private AsyncApplyTask(
|
private AsyncApplyTask(
|
||||||
RemoteViews rv, ViewGroup parent, Context context, OnViewAppliedListener listener,
|
RemoteViews rv, ViewGroup parent, Context context, OnViewAppliedListener listener,
|
||||||
InteractionHandler handler, ColorResources colorResources,
|
ActionApplyParams applyParams, View result, boolean topLevel) {
|
||||||
View result, boolean topLevel) {
|
|
||||||
mRV = rv;
|
mRV = rv;
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
mColorResources = colorResources;
|
|
||||||
mHandler = handler;
|
|
||||||
mTopLevel = topLevel;
|
mTopLevel = topLevel;
|
||||||
|
mApplyParams = applyParams;
|
||||||
mResult = result;
|
mResult = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5776,17 +5730,18 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
protected ViewTree doInBackground(Void... params) {
|
protected ViewTree doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
if (mResult == null) {
|
if (mResult == null) {
|
||||||
mResult = inflateView(mContext, mRV, mParent, 0, mColorResources);
|
mResult = inflateView(mContext, mRV, mParent, 0, mApplyParams.colorResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
mTree = new ViewTree(mResult);
|
mTree = new ViewTree(mResult);
|
||||||
|
|
||||||
if (mRV.mActions != null) {
|
if (mRV.mActions != null) {
|
||||||
int count = mRV.mActions.size();
|
int count = mRV.mActions.size();
|
||||||
mActions = new Action[count];
|
mActions = new Action[count];
|
||||||
for (int i = 0; i < count && !isCancelled(); i++) {
|
for (int i = 0; i < count && !isCancelled(); i++) {
|
||||||
// TODO: check if isCancelled in nested views.
|
// TODO: check if isCancelled in nested views.
|
||||||
mActions[i] = mRV.mActions.get(i).initActionAsync(mTree, mParent, mHandler,
|
mActions[i] = mRV.mActions.get(i)
|
||||||
mColorResources);
|
.initActionAsync(mTree, mParent, mApplyParams);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mActions = null;
|
mActions = null;
|
||||||
@@ -5808,10 +5763,13 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (mActions != null) {
|
if (mActions != null) {
|
||||||
InteractionHandler handler = mHandler == null
|
|
||||||
? DEFAULT_INTERACTION_HANDLER : mHandler;
|
ActionApplyParams applyParams = mApplyParams.clone();
|
||||||
|
if (applyParams.handler == null) {
|
||||||
|
applyParams.handler = DEFAULT_INTERACTION_HANDLER;
|
||||||
|
}
|
||||||
for (Action a : mActions) {
|
for (Action a : mActions) {
|
||||||
a.apply(viewTree.mRoot, mParent, handler, mColorResources);
|
a.apply(viewTree.mRoot, mParent, applyParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the parent of the view is has is a root, resolve the recycling.
|
// If the parent of the view is has is a root, resolve the recycling.
|
||||||
@@ -5859,18 +5817,43 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
* the {@link #apply(Context,ViewGroup)} call.
|
* the {@link #apply(Context,ViewGroup)} call.
|
||||||
*/
|
*/
|
||||||
public void reapply(Context context, View v) {
|
public void reapply(Context context, View v) {
|
||||||
reapply(context, v, null /* handler */);
|
reapply(context, v, null /* size */, new ActionApplyParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public void reapply(Context context, View v, InteractionHandler handler) {
|
public void reapply(Context context, View v, InteractionHandler handler) {
|
||||||
reapply(context, v, handler, null /* size */, null /* colorResources */);
|
reapply(context, v, null /* size */,
|
||||||
|
new ActionApplyParams().withInteractionHandler(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public void reapply(Context context, View v, InteractionHandler handler, SizeF size,
|
public void reapply(Context context, View v, InteractionHandler handler, SizeF size,
|
||||||
ColorResources colorResources) {
|
ColorResources colorResources) {
|
||||||
reapply(context, v, handler, size, colorResources, true);
|
reapply(context, v, size, new ActionApplyParams()
|
||||||
|
.withInteractionHandler(handler).withColorResources(colorResources));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
public void reapply(Context context, View v, @Nullable SizeF size, ActionApplyParams params) {
|
||||||
|
reapply(context, v, (ViewGroup) v.getParent(), size, params, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reapplyNestedViews(Context context, View v, ViewGroup rootParent,
|
||||||
|
ActionApplyParams params) {
|
||||||
|
reapply(context, v, rootParent, null, params, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: topLevel should be true only for calls on the topLevel RemoteViews, internal calls
|
||||||
|
// should set it to false.
|
||||||
|
private void reapply(Context context, View v, ViewGroup rootParent,
|
||||||
|
@Nullable SizeF size, ActionApplyParams params, boolean topLevel) {
|
||||||
|
RemoteViews rvToApply = getRemoteViewsToReapply(context, v, size);
|
||||||
|
rvToApply.performApply(v, rootParent, params);
|
||||||
|
|
||||||
|
// If the parent of the view is has is a root, resolve the recycling.
|
||||||
|
if (topLevel && v instanceof ViewGroup) {
|
||||||
|
finalizeViewRecycling((ViewGroup) v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -5922,27 +5905,6 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
return rvToApply;
|
return rvToApply;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: topLevel should be true only for calls on the topLevel RemoteViews, internal calls
|
|
||||||
// should set it to false.
|
|
||||||
private void reapply(Context context, View v, InteractionHandler handler, SizeF size,
|
|
||||||
ColorResources colorResources, boolean topLevel) {
|
|
||||||
|
|
||||||
RemoteViews rvToApply = getRemoteViewsToReapply(context, v, size);
|
|
||||||
|
|
||||||
rvToApply.performApply(v, (ViewGroup) v.getParent(), handler, colorResources);
|
|
||||||
|
|
||||||
// If the parent of the view is has is a root, resolve the recycling.
|
|
||||||
if (topLevel && v instanceof ViewGroup) {
|
|
||||||
finalizeViewRecycling((ViewGroup) v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
* Applies all the actions to the provided view, moving as much of the task on the background
|
||||||
* thread as possible.
|
* thread as possible.
|
||||||
@@ -5973,19 +5935,25 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
ColorResources colorResources) {
|
ColorResources colorResources) {
|
||||||
RemoteViews rvToApply = getRemoteViewsToReapply(context, v, size);
|
RemoteViews rvToApply = getRemoteViewsToReapply(context, v, size);
|
||||||
|
|
||||||
|
ActionApplyParams params = new ActionApplyParams()
|
||||||
|
.withColorResources(colorResources)
|
||||||
|
.withInteractionHandler(handler)
|
||||||
|
.withExecutor(executor);
|
||||||
|
|
||||||
return new AsyncApplyTask(rvToApply, (ViewGroup) v.getParent(),
|
return new AsyncApplyTask(rvToApply, (ViewGroup) v.getParent(),
|
||||||
context, listener, handler, colorResources, v, true /* topLevel */)
|
context, listener, params, v, true /* topLevel */)
|
||||||
.startTaskOnExecutor(executor);
|
.startTaskOnExecutor(executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performApply(View v, ViewGroup parent, InteractionHandler handler,
|
private void performApply(View v, ViewGroup parent, ActionApplyParams params) {
|
||||||
ColorResources colorResources) {
|
params = params.clone();
|
||||||
|
if (params.handler == null) {
|
||||||
|
params.handler = DEFAULT_INTERACTION_HANDLER;
|
||||||
|
}
|
||||||
if (mActions != null) {
|
if (mActions != null) {
|
||||||
handler = handler == null ? DEFAULT_INTERACTION_HANDLER : handler;
|
|
||||||
final int count = mActions.size();
|
final int count = mActions.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Action a = mActions.get(i);
|
mActions.get(i).apply(v, parent, params);
|
||||||
a.apply(v, parent, handler, colorResources);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6042,6 +6010,47 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class to hold all the options when applying the remote views
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public class ActionApplyParams {
|
||||||
|
|
||||||
|
public InteractionHandler handler;
|
||||||
|
public ColorResources colorResources;
|
||||||
|
public Executor executor;
|
||||||
|
@StyleRes public int applyThemeResId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionApplyParams clone() {
|
||||||
|
return new ActionApplyParams()
|
||||||
|
.withInteractionHandler(handler)
|
||||||
|
.withColorResources(colorResources)
|
||||||
|
.withExecutor(executor)
|
||||||
|
.withThemeResId(applyThemeResId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionApplyParams withInteractionHandler(InteractionHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionApplyParams withColorResources(ColorResources colorResources) {
|
||||||
|
this.colorResources = colorResources;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionApplyParams withThemeResId(@StyleRes int themeResId) {
|
||||||
|
this.applyThemeResId = themeResId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionApplyParams withExecutor(Executor executor) {
|
||||||
|
this.executor = executor;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object allowing the modification of a context to overload the system's dynamic colors.
|
* Object allowing the modification of a context to overload the system's dynamic colors.
|
||||||
*
|
*
|
||||||
@@ -6056,10 +6065,12 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
// Size, in bytes, of an entry in the array of colors in an ARSC file.
|
// Size, in bytes, of an entry in the array of colors in an ARSC file.
|
||||||
private static final int ARSC_ENTRY_SIZE = 16;
|
private static final int ARSC_ENTRY_SIZE = 16;
|
||||||
|
|
||||||
private ResourcesLoader mLoader;
|
private final ResourcesLoader mLoader;
|
||||||
|
private final SparseIntArray mColorMapping;
|
||||||
|
|
||||||
private ColorResources(ResourcesLoader loader) {
|
private ColorResources(ResourcesLoader loader, SparseIntArray colorMapping) {
|
||||||
mLoader = loader;
|
mLoader = loader;
|
||||||
|
mColorMapping = colorMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6071,6 +6082,10 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
context.getResources().addLoaders(mLoader);
|
context.getResources().addLoaders(mLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SparseIntArray getColorMapping() {
|
||||||
|
return mColorMapping;
|
||||||
|
}
|
||||||
|
|
||||||
private static ByteArrayOutputStream readFileContent(InputStream input) throws IOException {
|
private static ByteArrayOutputStream readFileContent(InputStream input) throws IOException {
|
||||||
ByteArrayOutputStream content = new ByteArrayOutputStream(2048);
|
ByteArrayOutputStream content = new ByteArrayOutputStream(2048);
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
@@ -6145,7 +6160,7 @@ public class RemoteViews implements Parcelable, Filter {
|
|||||||
ResourcesLoader colorsLoader = new ResourcesLoader();
|
ResourcesLoader colorsLoader = new ResourcesLoader();
|
||||||
colorsLoader.addProvider(ResourcesProvider
|
colorsLoader.addProvider(ResourcesProvider
|
||||||
.loadFromTable(pfd, null /* assetsProvider */));
|
.loadFromTable(pfd, null /* assetsProvider */));
|
||||||
return new ColorResources(colorsLoader);
|
return new ColorResources(colorsLoader, colorMapping.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user