Skip to content

Commit 90497c1

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Remotable view method for TextView.setTextSize(int, float)." into jb-dev
2 parents bfa3d50 + 7264f71 commit 90497c1

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

core/java/android/widget/RemoteViews.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.os.Parcelable;
3838
import android.text.TextUtils;
3939
import android.util.Log;
40+
import android.util.TypedValue;
4041
import android.view.LayoutInflater;
4142
import android.view.LayoutInflater.Filter;
4243
import android.view.RemotableViewMethod;
@@ -1181,6 +1182,45 @@ public void apply(View root, ViewGroup rootParent) {
11811182
public final static int TAG = 11;
11821183
}
11831184

1185+
/**
1186+
* Helper action to set compound drawables on a TextView. Supports relative
1187+
* (s/t/e/b) or cardinal (l/t/r/b) arrangement.
1188+
*/
1189+
private class TextViewSizeAction extends Action {
1190+
public TextViewSizeAction(int viewId, int units, float size) {
1191+
this.viewId = viewId;
1192+
this.units = units;
1193+
this.size = size;
1194+
}
1195+
1196+
public TextViewSizeAction(Parcel parcel) {
1197+
viewId = parcel.readInt();
1198+
units = parcel.readInt();
1199+
size = parcel.readFloat();
1200+
}
1201+
1202+
public void writeToParcel(Parcel dest, int flags) {
1203+
dest.writeInt(TAG);
1204+
dest.writeInt(viewId);
1205+
dest.writeInt(units);
1206+
dest.writeFloat(size);
1207+
}
1208+
1209+
@Override
1210+
public void apply(View root, ViewGroup rootParent) {
1211+
final Context context = root.getContext();
1212+
final TextView target = (TextView) root.findViewById(viewId);
1213+
if (target == null) return;
1214+
target.setTextSize(units, size);
1215+
}
1216+
1217+
int viewId;
1218+
int units;
1219+
float size;
1220+
1221+
public final static int TAG = 13;
1222+
}
1223+
11841224
/**
11851225
* Simple class used to keep track of memory usage in a RemoteViews.
11861226
*
@@ -1334,6 +1374,9 @@ private RemoteViews(Parcel parcel, BitmapCache bitmapCache) {
13341374
case TextViewDrawableAction.TAG:
13351375
mActions.add(new TextViewDrawableAction(parcel));
13361376
break;
1377+
case TextViewSizeAction.TAG:
1378+
mActions.add(new TextViewSizeAction(parcel));
1379+
break;
13371380
case BitmapReflectionAction.TAG:
13381381
mActions.add(new BitmapReflectionAction(parcel));
13391382
break;
@@ -1541,7 +1584,19 @@ public void setViewVisibility(int viewId, int visibility) {
15411584
public void setTextViewText(int viewId, CharSequence text) {
15421585
setCharSequence(viewId, "setText", text);
15431586
}
1544-
1587+
1588+
/**
1589+
* @hide
1590+
* Equivalent to calling {@link TextView#setTextSize(int, float)}
1591+
*
1592+
* @param viewId The id of the view whose text size should change
1593+
* @param units The units of size (e.g. COMPLEX_UNIT_SP)
1594+
* @param size The size of the text
1595+
*/
1596+
public void setTextViewTextSize(int viewId, int units, float size) {
1597+
addAction(new TextViewSizeAction(viewId, units, size));
1598+
}
1599+
15451600
/**
15461601
* Equivalent to calling
15471602
* {@link TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)}.

0 commit comments

Comments
 (0)