FileDocCategorySizeDatePackage
RemoteViews.javaAPI DocAndroid 5.1 API104913Thu Mar 12 22:22:10 GMT 2015android.widget

RemoteViews

public class RemoteViews extends Object implements android.view.LayoutInflater.Filter, android.os.Parcelable
A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.

Fields Summary
private static final String
LOG_TAG
static final String
EXTRA_REMOTEADAPTER_APPWIDGET_ID
The intent extra that contains the appWidgetId.
private android.content.pm.ApplicationInfo
mApplication
Application that hosts the remote views.
private final int
mLayoutId
The resource ID of the layout file. (Added to the parcel)
private ArrayList
mActions
An array of actions to perform on the view tree once it has been inflated
private MemoryUsageCounter
mMemoryUsageCounter
A class to keep track of memory usage by this RemoteViews
private BitmapCache
mBitmapCache
Maps bitmaps to unique indicies to avoid Bitmap duplication.
private boolean
mIsRoot
Indicates whether or not this RemoteViews object is contained as a child of any other RemoteViews.
private static final int
MODE_NORMAL
Constants to whether or not this RemoteViews is composed of a landscape and portrait RemoteViews.
private static final int
MODE_HAS_LANDSCAPE_AND_PORTRAIT
private RemoteViews
mLandscape
Used in conjunction with the special constructor {@link #RemoteViews(RemoteViews, RemoteViews)} to keep track of the landscape and portrait RemoteViews.
private RemoteViews
mPortrait
private boolean
mIsWidgetCollectionChild
This flag indicates whether this RemoteViews object is being created from a RemoteViewsService for use as a child of a widget collection. This flag is used to determine whether or not certain features are available, in particular, setting on click extras and setting on click pending intents. The former is enabled, and the latter disabled when this flag is true.
private static final OnClickHandler
DEFAULT_ON_CLICK_HANDLER
private static final Object[]
sMethodsLock
private static final android.util.ArrayMap
sMethods
private static final ThreadLocal
sInvokeArgsTls
private final MutablePair
mPair
This pair is used to perform lookups in sMethods without causing allocations.
public static final Parcelable.Creator
CREATOR
Parcelable.Creator that instantiates RemoteViews objects
Constructors Summary
protected RemoteViews(android.content.pm.ApplicationInfo application, int layoutId)
Create a new RemoteViews object that will display the views contained in the specified layout file.

param
application The application whose content is shown by the views.
param
layoutId The id of the layout resource.
hide

        mApplication = application;
        mLayoutId = layoutId;
        mBitmapCache = new BitmapCache();
        // setup the memory usage statistics
        mMemoryUsageCounter = new MemoryUsageCounter();
        recalculateMemoryUsage();
    
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.

param
landscape The RemoteViews to inflate in landscape configuration
param
portrait The RemoteViews to inflate in portrait configuration

        if (landscape == null || portrait == null) {
            throw new RuntimeException("Both RemoteViews must be non-null");
        }
        if (landscape.mApplication.uid != portrait.mApplication.uid
                || !landscape.mApplication.packageName.equals(portrait.mApplication.packageName)) {
            throw new RuntimeException("Both RemoteViews must share the same package and user");
        }
        mApplication = portrait.mApplication;
        mLayoutId = portrait.getLayoutId();

        mLandscape = landscape;
        mPortrait = portrait;

        // setup the memory usage statistics
        mMemoryUsageCounter = new MemoryUsageCounter();

        mBitmapCache = new BitmapCache();
        configureRemoteViewsAsChild(landscape);
        configureRemoteViewsAsChild(portrait);

        recalculateMemoryUsage();
    
public RemoteViews(android.os.Parcel parcel)
Reads a RemoteViews object from a parcel.

param
parcel

        this(parcel, null);
    
private RemoteViews(android.os.Parcel parcel, BitmapCache bitmapCache)

        int mode = parcel.readInt();

        // We only store a bitmap cache in the root of the RemoteViews.
        if (bitmapCache == null) {
            mBitmapCache = new BitmapCache(parcel);
        } else {
            setBitmapCache(bitmapCache);
            setNotRoot();
        }

        if (mode == MODE_NORMAL) {
            mApplication = parcel.readParcelable(null);
            mLayoutId = parcel.readInt();
            mIsWidgetCollectionChild = parcel.readInt() == 1;

            int count = parcel.readInt();
            if (count > 0) {
                mActions = new ArrayList<Action>(count);
                for (int i=0; i<count; i++) {
                    int tag = parcel.readInt();
                    switch (tag) {
                        case SetOnClickPendingIntent.TAG:
                            mActions.add(new SetOnClickPendingIntent(parcel));
                            break;
                        case SetDrawableParameters.TAG:
                            mActions.add(new SetDrawableParameters(parcel));
                            break;
                        case ReflectionAction.TAG:
                            mActions.add(new ReflectionAction(parcel));
                            break;
                        case ViewGroupAction.TAG:
                            mActions.add(new ViewGroupAction(parcel, mBitmapCache));
                            break;
                        case ReflectionActionWithoutParams.TAG:
                            mActions.add(new ReflectionActionWithoutParams(parcel));
                            break;
                        case SetEmptyView.TAG:
                            mActions.add(new SetEmptyView(parcel));
                            break;
                        case SetPendingIntentTemplate.TAG:
                            mActions.add(new SetPendingIntentTemplate(parcel));
                            break;
                        case SetOnClickFillInIntent.TAG:
                            mActions.add(new SetOnClickFillInIntent(parcel));
                            break;
                        case SetRemoteViewsAdapterIntent.TAG:
                            mActions.add(new SetRemoteViewsAdapterIntent(parcel));
                            break;
                        case TextViewDrawableAction.TAG:
                            mActions.add(new TextViewDrawableAction(parcel));
                            break;
                        case TextViewSizeAction.TAG:
                            mActions.add(new TextViewSizeAction(parcel));
                            break;
                        case ViewPaddingAction.TAG:
                            mActions.add(new ViewPaddingAction(parcel));
                            break;
                        case BitmapReflectionAction.TAG:
                            mActions.add(new BitmapReflectionAction(parcel));
                            break;
                        case SetRemoteViewsAdapterList.TAG:
                            mActions.add(new SetRemoteViewsAdapterList(parcel));
                            break;
                        case TextViewDrawableColorFilterAction.TAG:
                            mActions.add(new TextViewDrawableColorFilterAction(parcel));
                            break;
                        default:
                            throw new ActionException("Tag " + tag + " not found");
                    }
                }
            }
        } else {
            // MODE_HAS_LANDSCAPE_AND_PORTRAIT
            mLandscape = new RemoteViews(parcel, mBitmapCache);
            mPortrait = new RemoteViews(parcel, mBitmapCache);
            mApplication = mPortrait.mApplication;
            mLayoutId = mPortrait.getLayoutId();
        }

        // setup the memory usage statistics
        mMemoryUsageCounter = new MemoryUsageCounter();
        recalculateMemoryUsage();
    
public RemoteViews(String packageName, int layoutId)
Create a new RemoteViews object that will display the views contained in the specified layout file.

param
packageName Name of the package that contains the layout resource
param
layoutId The id of the layout resource

        this(getApplicationInfo(packageName, UserHandle.myUserId()), layoutId);
    
public RemoteViews(String packageName, int userId, int layoutId)
Create a new RemoteViews object that will display the views contained in the specified layout file.

param
packageName Name of the package that contains the layout resource.
param
userId The user under which the package is running.
param
layoutId The id of the layout resource.
hide

        this(getApplicationInfo(packageName, userId), layoutId);
    
Methods Summary
private voidaddAction(android.widget.RemoteViews$Action a)
Add an action to be executed on the remote side when apply is called.

param
a The action to add

        if (hasLandscapeAndPortraitLayouts()) {
            throw new RuntimeException("RemoteViews specifying separate landscape and portrait" +
                    " layouts cannot be modified. Instead, fully configure the landscape and" +
                    " portrait layouts individually before constructing the combined layout.");
        }
        if (mActions == null) {
            mActions = new ArrayList<Action>();
        }
        mActions.add(a);

        // update the memory usage stats
        a.updateMemoryUsageEstimate(mMemoryUsageCounter);
    
public voidaddView(int viewId, android.widget.RemoteViews nestedView)
Equivalent to calling {@link ViewGroup#addView(View)} after inflating the given {@link RemoteViews}. This allows users to build "nested" {@link RemoteViews}. In cases where consumers of {@link RemoteViews} may recycle layouts, use {@link #removeAllViews(int)} to clear any existing children.

param
viewId The id of the parent {@link ViewGroup} to add child into.
param
nestedView {@link RemoteViews} that describes the child.

        addAction(new ViewGroupAction(viewId, nestedView));
    
public android.view.Viewapply(android.content.Context context, android.view.ViewGroup parent)
Inflates the view hierarchy represented by this object and applies all of the actions.

Caller beware: this may throw

param
context Default context to use
param
parent Parent that the resulting view hierarchy will be attached to. This method does not attach the hierarchy. The caller should do so when appropriate.
return
The inflated view hierarchy

        return apply(context, parent, null);
    
public android.view.Viewapply(android.content.Context context, android.view.ViewGroup parent, android.widget.RemoteViews$OnClickHandler handler)

hide

        RemoteViews rvToApply = getRemoteViewsToApply(context);

        View result;
        // RemoteViews may be built by an application installed in another
        // user. So build a context that loads resources from that user but
        // still returns the current users userId so settings like data / time formats
        // are loaded without requiring cross user persmissions.
        final Context contextForResources = getContextForResources(context);
        Context inflationContext = new ContextWrapper(context) {
            @Override
            public Resources getResources() {
                return contextForResources.getResources();
            }
            @Override
            public Resources.Theme getTheme() {
                return contextForResources.getTheme();
            }
        };

        LayoutInflater inflater = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // Clone inflater so we load resources from correct context and
        // we don't add a filter to the static version returned by getSystemService.
        inflater = inflater.cloneInContext(inflationContext);
        inflater.setFilter(this);
        result = inflater.inflate(rvToApply.getLayoutId(), parent, false);

        rvToApply.performApply(result, parent, handler);

        return result;
    
public android.widget.RemoteViewsclone()

        Parcel p = Parcel.obtain();
        writeToParcel(p, 0);
        p.setDataPosition(0);
        RemoteViews rv = new RemoteViews(p);
        p.recycle();
        return rv;
    
private voidconfigureRemoteViewsAsChild(android.widget.RemoteViews rv)

        mBitmapCache.assimilate(rv.mBitmapCache);
        rv.setBitmapCache(mBitmapCache);
        rv.setNotRoot();
    
public intdescribeContents()

        return 0;
    
public intestimateMemoryUsage()

hide

        return mMemoryUsageCounter.getMemoryUsage();
    
private static android.content.pm.ApplicationInfogetApplicationInfo(java.lang.String packageName, int userId)

        if (packageName == null) {
            return null;
        }

        // Get the application for the passed in package and user.
        Application application = ActivityThread.currentApplication();
        if (application == null) {
            throw new IllegalStateException("Cannot create remote views out of an aplication.");
        }

        ApplicationInfo applicationInfo = application.getApplicationInfo();
        if (UserHandle.getUserId(applicationInfo.uid) != userId
                || !applicationInfo.packageName.equals(packageName)) {
            try {
                Context context = application.getBaseContext().createPackageContextAsUser(
                        packageName, 0, new UserHandle(userId));
                applicationInfo = context.getApplicationInfo();
            } catch (NameNotFoundException nnfe) {
                throw new IllegalArgumentException("No such package " + packageName);
            }
        }

        return applicationInfo;
    
private android.content.ContextgetContextForResources(android.content.Context context)

        if (mApplication != null) {
            if (context.getUserId() == UserHandle.getUserId(mApplication.uid)
                    && context.getPackageName().equals(mApplication.packageName)) {
                return context;
            }
            try {
                return context.createApplicationContext(mApplication,
                        Context.CONTEXT_RESTRICTED);
            } catch (NameNotFoundException e) {
                Log.e(LOG_TAG, "Package name " + mApplication.packageName + " not found");
            }
        }

        return context;
    
public intgetLayoutId()
Reutrns the layout id of the root layout associated with this RemoteViews. In the case that the RemoteViews has both a landscape and portrait root, this will return the layout id associated with the portrait layout.

return
the layout id.

        return mLayoutId;
    
private java.lang.reflect.MethodgetMethod(android.view.View view, java.lang.String methodName, java.lang.Class paramType)

        Method method;
        Class<? extends View> klass = view.getClass();

        synchronized (sMethodsLock) {
            ArrayMap<MutablePair<String, Class<?>>, Method> methods = sMethods.get(klass);
            if (methods == null) {
                methods = new ArrayMap<MutablePair<String, Class<?>>, Method>();
                sMethods.put(klass, methods);
            }

            mPair.first = methodName;
            mPair.second = paramType;

            method = methods.get(mPair);
            if (method == null) {
                try {
                    if (paramType == null) {
                        method = klass.getMethod(methodName);
                    } else {
                        method = klass.getMethod(methodName, paramType);
                    }
                } catch (NoSuchMethodException ex) {
                    throw new ActionException("view: " + klass.getName() + " doesn't have method: "
                            + methodName + getParameters(paramType));
                }

                if (!method.isAnnotationPresent(RemotableViewMethod.class)) {
                    throw new ActionException("view: " + klass.getName()
                            + " can't use method with RemoteViews: "
                            + methodName + getParameters(paramType));
                }

                methods.put(new MutablePair<String, Class<?>>(methodName, paramType), method);
            }
        }

        return method;
    
public java.lang.StringgetPackage()

        return (mApplication != null) ? mApplication.packageName : null;
    
private static java.lang.StringgetParameters(java.lang.Class paramType)

        if (paramType == null) return "()";
        return "(" + paramType + ")";
    
private android.widget.RemoteViewsgetRemoteViewsToApply(android.content.Context context)

        if (hasLandscapeAndPortraitLayouts()) {
            int orientation = context.getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                return mLandscape;
            } else {
                return mPortrait;
            }
        }
        return this;
    
public intgetSequenceNumber()
Returns the number of actions in this RemoteViews. Can be used as a sequence number.

hide

        return (mActions == null) ? 0 : mActions.size();
    
private static android.graphics.RectgetSourceBounds(android.view.View v)

    

         
        final float appScale = v.getContext().getResources()
                .getCompatibilityInfo().applicationScale;
        final int[] pos = new int[2];
        v.getLocationOnScreen(pos);

        final Rect rect = new Rect();
        rect.left = (int) (pos[0] * appScale + 0.5f);
        rect.top = (int) (pos[1] * appScale + 0.5f);
        rect.right = (int) ((pos[0] + v.getWidth()) * appScale + 0.5f);
        rect.bottom = (int) ((pos[1] + v.getHeight()) * appScale + 0.5f);
        return rect;
    
private booleanhasLandscapeAndPortraitLayouts()

        return (mLandscape != null) && (mPortrait != null);
    
public voidmergeRemoteViews(android.widget.RemoteViews newRv)
Merges the passed RemoteViews actions with this RemoteViews actions according to action-specific merge rules.

param
newRv
hide

        if (newRv == null) return;
        // We first copy the new RemoteViews, as the process of merging modifies the way the actions
        // reference the bitmap cache. We don't want to modify the object as it may need to
        // be merged and applied multiple times.
        RemoteViews copy = newRv.clone();

        HashMap<String, Action> map = new HashMap<String, Action>();
        if (mActions == null) {
            mActions = new ArrayList<Action>();
        }

        int count = mActions.size();
        for (int i = 0; i < count; i++) {
            Action a = mActions.get(i);
            map.put(a.getUniqueKey(), a);
        }

        ArrayList<Action> newActions = copy.mActions;
        if (newActions == null) return;
        count = newActions.size();
        for (int i = 0; i < count; i++) {
            Action a = newActions.get(i);
            String key = newActions.get(i).getUniqueKey();
            int mergeBehavior = newActions.get(i).mergeBehavior();
            if (map.containsKey(key) && mergeBehavior == Action.MERGE_REPLACE) {
                mActions.remove(map.get(key));
                map.remove(key);
            }

            // If the merge behavior is ignore, we don't bother keeping the extra action
            if (mergeBehavior == Action.MERGE_REPLACE || mergeBehavior == Action.MERGE_APPEND) {
                mActions.add(a);
            }
        }

        // Because pruning can remove the need for bitmaps, we reconstruct the bitmap cache
        mBitmapCache = new BitmapCache();
        setBitmapCache(mBitmapCache);
    
public booleanonLoadClass(java.lang.Class clazz)

        return clazz.isAnnotationPresent(RemoteView.class);
    
private voidperformApply(android.view.View v, android.view.ViewGroup parent, android.widget.RemoteViews$OnClickHandler handler)

        if (mActions != null) {
            handler = handler == null ? DEFAULT_ON_CLICK_HANDLER : handler;
            final int count = mActions.size();
            for (int i = 0; i < count; i++) {
                Action a = mActions.get(i);
                a.apply(v, parent, handler);
            }
        }
    
public voidreapply(android.content.Context context, android.view.View v)
Applies all of the actions to the provided view.

Caller beware: this may throw

param
v The view to apply the actions to. This should be the result of the {@link #apply(Context,ViewGroup)} call.

        reapply(context, v, null);
    
public voidreapply(android.content.Context context, android.view.View v, android.widget.RemoteViews$OnClickHandler handler)

hide

        RemoteViews rvToApply = getRemoteViewsToApply(context);

        // In the case that a view has this RemoteViews applied in one orientation, is persisted
        // across orientation change, and has the RemoteViews re-applied in the new orientation,
        // we throw an exception, since the layouts may be completely unrelated.
        if (hasLandscapeAndPortraitLayouts()) {
            if (v.getId() != rvToApply.getLayoutId()) {
                throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" +
                        " that does not share the same root layout id.");
            }
        }

        rvToApply.performApply(v, (ViewGroup) v.getParent(), handler);
    
private voidrecalculateMemoryUsage()
Updates the memory usage statistics.

        mMemoryUsageCounter.clear();

        if (!hasLandscapeAndPortraitLayouts()) {
            // Accumulate the memory usage for each action
            if (mActions != null) {
                final int count = mActions.size();
                for (int i= 0; i < count; ++i) {
                    mActions.get(i).updateMemoryUsageEstimate(mMemoryUsageCounter);
                }
            }
            if (mIsRoot) {
                mBitmapCache.addBitmapMemory(mMemoryUsageCounter);
            }
        } else {
            mMemoryUsageCounter.increment(mLandscape.estimateMemoryUsage());
            mMemoryUsageCounter.increment(mPortrait.estimateMemoryUsage());
            mBitmapCache.addBitmapMemory(mMemoryUsageCounter);
        }
    
public voidremoveAllViews(int viewId)
Equivalent to calling {@link ViewGroup#removeAllViews()}.

param
viewId The id of the parent {@link ViewGroup} to remove all children from.

        addAction(new ViewGroupAction(viewId, null));
    
public voidsetAccessibilityTraversalAfter(int viewId, int nextId)
Equivalent to calling {@link android.view.View#setAccessibilityTraversalAfter(int)}.

param
viewId The id of the view whose after view in accessibility traversal to set.
param
nextId The id of the next in the accessibility traversal.

        setInt(viewId, "setAccessibilityTraversalAfter", nextId);
    
public voidsetAccessibilityTraversalBefore(int viewId, int nextId)
Equivalent to calling {@link android.view.View#setAccessibilityTraversalBefore(int)}.

param
viewId The id of the view whose before view in accessibility traversal to set.
param
nextId The id of the next in the accessibility traversal.

        setInt(viewId, "setAccessibilityTraversalBefore", nextId);
    
public voidsetBitmap(int viewId, java.lang.String methodName, android.graphics.Bitmap value)
Call a method taking one Bitmap on a view in the layout for this RemoteViews.

more

The bitmap will be flattened into the parcel if this object is sent across processes, so it may end up using a lot of memory, and may be fairly slow.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new BitmapReflectionAction(viewId, methodName, value));
    
private voidsetBitmapCache(android.widget.RemoteViews$BitmapCache bitmapCache)
Recursively sets BitmapCache in the hierarchy and update the bitmap ids.

        mBitmapCache = bitmapCache;
        if (!hasLandscapeAndPortraitLayouts()) {
            if (mActions != null) {
                final int count = mActions.size();
                for (int i= 0; i < count; ++i) {
                    mActions.get(i).setBitmapCache(bitmapCache);
                }
            }
        } else {
            mLandscape.setBitmapCache(bitmapCache);
            mPortrait.setBitmapCache(bitmapCache);
        }
    
public voidsetBoolean(int viewId, java.lang.String methodName, boolean value)
Call a method taking one boolean on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BOOLEAN, value));
    
public voidsetBundle(int viewId, java.lang.String methodName, android.os.Bundle value)
Call a method taking one Bundle on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BUNDLE, value));
    
