diff options
author | Daniel Sandler <dsandler@android.com> | 2012-05-21 16:14:14 -0400 |
---|---|---|
committer | Daniel Sandler <dsandler@android.com> | 2012-05-21 16:15:06 -0400 |
commit | 99d1f74864c3449585690f85a5fe6fb36ef796d5 (patch) | |
tree | bd62d71286bc3c6be961ae61b300df98d1948560 | |
parent | 7264f71399018e2dd79d974ee5162cf652ac786f (diff) | |
download | frameworks_base-99d1f74864c3449585690f85a5fe6fb36ef796d5.zip frameworks_base-99d1f74864c3449585690f85a5fe6fb36ef796d5.tar.gz frameworks_base-99d1f74864c3449585690f85a5fe6fb36ef796d5.tar.bz2 |
Add RemoteViews.setViewPadding().
Bug: 6519374
Change-Id: I29ad738d741153a9d9e74c9e2ac110a8b97f046b
-rw-r--r-- | core/java/android/widget/RemoteViews.java | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 529a09a..1985792 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -1183,8 +1183,7 @@ public class RemoteViews implements Parcelable, Filter { } /** - * Helper action to set compound drawables on a TextView. Supports relative - * (s/t/e/b) or cardinal (l/t/r/b) arrangement. + * Helper action to set text size on a TextView in any supported units. */ private class TextViewSizeAction extends Action { public TextViewSizeAction(int viewId, int units, float size) { @@ -1222,6 +1221,49 @@ public class RemoteViews implements Parcelable, Filter { } /** + * Helper action to set padding on a View. + */ + private class ViewPaddingAction extends Action { + public ViewPaddingAction(int viewId, int left, int top, int right, int bottom) { + this.viewId = viewId; + this.left = left; + this.top = top; + this.right = right; + this.bottom = bottom; + } + + public ViewPaddingAction(Parcel parcel) { + viewId = parcel.readInt(); + left = parcel.readInt(); + top = parcel.readInt(); + right = parcel.readInt(); + bottom = parcel.readInt(); + } + + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(TAG); + dest.writeInt(viewId); + dest.writeInt(left); + dest.writeInt(top); + dest.writeInt(right); + dest.writeInt(bottom); + } + + @Override + public void apply(View root, ViewGroup rootParent) { + final Context context = root.getContext(); + final View target = root.findViewById(viewId); + if (target == null) return; + target.setPadding(left, top, right, bottom); + } + + int viewId; + int left, top, right, bottom; + + public final static int TAG = 14; + } + + /** * Simple class used to keep track of memory usage in a RemoteViews. * */ @@ -1377,6 +1419,9 @@ public class RemoteViews implements Parcelable, Filter { 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; @@ -1854,6 +1899,20 @@ public class RemoteViews implements Parcelable, Filter { } /** + * @hide + * Equivalent to calling {@link 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 + */ + public void setViewPadding(int viewId, int left, int top, int right, int bottom) { + addAction(new ViewPaddingAction(viewId, left, top, right, bottom)); + } + + /** * 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. |