Skip to content

Commit 820ba32

Browse files
committed
Add remotable methods for TextView's compound drawables.
Change-Id: I67445e5b1d4a571020dfcd551ab00bd83a8eb536
1 parent 7cf4640 commit 820ba32

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27270,6 +27270,8 @@ package android.widget {
2727027270
method public void setShort(int, java.lang.String, short);
2727127271
method public void setString(int, java.lang.String, java.lang.String);
2727227272
method public void setTextColor(int, int);
27273+
method public void setTextViewCompoundDrawables(int, int, int, int, int);
27274+
method public void setTextViewCompoundDrawablesRelative(int, int, int, int, int);
2727327275
method public void setTextViewText(int, java.lang.CharSequence);
2727427276
method public void setUri(int, java.lang.String, android.net.Uri);
2727527277
method public void setViewVisibility(int, int);

core/java/android/widget/RemoteViews.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,58 @@ public void updateMemoryUsageEstimate(MemoryUsageCounter counter) {
964964
public final static int TAG = 4;
965965
}
966966

967+
/**
968+
* Helper action to set compound drawables on a TextView. Supports relative
969+
* (s/t/e/b) or cardinal (l/t/r/b) arrangement.
970+
*/
971+
private class TextViewDrawableAction extends Action {
972+
public TextViewDrawableAction(int viewId, boolean isRelative, int d1, int d2, int d3, int d4) {
973+
this.viewId = viewId;
974+
this.isRelative = isRelative;
975+
this.d1 = d1;
976+
this.d2 = d2;
977+
this.d3 = d3;
978+
this.d4 = d4;
979+
}
980+
981+
public TextViewDrawableAction(Parcel parcel) {
982+
viewId = parcel.readInt();
983+
isRelative = (parcel.readInt() != 0);
984+
d1 = parcel.readInt();
985+
d2 = parcel.readInt();
986+
d3 = parcel.readInt();
987+
d4 = parcel.readInt();
988+
}
989+
990+
public void writeToParcel(Parcel dest, int flags) {
991+
dest.writeInt(TAG);
992+
dest.writeInt(viewId);
993+
dest.writeInt(isRelative ? 1 : 0);
994+
dest.writeInt(d1);
995+
dest.writeInt(d2);
996+
dest.writeInt(d3);
997+
dest.writeInt(d4);
998+
}
999+
1000+
@Override
1001+
public void apply(View root, ViewGroup rootParent) {
1002+
final Context context = root.getContext();
1003+
final TextView target = (TextView) root.findViewById(viewId);
1004+
if (target == null) return;
1005+
if (isRelative) {
1006+
target.setCompoundDrawablesRelativeWithIntrinsicBounds(d1, d2, d3, d4);
1007+
} else {
1008+
target.setCompoundDrawablesWithIntrinsicBounds(d1, d2, d3, d4);
1009+
}
1010+
}
1011+
1012+
int viewId;
1013+
boolean isRelative = false;
1014+
int d1, d2, d3, d4;
1015+
1016+
public final static int TAG = 11;
1017+
}
1018+
9671019
/**
9681020
* Simple class used to keep track of memory usage in a RemoteViews.
9691021
*
@@ -1043,6 +1095,9 @@ public RemoteViews(Parcel parcel) {
10431095
case SetRemoteViewsAdapterIntent.TAG:
10441096
mActions.add(new SetRemoteViewsAdapterIntent(parcel));
10451097
break;
1098+
case TextViewDrawableAction.TAG:
1099+
mActions.add(new TextViewDrawableAction(parcel));
1100+
break;
10461101
default:
10471102
throw new ActionException("Tag " + tag + " not found");
10481103
}
@@ -1194,6 +1249,35 @@ public void setTextViewText(int viewId, CharSequence text) {
11941249
setCharSequence(viewId, "setText", text);
11951250
}
11961251

1252+
/**
1253+
* Equivalent to calling
1254+
* {@link TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)}.
1255+
*
1256+
* @param viewId The id of the view whose text should change
1257+
* @param left The id of a drawable to place to the left of the text, or 0
1258+
* @param top The id of a drawable to place above the text, or 0
1259+
* @param right The id of a drawable to place to the right of the text, or 0
1260+
* @param bottom The id of a drawable to place below the text, or 0
1261+
*/
1262+
public void setTextViewCompoundDrawables(int viewId, int left, int top, int right, int bottom) {
1263+
addAction(new TextViewDrawableAction(viewId, false, left, top, right, bottom));
1264+
}
1265+
1266+
/**
1267+
* Equivalent to calling {@link
1268+
* TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int, int)}.
1269+
*
1270+
* @param viewId The id of the view whose text should change
1271+
* @param start The id of a drawable to place before the text (relative to the
1272+
* layout direction), or 0
1273+
* @param top The id of a drawable to place above the text, or 0
1274+
* @param end The id of a drawable to place after the text, or 0
1275+
* @param bottom The id of a drawable to place below the text, or 0
1276+
*/
1277+
public void setTextViewCompoundDrawablesRelative(int viewId, int start, int top, int end, int bottom) {
1278+
addAction(new TextViewDrawableAction(viewId, true, start, top, end, bottom));
1279+
}
1280+
11971281
/**
11981282
* Equivalent to calling ImageView.setImageResource
11991283
*

core/java/android/widget/TextView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ public void setCompoundDrawables(Drawable left, Drawable top,
17981798
* @attr ref android.R.styleable#TextView_drawableRight
17991799
* @attr ref android.R.styleable#TextView_drawableBottom
18001800
*/
1801+
@android.view.RemotableViewMethod
18011802
public void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) {
18021803
final Resources resources = getContext().getResources();
18031804
setCompoundDrawablesWithIntrinsicBounds(left != 0 ? resources.getDrawable(left) : null,
@@ -1967,6 +1968,7 @@ public void setCompoundDrawablesRelative(Drawable start, Drawable top,
19671968
* @attr ref android.R.styleable#TextView_drawableEnd
19681969
* @attr ref android.R.styleable#TextView_drawableBottom
19691970
*/
1971+
@android.view.RemotableViewMethod
19701972
public void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end,
19711973
int bottom) {
19721974
resetResolvedDrawables();
@@ -2042,6 +2044,7 @@ public Drawable[] getCompoundDrawablesRelative() {
20422044
*
20432045
* @attr ref android.R.styleable#TextView_drawablePadding
20442046
*/
2047+
@android.view.RemotableViewMethod
20452048
public void setCompoundDrawablePadding(int pad) {
20462049
Drawables dr = mDrawables;
20472050
if (pad == 0) {

0 commit comments

Comments
 (0)