FileDocCategorySizeDatePackage
RemoteViews.javaAPI DocAndroid 1.5 API32939Wed May 06 22:41:56 BST 2009android.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
private String
mPackage
The package name of the package containing the layout resource. (Added to the parcel)
private int
mLayoutId
The resource ID of the layout file. (Added to the parcel)
private android.content.Context
mContext
The Context object used to inflate the layout file. Also may be used by actions if they need access to the senders resources.
private ArrayList
mActions
An array of actions to perform on the view tree once it has been inflated
public static final Parcelable.Creator
CREATOR
Parcelable.Creator that instantiates RemoteViews objects
Constructors Summary
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

        mPackage = packageName;
        mLayoutId = layoutId;
    
public RemoteViews(android.os.Parcel parcel)
Reads a RemoteViews object from a parcel.

param
parcel

        mPackage = parcel.readString();
        mLayoutId = parcel.readInt();
        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;
                default:
                    throw new ActionException("Tag " + tag + " not found");
                }
            }
        }
    
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 (mActions == null) {
            mActions = new ArrayList<Action>();
        }
        mActions.add(a);
    
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

        View result = null;

        Context c = prepareContext(context);

        Resources r = c.getResources();
        LayoutInflater inflater = (LayoutInflater) c
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        inflater = inflater.cloneInContext(c);
        inflater.setFilter(this);

        result = inflater.inflate(mLayoutId, parent, false);

        performApply(result);

        return result;
    
public intdescribeContents()

        return 0;
    
public intgetLayoutId()

        return mLayoutId;
    
public java.lang.StringgetPackage()

        return mPackage;
    
public booleanonLoadClass(java.lang.Class clazz)

        return clazz.isAnnotationPresent(RemoteView.class);
    
private voidperformApply(android.view.View v)

        if (mActions != null) {
            final int count = mActions.size();
            for (int i = 0; i < count; i++) {
                Action a = mActions.get(i);
                a.apply(v);
            }
        }
    
private android.content.ContextprepareContext(android.content.Context context)

        Context c = null;
        String packageName = mPackage;

        if (packageName != null) {
            try {
                c = context.createPackageContext(packageName, 0);
            } catch (NameNotFoundException e) {
                Log.e(LOG_TAG, "Package name " + packageName + " not found");
                c = context;
            }
        } else {
            c = context;
        }

        mContext = c;

        return c;
    
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.

        prepareContext(context);
        performApply(v);
    
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 whose text should change
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BITMAP, value));
    
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 whose text should change
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 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 whose text should change
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 whose text should change
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 whose text should change
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 view whose text should 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 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 whose text should change
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, or -1 to leave unchanged.
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 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 whose text should change
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 drawable 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 whose text should change
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 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 whose text should change
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));
    
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}.

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 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 view whose text should 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 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 whose text should change
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 whose text should change
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 should change
param
color Sets the text color for all the states (normal, selected, focused) to be this color.

        setInt(viewId, "setTextColor", color);
    
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 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 whose text should change
param
methodName The name of the method to call.
param
value The value to pass to the method.

        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.URI, value));
    
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 voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeString(mPackage);
        dest.writeInt(mLayoutId);
        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);
        }