public voidsetByte(int viewId, java.lang.String methodName, byte value)
Call a method taking one byte on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BYTE, value));
    
public voidsetChar(int viewId, java.lang.String methodName, char value)
Call a method taking one char on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.CHAR, value));
    
public voidsetCharSequence(int viewId, java.lang.String methodName, java.lang.CharSequence value)
Call a method taking one CharSequence on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.CHAR_SEQUENCE, value));
    
public voidsetChronometer(int viewId, long base, java.lang.String format, boolean started)
Equivalent to calling {@link Chronometer#setBase Chronometer.setBase}, {@link Chronometer#setFormat Chronometer.setFormat}, and {@link Chronometer#start Chronometer.start()} or {@link Chronometer#stop Chronometer.stop()}.

param
viewId The id of the {@link Chronometer} to change
param
base The time at which the timer would have read 0:00. This time should be based off of {@link android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime()}.
param
format The Chronometer format string, or null to simply display the timer value.
param
started True if you want the clock to be started, false if not.

        setLong(viewId, "setBase", base);
        setString(viewId, "setFormat", format);
        setBoolean(viewId, "setStarted", started);
    
public voidsetContentDescription(int viewId, java.lang.CharSequence contentDescription)
Equivalent to calling View.setContentDescription(CharSequence).

param
viewId The id of the view whose content description should change.
param
contentDescription The new content description for the view.

        setCharSequence(viewId, "setContentDescription", contentDescription);
    
public voidsetDisplayedChild(int viewId, int childIndex)
Equivalent to calling {@link AdapterViewAnimator#setDisplayedChild(int)}

param
viewId The id of the view on which to call {@link AdapterViewAnimator#setDisplayedChild(int)}

        setInt(viewId, "setDisplayedChild", childIndex);
    
public voidsetDouble(int viewId, java.lang.String methodName, double value)
Call a method taking one double on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.DOUBLE, value));
    
public voidsetDrawableParameters(int viewId, boolean targetBackground, int alpha, int colorFilter, PorterDuff.Mode mode, int level)

hide
Equivalent to calling a combination of {@link Drawable#setAlpha(int)}, {@link Drawable#setColorFilter(int, android.graphics.PorterDuff.Mode)}, and/or {@link Drawable#setLevel(int)} on the {@link Drawable} of a given view.

You can omit specific calls by marking their values with null or -1.

param
viewId The id of the view that contains the target {@link Drawable}
param
targetBackground If true, apply these parameters to the {@link Drawable} returned by {@link android.view.View#getBackground()}. Otherwise, assume the target view is an {@link ImageView} and apply them to {@link ImageView#getDrawable()}.
param
alpha Specify an alpha value for the drawable, or -1 to leave unchanged.
param
colorFilter Specify a color for a {@link android.graphics.ColorFilter} for this drawable. This will be ignored if {@code mode} is {@code null}.
param
mode Specify a PorterDuff mode for this drawable, or null to leave unchanged.
param
level Specify the level for the drawable, or -1 to leave unchanged.

        addAction(new SetDrawableParameters(viewId, targetBackground, alpha,
                colorFilter, mode, level));
    
public voidsetEmptyView(int viewId, int emptyViewId)
Equivalent to calling AdapterView.setEmptyView

param
viewId The id of the view on which to set the empty view
param
emptyViewId The view id of the empty view

        addAction(new SetEmptyView(viewId, emptyViewId));
    
public voidsetFloat(int viewId, java.lang.String methodName, float value)
Call a method taking one float on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.FLOAT, value));
    
public voidsetImageViewBitmap(int viewId, android.graphics.Bitmap bitmap)
Equivalent to calling ImageView.setImageBitmap

param
viewId The id of the view whose bitmap should change
param
bitmap The new Bitmap for the drawable

        setBitmap(viewId, "setImageBitmap", bitmap);
    
public voidsetImageViewResource(int viewId, int srcId)
Equivalent to calling ImageView.setImageResource

param
viewId The id of the view whose drawable should change
param
srcId The new resource id for the drawable

        setInt(viewId, "setImageResource", srcId);
    
public voidsetImageViewUri(int viewId, android.net.Uri uri)
Equivalent to calling ImageView.setImageURI

param
viewId The id of the view whose drawable should change
param
uri The Uri for the image

        setUri(viewId, "setImageURI", uri);
    
public voidsetInt(int viewId, java.lang.String methodName, int value)
Call a method taking one int on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.INT, value));
    
