7 package com.google.appinventor.components.runtime.util;
11 import android.content.res.ColorStateList;
12 import android.graphics.Typeface;
13 import android.view.Gravity;
14 import android.widget.TextView;
15 import android.text.Html;
16 import android.content.Context;
35 public static void setAlignment(TextView textview,
int alignment,
boolean centerVertically) {
36 int horizontalGravity;
39 throw new IllegalArgumentException();
42 horizontalGravity = Gravity.LEFT;
46 horizontalGravity = Gravity.CENTER_HORIZONTAL;
50 horizontalGravity = Gravity.RIGHT;
53 int verticalGravity = centerVertically ? Gravity.CENTER_VERTICAL : Gravity.TOP;
54 textview.setGravity(horizontalGravity | verticalGravity);
55 textview.invalidate();
67 textview.setBackgroundColor(argb);
68 textview.invalidate();
77 public static boolean isEnabled(TextView textview) {
78 return textview.isEnabled();
87 public static void setEnabled(TextView textview,
boolean enabled) {
88 textview.setEnabled(enabled);
89 textview.invalidate();
99 public static float getFontSize(TextView textview, Context context) {
100 float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
101 return textview.getTextSize()/scaledDensity;
111 textview.setTextSize(size);
112 textview.requestLayout();
127 boolean bold,
boolean italic) {
131 throw new IllegalArgumentException();
134 tf = Typeface.DEFAULT;
142 tf = Typeface.SANS_SERIF;
146 tf = Typeface.MONOSPACE;
152 style |= Typeface.BOLD;
155 style |= Typeface.ITALIC;
157 textview.setTypeface(Typeface.create(tf, style));
158 textview.requestLayout();
167 public static String
getText(TextView textview) {
168 return textview.getText().toString();
178 textview.setText(Html.fromHtml(text));
179 textview.requestLayout();
188 public static void setText(TextView textview, String text) {
189 textview.setText(text);
190 textview.requestLayout();
199 public static void setPadding(TextView textview,
int padding) {
200 textview.setPadding(padding, padding, 0, 0);
201 textview.requestLayout();
211 textview.setTextColor(argb);
212 textview.invalidate();
215 public static void setTextColors(TextView textview, ColorStateList colorStateList) {
216 textview.setTextColor(colorStateList);
228 textview.setMinWidth(minWidth);
229 textview.setMinimumWidth(minWidth);
241 textview.setMinHeight(minHeight);
242 textview.setMinimumHeight(minHeight);
252 public static void setMinSize(TextView textview,
int minWidth,
int minHeight) {