summaryrefslogtreecommitdiff
path: root/core/java/android/widget/RemoteViews.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2010-08-15 18:20:04 -0700
committerAdam Cohen <adamcohen@google.com>2010-08-17 10:29:35 -0700
commit2dd2197805edb4d9547b143deef2226413218f4c (patch)
tree9ac6869e60bc425c276bce8c309aecdb1ebb450e /core/java/android/widget/RemoteViews.java
parent0c316eeb437a0ac1d6840690be643d1a553f0b23 (diff)
-> Enabled partial updates to app widgets through AppWidgetManager.
Partial updates are not cached by the AppWidgetService. -> Added the ability to insert commands with no parameters into RemoteViews objects. -> Added showNext() and showPrevious() methods to RemoteViews. -> Made showNext() / showPrevious() of AdapterViewFlipper remotable. Change-Id: Ic5491bb374424a54728c4ca92b94b1f00dfb87ff
Diffstat (limited to 'core/java/android/widget/RemoteViews.java')
-rw-r--r--core/java/android/widget/RemoteViews.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 50745dc05e50..f23a7239ede9 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -266,6 +266,63 @@ public class RemoteViews implements Parcelable, Filter {
public final static int TAG = 3;
}
+ private class ReflectionActionWithoutParams extends Action {
+ int viewId;
+ String methodName;
+
+ public final static int TAG = 5;
+
+ ReflectionActionWithoutParams(int viewId, String methodName) {
+ this.viewId = viewId;
+ this.methodName = methodName;
+ }
+
+ ReflectionActionWithoutParams(Parcel in) {
+ this.viewId = in.readInt();
+ this.methodName = in.readString();
+ }
+
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(TAG);
+ out.writeInt(this.viewId);
+ out.writeString(this.methodName);
+ }
+
+ @Override
+ public void apply(View root) {
+ final View view = root.findViewById(viewId);
+ if (view == null) {
+ throw new ActionException("can't find view: 0x" + Integer.toHexString(viewId));
+ }
+
+ Class klass = view.getClass();
+ Method method;
+ try {
+ method = klass.getMethod(this.methodName);
+ } catch (NoSuchMethodException ex) {
+ throw new ActionException("view: " + klass.getName() + " doesn't have method: "
+ + this.methodName + "()");
+ }
+
+ if (!method.isAnnotationPresent(RemotableViewMethod.class)) {
+ throw new ActionException("view: " + klass.getName()
+ + " can't use method with RemoteViews: "
+ + this.methodName + "()");
+ }
+
+ try {
+ //noinspection ConstantIfStatement
+ if (false) {
+ Log.d("RemoteViews", "view: " + klass.getName() + " calling method: "
+ + this.methodName + "()");
+ }
+ method.invoke(view);
+ } catch (Exception ex) {
+ throw new ActionException(ex);
+ }
+ }
+ }
+
/**
* Base class for the reflection actions.
*/
@@ -571,6 +628,9 @@ public class RemoteViews implements Parcelable, Filter {
case ViewGroupAction.TAG:
mActions.add(new ViewGroupAction(parcel));
break;
+ case ReflectionActionWithoutParams.TAG:
+ mActions.add(new ReflectionActionWithoutParams(parcel));
+ break;
default:
throw new ActionException("Tag " + tag + " not found");
}
@@ -632,6 +692,24 @@ public class RemoteViews implements Parcelable, Filter {
}
/**
+ * Equivalent to calling {@link AdapterViewFlipper#showNext()}
+ *
+ * @param viewId The id of the view on which to call {@link AdapterViewFlipper#showNext()}
+ */
+ public void showNext(int viewId) {
+ addAction(new ReflectionActionWithoutParams(viewId, "showNext"));
+ }
+
+ /**
+ * Equivalent to calling {@link AdapterViewFlipper#showPrevious()}
+ *
+ * @param viewId The id of the view on which to call {@link AdapterViewFlipper#showPrevious()}
+ */
+ public void showPrevious(int viewId) {
+ addAction(new ReflectionActionWithoutParams(viewId, "showPrevious"));
+ }
+
+ /**
* Equivalent to calling View.setVisibility
*
* @param viewId The id of the view whose visibility should change