From 2dd2197805edb4d9547b143deef2226413218f4c Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Sun, 15 Aug 2010 18:20:04 -0700 Subject: -> 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 --- core/java/android/widget/RemoteViews.java | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'core/java/android/widget/RemoteViews.java') 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"); } @@ -631,6 +691,24 @@ public class RemoteViews implements Parcelable, Filter { addAction(new ViewGroupAction(viewId, null)); } + /** + * 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 * -- cgit v1.2.3