Loading core/java/android/widget/RemoteViews.java +100 −50 Original line number Diff line number Diff line Loading @@ -1905,31 +1905,49 @@ public class RemoteViews implements Parcelable, Filter { } @Override protected @NonNull Object getParameterValue(View view) throws ActionException { protected Object getParameterValue(View view) throws ActionException { Resources resources = view.getContext().getResources(); try { switch (this.mResourceType) { case DIMEN_RESOURCE: if (this.type == BaseReflectionAction.INT) { return resources.getDimensionPixelSize(this.mResId); switch (this.type) { case BaseReflectionAction.INT: return mResId == 0 ? 0 : resources.getDimensionPixelSize(mResId); case BaseReflectionAction.FLOAT: return mResId == 0 ? 0f : resources.getDimension(mResId); default: throw new ActionException( "dimen resources must be used as INT or FLOAT, " + "not " + this.type); } return resources.getDimension(this.mResId); case COLOR_RESOURCE: switch (this.type) { case BaseReflectionAction.INT: return view.getContext().getColor(this.mResId); return mResId == 0 ? 0 : view.getContext().getColor(mResId); case BaseReflectionAction.COLOR_STATE_LIST: return view.getContext().getColorStateList(this.mResId); return mResId == 0 ? null : view.getContext().getColorStateList(mResId); default: throw new ActionException( "color resources must be used as int or ColorStateList, " "color resources must be used as INT or COLOR_STATE_LIST," + " not " + this.type); } case STRING_RESOURCE: return resources.getText(this.mResId); switch (this.type) { case BaseReflectionAction.CHAR_SEQUENCE: return mResId == 0 ? null : resources.getText(mResId); case BaseReflectionAction.STRING: return mResId == 0 ? null : resources.getString(mResId); default: throw new ActionException( "string resources must be used as STRING or CHAR_SEQUENCE," + " not " + this.type); } default: throw new ActionException("unknown resource type: " + this.mResourceType); } } catch (ActionException ex) { throw ex; } catch (Throwable t) { throw new ActionException(t); } Loading Loading @@ -1971,21 +1989,27 @@ public class RemoteViews implements Parcelable, Filter { } @Override protected @NonNull Object getParameterValue(View view) throws ActionException { try { TypedArray typedArray = view.getContext().obtainStyledAttributes( new int[]{this.mAttrId}); protected Object getParameterValue(View view) throws ActionException { TypedArray typedArray = view.getContext().obtainStyledAttributes(new int[]{mAttrId}); try { if (typedArray.getType(0) == TypedValue.TYPE_NULL) { // When mAttrId == 0, we will depend on the default values below if (mAttrId != 0 && typedArray.getType(0) == TypedValue.TYPE_NULL) { throw new ActionException("Attribute 0x" + Integer.toHexString(this.mAttrId) + " is not defined"); } switch (this.mResourceType) { case DIMEN_RESOURCE: if (this.type == BaseReflectionAction.INT) { switch (this.type) { case BaseReflectionAction.INT: return typedArray.getDimensionPixelSize(0, 0); } case BaseReflectionAction.FLOAT: return typedArray.getDimension(0, 0); default: throw new ActionException( "dimen attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as INT or FLOAT," + " not " + this.type); } case COLOR_RESOURCE: switch (this.type) { case BaseReflectionAction.INT: Loading @@ -1994,27 +2018,33 @@ public class RemoteViews implements Parcelable, Filter { return typedArray.getColorStateList(0); default: throw new ActionException( "Color attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as int or ColorStateList"); "color attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as INT or COLOR_STATE_LIST," + " not " + this.type); } case STRING_RESOURCE: String value = typedArray.getString(0); if (value == null) { throw new ActionException("Attribute 0x" + Integer.toHexString(this.mAttrId) + " is not a defined or is not a string"); switch (this.type) { case BaseReflectionAction.CHAR_SEQUENCE: return typedArray.getText(0); case BaseReflectionAction.STRING: return typedArray.getString(0); default: throw new ActionException( "string attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as STRING or CHAR_SEQUENCE," + " not " + this.type); } return value; default: // Note: This can only be an implementation error. throw new ActionException( "Unknown resource type: " + this.mResourceType); } } finally { typedArray.recycle(); } } catch (ActionException ex) { throw ex; } catch (Throwable t) { throw new ActionException(t); } finally { typedArray.recycle(); } } Loading Loading @@ -4519,7 +4549,7 @@ public class RemoteViews implements Parcelable, Filter { * * @param viewId The id of the view to change * @param type The margin being set e.g. {@link #MARGIN_END} * @param attr a dimension attribute to apply to the margin. * @param attr a dimension attribute to apply to the margin, or 0 to clear the margin. */ public void setViewLayoutMarginAttr(@IdRes int viewId, @MarginType int type, @AttrRes int attr) { Loading Loading @@ -4702,6 +4732,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenResource The resource to resolve and pass as argument to the method. Loading Loading @@ -4736,6 +4768,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the theme attribute at the time the * {@link RemoteViews} is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenAttr The attribute to resolve and pass as argument to the method. Loading @@ -4752,6 +4786,8 @@ public class RemoteViews implements Parcelable, Filter { * The Color will be resolved from the resources at the time the {@link RemoteViews} is (re-) * applied. * * Undefined resources will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorResource The resource to resolve and pass as argument to the method. Loading @@ -4768,6 +4804,8 @@ public class RemoteViews implements Parcelable, Filter { * The Color will be resolved from the theme attribute at the time the {@link RemoteViews} is * (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorAttribute The theme attribute to resolve and pass as argument to the method. Loading Loading @@ -4846,6 +4884,8 @@ public class RemoteViews implements Parcelable, Filter { * The ColorStateList will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorResource The resource to resolve and pass as argument to the method. Loading @@ -4863,6 +4903,8 @@ public class RemoteViews implements Parcelable, Filter { * The ColorStateList will be resolved from the theme attribute at the time the * {@link RemoteViews} is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorAttr The theme attribute to resolve and pass as argument to the method. Loading Loading @@ -4903,6 +4945,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to 0f. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenResource The resource to resolve and pass as argument to the method. Loading Loading @@ -4939,6 +4983,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the theme attribute at the time the {@link RemoteViews} * is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to 0f. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenAttr The attribute to resolve and pass as argument to the method. Loading Loading @@ -5000,6 +5046,8 @@ public class RemoteViews implements Parcelable, Filter { * The CharSequence will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param stringResource The resource to resolve and pass as argument to the method. Loading @@ -5017,6 +5065,8 @@ public class RemoteViews implements Parcelable, Filter { * The CharSequence will be resolved from the theme attribute at the time the * {@link RemoteViews} is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param stringAttribute The attribute to resolve and pass as argument to the method. Loading Loading
core/java/android/widget/RemoteViews.java +100 −50 Original line number Diff line number Diff line Loading @@ -1905,31 +1905,49 @@ public class RemoteViews implements Parcelable, Filter { } @Override protected @NonNull Object getParameterValue(View view) throws ActionException { protected Object getParameterValue(View view) throws ActionException { Resources resources = view.getContext().getResources(); try { switch (this.mResourceType) { case DIMEN_RESOURCE: if (this.type == BaseReflectionAction.INT) { return resources.getDimensionPixelSize(this.mResId); switch (this.type) { case BaseReflectionAction.INT: return mResId == 0 ? 0 : resources.getDimensionPixelSize(mResId); case BaseReflectionAction.FLOAT: return mResId == 0 ? 0f : resources.getDimension(mResId); default: throw new ActionException( "dimen resources must be used as INT or FLOAT, " + "not " + this.type); } return resources.getDimension(this.mResId); case COLOR_RESOURCE: switch (this.type) { case BaseReflectionAction.INT: return view.getContext().getColor(this.mResId); return mResId == 0 ? 0 : view.getContext().getColor(mResId); case BaseReflectionAction.COLOR_STATE_LIST: return view.getContext().getColorStateList(this.mResId); return mResId == 0 ? null : view.getContext().getColorStateList(mResId); default: throw new ActionException( "color resources must be used as int or ColorStateList, " "color resources must be used as INT or COLOR_STATE_LIST," + " not " + this.type); } case STRING_RESOURCE: return resources.getText(this.mResId); switch (this.type) { case BaseReflectionAction.CHAR_SEQUENCE: return mResId == 0 ? null : resources.getText(mResId); case BaseReflectionAction.STRING: return mResId == 0 ? null : resources.getString(mResId); default: throw new ActionException( "string resources must be used as STRING or CHAR_SEQUENCE," + " not " + this.type); } default: throw new ActionException("unknown resource type: " + this.mResourceType); } } catch (ActionException ex) { throw ex; } catch (Throwable t) { throw new ActionException(t); } Loading Loading @@ -1971,21 +1989,27 @@ public class RemoteViews implements Parcelable, Filter { } @Override protected @NonNull Object getParameterValue(View view) throws ActionException { try { TypedArray typedArray = view.getContext().obtainStyledAttributes( new int[]{this.mAttrId}); protected Object getParameterValue(View view) throws ActionException { TypedArray typedArray = view.getContext().obtainStyledAttributes(new int[]{mAttrId}); try { if (typedArray.getType(0) == TypedValue.TYPE_NULL) { // When mAttrId == 0, we will depend on the default values below if (mAttrId != 0 && typedArray.getType(0) == TypedValue.TYPE_NULL) { throw new ActionException("Attribute 0x" + Integer.toHexString(this.mAttrId) + " is not defined"); } switch (this.mResourceType) { case DIMEN_RESOURCE: if (this.type == BaseReflectionAction.INT) { switch (this.type) { case BaseReflectionAction.INT: return typedArray.getDimensionPixelSize(0, 0); } case BaseReflectionAction.FLOAT: return typedArray.getDimension(0, 0); default: throw new ActionException( "dimen attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as INT or FLOAT," + " not " + this.type); } case COLOR_RESOURCE: switch (this.type) { case BaseReflectionAction.INT: Loading @@ -1994,27 +2018,33 @@ public class RemoteViews implements Parcelable, Filter { return typedArray.getColorStateList(0); default: throw new ActionException( "Color attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as int or ColorStateList"); "color attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as INT or COLOR_STATE_LIST," + " not " + this.type); } case STRING_RESOURCE: String value = typedArray.getString(0); if (value == null) { throw new ActionException("Attribute 0x" + Integer.toHexString(this.mAttrId) + " is not a defined or is not a string"); switch (this.type) { case BaseReflectionAction.CHAR_SEQUENCE: return typedArray.getText(0); case BaseReflectionAction.STRING: return typedArray.getString(0); default: throw new ActionException( "string attribute 0x" + Integer.toHexString(this.mAttrId) + " must be used as STRING or CHAR_SEQUENCE," + " not " + this.type); } return value; default: // Note: This can only be an implementation error. throw new ActionException( "Unknown resource type: " + this.mResourceType); } } finally { typedArray.recycle(); } } catch (ActionException ex) { throw ex; } catch (Throwable t) { throw new ActionException(t); } finally { typedArray.recycle(); } } Loading Loading @@ -4519,7 +4549,7 @@ public class RemoteViews implements Parcelable, Filter { * * @param viewId The id of the view to change * @param type The margin being set e.g. {@link #MARGIN_END} * @param attr a dimension attribute to apply to the margin. * @param attr a dimension attribute to apply to the margin, or 0 to clear the margin. */ public void setViewLayoutMarginAttr(@IdRes int viewId, @MarginType int type, @AttrRes int attr) { Loading Loading @@ -4702,6 +4732,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenResource The resource to resolve and pass as argument to the method. Loading Loading @@ -4736,6 +4768,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the theme attribute at the time the * {@link RemoteViews} is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenAttr The attribute to resolve and pass as argument to the method. Loading @@ -4752,6 +4786,8 @@ public class RemoteViews implements Parcelable, Filter { * The Color will be resolved from the resources at the time the {@link RemoteViews} is (re-) * applied. * * Undefined resources will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorResource The resource to resolve and pass as argument to the method. Loading @@ -4768,6 +4804,8 @@ public class RemoteViews implements Parcelable, Filter { * The Color will be resolved from the theme attribute at the time the {@link RemoteViews} is * (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to 0. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorAttribute The theme attribute to resolve and pass as argument to the method. Loading Loading @@ -4846,6 +4884,8 @@ public class RemoteViews implements Parcelable, Filter { * The ColorStateList will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorResource The resource to resolve and pass as argument to the method. Loading @@ -4863,6 +4903,8 @@ public class RemoteViews implements Parcelable, Filter { * The ColorStateList will be resolved from the theme attribute at the time the * {@link RemoteViews} is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param colorAttr The theme attribute to resolve and pass as argument to the method. Loading Loading @@ -4903,6 +4945,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to 0f. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenResource The resource to resolve and pass as argument to the method. Loading Loading @@ -4939,6 +4983,8 @@ public class RemoteViews implements Parcelable, Filter { * The dimension will be resolved from the theme attribute at the time the {@link RemoteViews} * is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to 0f. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param dimenAttr The attribute to resolve and pass as argument to the method. Loading Loading @@ -5000,6 +5046,8 @@ public class RemoteViews implements Parcelable, Filter { * The CharSequence will be resolved from the resources at the time the {@link RemoteViews} is * (re-)applied. * * Undefined resources will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param stringResource The resource to resolve and pass as argument to the method. Loading @@ -5017,6 +5065,8 @@ public class RemoteViews implements Parcelable, Filter { * The CharSequence will be resolved from the theme attribute at the time the * {@link RemoteViews} is (re-)applied. * * Unresolvable attributes will result in an exception, except 0 which will resolve to null. * * @param viewId The id of the view on which to call the method. * @param methodName The name of the method to call. * @param stringAttribute The attribute to resolve and pass as argument to the method. Loading