public voidsetIntent(int viewId, java.lang.String methodName, android.content.Intent value)
Call a method taking one Intent on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The {@link android.content.Intent} to pass the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.INTENT, value));
    
voidsetIsWidgetCollectionChild(boolean isWidgetCollectionChild)

        mIsWidgetCollectionChild = isWidgetCollectionChild;
    
public voidsetLabelFor(int viewId, int labeledId)
Equivalent to calling View.setLabelFor(int).

param
viewId The id of the view whose property to set.
param
labeledId The id of a view for which this view serves as a label.

        setInt(viewId, "setLabelFor", labeledId);
    
public voidsetLong(int viewId, java.lang.String methodName, long value)
Call a method taking one long on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.LONG, value));
    
voidsetNotRoot()

        mIsRoot = false;
    
public voidsetOnClickFillInIntent(int viewId, android.content.Intent fillInIntent)
When using collections (eg. {@link ListView}, {@link StackView} etc.) in widgets, it is very costly to set PendingIntents on the individual items, and is hence not permitted. Instead a single PendingIntent template can be set on the collection, see {@link RemoteViews#setPendingIntentTemplate(int, PendingIntent)}, and the individual on-click action of a given item can be distinguished by setting a fillInIntent on that item. The fillInIntent is then combined with the PendingIntent template in order to determine the final intent which will be executed when the item is clicked. This works as follows: any fields which are left blank in the PendingIntent template, but are provided by the fillInIntent will be overwritten, and the resulting PendingIntent will be used. of the PendingIntent template will then be filled in with the associated fields that are set in fillInIntent. See {@link Intent#fillIn(Intent, int)} for more details.

param
viewId The id of the view on which to set the fillInIntent
param
fillInIntent The intent which will be combined with the parent's PendingIntent in order to determine the on-click behavior of the view specified by viewId

        addAction(new SetOnClickFillInIntent(viewId, fillInIntent));
    
public voidsetOnClickPendingIntent(int viewId, android.app.PendingIntent pendingIntent)
Equivalent to calling {@link android.view.View#setOnClickListener(android.view.View.OnClickListener)} to launch the provided {@link PendingIntent}. When setting the on-click action of items within collections (eg. {@link ListView}, {@link StackView} etc.), this method will not work. Instead, use {@link RemoteViews#setPendingIntentTemplate(int, PendingIntent) in conjunction with RemoteViews#setOnClickFillInIntent(int, Intent).

param
viewId The id of the view that will trigger the {@link PendingIntent} when clicked
param
pendingIntent The {@link PendingIntent} to send when user clicks

        addAction(new SetOnClickPendingIntent(viewId, pendingIntent));
    
public voidsetPendingIntentTemplate(int viewId, android.app.PendingIntent pendingIntentTemplate)
When using collections (eg. {@link ListView}, {@link StackView} etc.) in widgets, it is very costly to set PendingIntents on the individual items, and is hence not permitted. Instead this method should be used to set a single PendingIntent template on the collection, and individual items can differentiate their on-click behavior using {@link RemoteViews#setOnClickFillInIntent(int, Intent)}.

param
viewId The id of the collection who's children will use this PendingIntent template when clicked
param
pendingIntentTemplate The {@link PendingIntent} to be combined with extras specified by a child of viewId and executed when that child is clicked

        addAction(new SetPendingIntentTemplate(viewId, pendingIntentTemplate));
    
public voidsetProgressBackgroundTintList(int viewId, android.content.res.ColorStateList tint)

hide
Equivalent to calling {@link android.widget.ProgressBar#setProgressBackgroundTintList}.
param
viewId The id of the view whose tint should change
param
tint the tint to apply, may be {@code null} to clear tint

        addAction(new ReflectionAction(viewId, "setProgressBackgroundTintList",
                ReflectionAction.COLOR_STATE_LIST, tint));
    
public voidsetProgressBar(int viewId, int max, int progress, boolean indeterminate)
Equivalent to calling {@link ProgressBar#setMax ProgressBar.setMax}, {@link ProgressBar#setProgress ProgressBar.setProgress}, and {@link ProgressBar#setIndeterminate ProgressBar.setIndeterminate} If indeterminate is true, then the values for max and progress are ignored.

param
viewId The id of the {@link ProgressBar} to change
param
max The 100% value for the progress bar
param
progress The current value of the progress bar.
param
indeterminate True if the progress bar is indeterminate, false if not.

        setBoolean(viewId, "setIndeterminate", indeterminate);
        if (!indeterminate) {
            setInt(viewId, "setMax", max);
            setInt(viewId, "setProgress", progress);
        }
    
public voidsetProgressIndeterminateTintList(int viewId, android.content.res.ColorStateList tint)

hide
Equivalent to calling {@link android.widget.ProgressBar#setIndeterminateTintList}.
param
viewId The id of the view whose tint should change
param
tint the tint to apply, may be {@code null} to clear tint

        addAction(new ReflectionAction(viewId, "setIndeterminateTintList",
                ReflectionAction.COLOR_STATE_LIST, tint));
    
public voidsetProgressTintList(int viewId, android.content.res.ColorStateList tint)

hide
Equivalent to calling {@link android.widget.ProgressBar#setProgressTintList}.
param
viewId The id of the view whose tint should change
param
tint the tint to apply, may be {@code null} to clear tint

        addAction(new ReflectionAction(viewId, "setProgressTintList",
                ReflectionAction.COLOR_STATE_LIST, tint));
    
public voidsetRelativeScrollPosition(int viewId, int offset)
Equivalent to calling {@link android.widget.AbsListView#smoothScrollToPosition(int, int)}.

param
viewId The id of the view to change
param
offset Scroll by this adapter position offset

        setInt(viewId, "smoothScrollByOffset", offset);
    
public voidsetRemoteAdapter(int appWidgetId, int viewId, android.content.Intent intent)
Equivalent to calling {@link android.widget.AbsListView#setRemoteViewsAdapter(Intent)}.

param
appWidgetId The id of the app widget which contains the specified view. (This parameter is ignored in this deprecated method)
param
viewId The id of the {@link AdapterView}
param
intent The intent of the service which will be providing data to the RemoteViewsAdapter
deprecated
This method has been deprecated. See {@link android.widget.RemoteViews#setRemoteAdapter(int, Intent)}

        setRemoteAdapter(viewId, intent);
    
public voidsetRemoteAdapter(int viewId, android.content.Intent intent)
Equivalent to calling {@link android.widget.AbsListView#setRemoteViewsAdapter(Intent)}. Can only be used for App Widgets.

param
viewId The id of the {@link AdapterView}
param
intent The intent of the service which will be providing data to the RemoteViewsAdapter

        addAction(new SetRemoteViewsAdapterIntent(viewId, intent));
    
public voidsetRemoteAdapter(int viewId, java.util.ArrayList list, int viewTypeCount)
Creates a simple Adapter for the viewId specified. The viewId must point to an AdapterView, ie. {@link ListView}, {@link GridView}, {@link StackView} or {@link AdapterViewAnimator}. This is a simpler but less flexible approach to populating collection widgets. Its use is encouraged for most scenarios, as long as the total memory within the list of RemoteViews is relatively small (ie. doesn't contain large or numerous Bitmaps, see {@link RemoteViews#setImageViewBitmap}). In the case of numerous images, the use of API is still possible by setting image URIs instead of Bitmaps, see {@link RemoteViews#setImageViewUri}. This API is supported in the compatibility library for previous API levels, see RemoteViewsCompat.

param
viewId The id of the {@link AdapterView}
param
list The list of RemoteViews which will populate the view specified by viewId.
param
viewTypeCount The maximum number of unique layout id's used to construct the list of RemoteViews. This count cannot change during the life-cycle of a given widget, so this parameter should account for the maximum possible number of types that may appear in the See {@link Adapter#getViewTypeCount()}.
hide

        addAction(new SetRemoteViewsAdapterList(viewId, list, viewTypeCount));
    
public voidsetScrollPosition(int viewId, int position)
Equivalent to calling {@link android.widget.AbsListView#smoothScrollToPosition(int, int)}.

param
viewId The id of the view to change
param
position Scroll to this adapter position

        setInt(viewId, "smoothScrollToPosition", position);
    
public voidsetShort(int viewId, java.lang.String methodName, short value)
Call a method taking one short on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.SHORT, value));
    
public voidsetString(int viewId, java.lang.String methodName, java.lang.String value)
Call a method taking one String on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.STRING, value));
    
public voidsetTextColor(int viewId, int color)
Equivalent to calling {@link android.widget.TextView#setTextColor(int)}.

param
viewId The id of the view whose text color should change
param
color Sets the text color for all the states (normal, selected, focused) to be this color.

        setInt(viewId, "setTextColor", color);
    
public voidsetTextViewCompoundDrawables(int viewId, int left, int top, int right, int bottom)
Equivalent to calling {@link TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)}.

param
viewId The id of the view whose text should change
param
left The id of a drawable to place to the left of the text, or 0
param
top The id of a drawable to place above the text, or 0
param
right The id of a drawable to place to the right of the text, or 0
param
bottom The id of a drawable to place below the text, or 0

        addAction(new TextViewDrawableAction(viewId, false, left, top, right, bottom));
    
public voidsetTextViewCompoundDrawablesRelative(int viewId, int start, int top, int end, int bottom)
Equivalent to calling {@link TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int, int)}.

param
viewId The id of the view whose text should change
param
start The id of a drawable to place before the text (relative to the layout direction), or 0
param
top The id of a drawable to place above the text, or 0
param
end The id of a drawable to place after the text, or 0
param
bottom The id of a drawable to place below the text, or 0

        addAction(new TextViewDrawableAction(viewId, true, start, top, end, bottom));
    
public voidsetTextViewCompoundDrawablesRelativeColorFilter(int viewId, int index, int color, PorterDuff.Mode mode)
Equivalent to applying a color filter on one of the drawables in {@link android.widget.TextView#getCompoundDrawablesRelative()}.

param
viewId The id of the view whose text should change.
param
index The index of the drawable in the array of {@link android.widget.TextView#getCompoundDrawablesRelative()} to set the color filter on. Must be in [0, 3].
param
color The color of the color filter. See {@link Drawable#setColorFilter(int, android.graphics.PorterDuff.Mode)}.
param
mode The mode of the color filter. See {@link Drawable#setColorFilter(int, android.graphics.PorterDuff.Mode)}.
hide

        if (index < 0 || index >= 4) {
            throw new IllegalArgumentException("index must be in range [0, 3].");
        }
        addAction(new TextViewDrawableColorFilterAction(viewId, true, index, color, mode));
    
public voidsetTextViewText(int viewId, java.lang.CharSequence text)
Equivalent to calling TextView.setText

param
viewId The id of the view whose text should change
param
text The new text for the view

        setCharSequence(viewId, "setText", text);
    
public voidsetTextViewTextSize(int viewId, int units, float size)
Equivalent to calling {@link TextView#setTextSize(int, float)}

param
viewId The id of the view whose text size should change
param
units The units of size (e.g. COMPLEX_UNIT_SP)
param
size The size of the text

        addAction(new TextViewSizeAction(viewId, units, size));
    
public voidsetUri(int viewId, java.lang.String methodName, android.net.Uri value)
Call a method taking one Uri on a view in the layout for this RemoteViews.

param
viewId The id of the view on which to call the method.
param
methodName The name of the method to call.
param
value The value to pass to the method.

        if (value != null) {
            // Resolve any filesystem path before sending remotely
            value = value.getCanonicalUri();
            if (StrictMode.vmFileUriExposureEnabled()) {
                value.checkFileUriExposed("RemoteViews.setUri()");
            }
        }
        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.URI, value));
    
public voidsetViewPadding(int viewId, int left, int top, int right, int bottom)
Equivalent to calling {@link android.view.View#setPadding(int, int, int, int)}.

param
viewId The id of the view to change
param
left the left padding in pixels
param
top the top padding in pixels
param
right the right padding in pixels
param
bottom the bottom padding in pixels

        addAction(new ViewPaddingAction(viewId, left, top, right, bottom));
    
public voidsetViewVisibility(int viewId, int visibility)
Equivalent to calling View.setVisibility

param
viewId The id of the view whose visibility should change
param
visibility The new visibility for the view

        setInt(viewId, "setVisibility", visibility);
    
public voidshowNext(int viewId)
Equivalent to calling {@link AdapterViewAnimator#showNext()}

param
viewId The id of the view on which to call {@link AdapterViewAnimator#showNext()}

        addAction(new ReflectionActionWithoutParams(viewId, "showNext"));
    
public voidshowPrevious(int viewId)
Equivalent to calling {@link AdapterViewAnimator#showPrevious()}

param
viewId The id of the view on which to call {@link AdapterViewAnimator#showPrevious()}

        addAction(new ReflectionActionWithoutParams(viewId, "showPrevious"));
    
private static java.lang.Object[]wrapArg(java.lang.Object value)

        Object[] args = sInvokeArgsTls.get();
        args[0] = value;
        return args;
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        if (!hasLandscapeAndPortraitLayouts()) {
            dest.writeInt(MODE_NORMAL);
            // We only write the bitmap cache if we are the root RemoteViews, as this cache
            // is shared by all children.
            if (mIsRoot) {
                mBitmapCache.writeBitmapsToParcel(dest, flags);
            }
            dest.writeParcelable(mApplication, flags);
            dest.writeInt(mLayoutId);
            dest.writeInt(mIsWidgetCollectionChild ? 1 : 0);
            int count;
            if (mActions != null) {
                count = mActions.size();
            } else {
                count = 0;
            }
            dest.writeInt(count);
            for (int i=0; i<count; i++) {
                Action a = mActions.get(i);
                a.writeToParcel(dest, 0);
            }
        } else {
            dest.writeInt(MODE_HAS_LANDSCAPE_AND_PORTRAIT);
            // We only write the bitmap cache if we are the root RemoteViews, as this cache
            // is shared by all children.
            if (mIsRoot) {
                mBitmapCache.writeBitmapsToParcel(dest, flags);
            }
            mLandscape.writeToParcel(dest, flags);
            mPortrait.writeToParcel(dest, flags);
        }