RemoteViewspublic class RemoteViews extends Object implements android.view.LayoutInflater.Filter, android.os.ParcelableA 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 | mPackageThe package name of the package containing the layout
resource. (Added to the parcel) | private int | mLayoutIdThe resource ID of the layout file. (Added to the parcel) | private android.content.Context | mContextThe Context object used to inflate the layout file. Also may
be used by actions if they need access to the senders resources. | private ArrayList | mActionsAn array of actions to perform on the view tree once it has been
inflated | public static final Parcelable.Creator | CREATORParcelable.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.
mPackage = packageName;
mLayoutId = layoutId;
| public RemoteViews(android.os.Parcel parcel)Reads a RemoteViews object from a 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 void | addAction(android.widget.RemoteViews$Action a)Add an action to be executed on the remote side when apply is called.
if (mActions == null) {
mActions = new ArrayList<Action>();
}
mActions.add(a);
| public android.view.View | apply(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
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 int | describeContents()
return 0;
| public int | getLayoutId()
return mLayoutId;
| public java.lang.String | getPackage()
return mPackage;
| public boolean | onLoadClass(java.lang.Class clazz)
return clazz.isAnnotationPresent(RemoteView.class);
| private void | performApply(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.Context | prepareContext(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 void | reapply(android.content.Context context, android.view.View v)Applies all of the actions to the provided view.
Caller beware: this may throw
prepareContext(context);
performApply(v);
| public void | setBitmap(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.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BITMAP, value));
| public void | setBoolean(int viewId, java.lang.String methodName, boolean value)Call a method taking one boolean on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BOOLEAN, value));
| public void | setByte(int viewId, java.lang.String methodName, byte value)Call a method taking one byte on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.BYTE, value));
| public void | setChar(int viewId, java.lang.String methodName, char value)Call a method taking one char on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.CHAR, value));
| public void | setCharSequence(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.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.CHAR_SEQUENCE, value));
| public void | setChronometer(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()}.
setLong(viewId, "setBase", base);
setString(viewId, "setFormat", format);
setBoolean(viewId, "setStarted", started);
| public void | setDouble(int viewId, java.lang.String methodName, double value)Call a method taking one double on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.DOUBLE, value));
| public void | setDrawableParameters(int viewId, boolean targetBackground, int alpha, int colorFilter, PorterDuff.Mode mode, int level)
addAction(new SetDrawableParameters(viewId, targetBackground, alpha,
colorFilter, mode, level));
| public void | setFloat(int viewId, java.lang.String methodName, float value)Call a method taking one float on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.FLOAT, value));
| public void | setImageViewBitmap(int viewId, android.graphics.Bitmap bitmap)Equivalent to calling ImageView.setImageBitmap
setBitmap(viewId, "setImageBitmap", bitmap);
| public void | setImageViewResource(int viewId, int srcId)Equivalent to calling ImageView.setImageResource
setInt(viewId, "setImageResource", srcId);
| public void | setImageViewUri(int viewId, android.net.Uri uri)Equivalent to calling ImageView.setImageURI
setUri(viewId, "setImageURI", uri);
| public void | setInt(int viewId, java.lang.String methodName, int value)Call a method taking one int on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.INT, value));
| public void | setLong(int viewId, java.lang.String methodName, long value)Call a method taking one long on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.LONG, value));
| public void | setOnClickPendingIntent(int viewId, android.app.PendingIntent pendingIntent)Equivalent to calling
{@link android.view.View#setOnClickListener(android.view.View.OnClickListener)}
to launch the provided {@link PendingIntent}.
addAction(new SetOnClickPendingIntent(viewId, pendingIntent));
| public void | setProgressBar(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.
setBoolean(viewId, "setIndeterminate", indeterminate);
if (!indeterminate) {
setInt(viewId, "setMax", max);
setInt(viewId, "setProgress", progress);
}
| public void | setShort(int viewId, java.lang.String methodName, short value)Call a method taking one short on a view in the layout for this RemoteViews.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.SHORT, value));
| public void | setString(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.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.STRING, value));
| public void | setTextColor(int viewId, int color)Equivalent to calling {@link android.widget.TextView#setTextColor(int)}.
setInt(viewId, "setTextColor", color);
| public void | setTextViewText(int viewId, java.lang.CharSequence text)Equivalent to calling TextView.setText
setCharSequence(viewId, "setText", text);
| public void | setUri(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.
addAction(new ReflectionAction(viewId, methodName, ReflectionAction.URI, value));
| public void | setViewVisibility(int viewId, int visibility)Equivalent to calling View.setVisibility
setInt(viewId, "setVisibility", visibility);
| public void | writeToParcel(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);
}
|
|