|
37 | 37 | import android.os.Parcelable; |
38 | 38 | import android.text.TextUtils; |
39 | 39 | import android.util.Log; |
| 40 | +import android.util.TypedValue; |
40 | 41 | import android.view.LayoutInflater; |
41 | 42 | import android.view.LayoutInflater.Filter; |
42 | 43 | import android.view.RemotableViewMethod; |
@@ -1181,6 +1182,45 @@ public void apply(View root, ViewGroup rootParent) { |
1181 | 1182 | public final static int TAG = 11; |
1182 | 1183 | } |
1183 | 1184 |
|
| 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 | + |
1184 | 1224 | /** |
1185 | 1225 | * Simple class used to keep track of memory usage in a RemoteViews. |
1186 | 1226 | * |
@@ -1334,6 +1374,9 @@ private RemoteViews(Parcel parcel, BitmapCache bitmapCache) { |
1334 | 1374 | case TextViewDrawableAction.TAG: |
1335 | 1375 | mActions.add(new TextViewDrawableAction(parcel)); |
1336 | 1376 | break; |
| 1377 | + case TextViewSizeAction.TAG: |
| 1378 | + mActions.add(new TextViewSizeAction(parcel)); |
| 1379 | + break; |
1337 | 1380 | case BitmapReflectionAction.TAG: |
1338 | 1381 | mActions.add(new BitmapReflectionAction(parcel)); |
1339 | 1382 | break; |
@@ -1541,7 +1584,19 @@ public void setViewVisibility(int viewId, int visibility) { |
1541 | 1584 | public void setTextViewText(int viewId, CharSequence text) { |
1542 | 1585 | setCharSequence(viewId, "setText", text); |
1543 | 1586 | } |
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 | + |
1545 | 1600 | /** |
1546 | 1601 | * Equivalent to calling |
1547 | 1602 | * {@link TextView#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)}. |
|
0 commit comments