7 package com.google.appinventor.components.runtime;
20 import android.util.Log;
21 import android.view.View;
22 import android.widget.LinearLayout;
23 import android.widget.TextView;
33 @DesignerComponent(version = YaVersion.LABEL_COMPONENT_VERSION,
34 description =
"A Label displays a piece of text, which is " +
35 "specified through the <code>Text</code> property. Other properties, " +
36 "all of which can be set in the Designer or Blocks Editor, control " +
37 "the appearance and placement of the text.",
38 category = ComponentCategory.USERINTERFACE)
45 private static final int DEFAULT_LABEL_MARGIN = 2;
49 private int defaultLabelMarginInDp = 0;
51 private final TextView view;
53 private final LinearLayout.LayoutParams linearLayoutParams;
56 private int textAlignment;
59 private int backgroundColor;
62 private int fontTypeface;
68 private boolean italic;
71 private boolean hasMargins;
74 private int textColor;
77 private boolean htmlFormat;
80 private String htmlContent;
98 Object lp = view.getLayoutParams();
103 defaultLabelMarginInDp = dpToPx(view, DEFAULT_LABEL_MARGIN);
105 defaultLabelMarginInDp = 0;
106 linearLayoutParams =
null;
107 Log.e(
"Label",
"Error: The label's view does not have linear layout parameters");
108 new RuntimeException().printStackTrace();
124 private static int dpToPx(View view,
int dp) {
125 float density = view.getContext().getResources().getDisplayMetrics().density;
126 return Math.round((
float)dp * density);
147 return textAlignment;
164 this.textAlignment = alignment;
178 return backgroundColor;
191 backgroundColor = argb;
220 defaultValue =
"False")
249 defaultValue =
"False")
253 this.italic = italic;
264 description =
"Reports whether or not the label appears with margins. All four "
265 +
"margins (left, right, top, bottom) are the same. This property has no effect "
266 +
"in the designer, where labels are always shown with margins.",
281 defaultValue =
"True")
285 this.hasMargins = hasMargins;
286 setLabelMargins(hasMargins);
289 private void setLabelMargins(
boolean hasMargins) {
290 int m = hasMargins ? defaultLabelMarginInDp : 0 ;
291 linearLayoutParams.setMargins(m, m, m, m);
301 category = PropertyCategory.APPEARANCE)
348 fontTypeface = typeface;
371 public void Text(String text) {
404 description =
"If true, then this label will show html text else it " +
405 "will show plain text. Note: Not all HTML is supported.")
417 defaultValue =
"False")