7 package com.google.appinventor.components.runtime;
9 import android.app.Activity;
11 import android.graphics.drawable.Drawable;
13 import android.os.Handler;
15 import android.util.Log;
17 import android.view.View;
18 import android.view.ViewGroup;
20 import android.widget.FrameLayout;
21 import android.widget.HorizontalScrollView;
22 import android.widget.ScrollView;
37 import java.io.IOException;
49 private final Activity context;
52 private final int orientation;
54 private ViewGroup frameContainer;
55 private boolean scrollable =
false;
60 private int horizontalAlignment;
61 private int verticalAlignment;
63 private int backgroundColor;
66 private Drawable backgroundImageDrawable;
68 private String imagePath =
"";
70 private Drawable defaultButtonDrawable;
72 private final Handler androidUIHandler =
new Handler();
74 private static final String LOG_TAG =
"HVArrangement";
88 this.orientation = orientation;
89 this.scrollable = scrollable;
102 switch (orientation) {
104 Log.d(LOG_TAG,
"Setting up frameContainer = ScrollView()");
105 frameContainer =
new ScrollView(context);
108 Log.d(LOG_TAG,
"Setting up frameContainer = HorizontalScrollView()");
109 frameContainer =
new HorizontalScrollView(context);
113 Log.d(LOG_TAG,
"Setting up frameContainer = FrameLayout()");
114 frameContainer =
new FrameLayout(context);
118 frameContainer.addView(viewLayout.
getLayoutManager(),
new ViewGroup.LayoutParams(
119 ViewGroup.LayoutParams.MATCH_PARENT,
120 ViewGroup.LayoutParams.MATCH_PARENT));
123 defaultButtonDrawable =
getView().getBackground();
146 viewLayout.
add(component);
156 if (cWidth == 0 && trycount < 2) {
157 final int fWidth = width;
158 androidUIHandler.postDelayed(
new Runnable() {
161 Log.d(LOG_TAG,
"(HVArrangement)Width not stable yet... trying again");
167 Log.d(LOG_TAG,
"HVArrangement.setChildWidth(): width = " + width +
" parent Width = " + cWidth +
" child = " + component);
184 final int fHeight = height;
185 androidUIHandler.postDelayed(
new Runnable() {
188 Log.d(LOG_TAG,
"(HVArrangement)Height not stable yet... trying again");
210 return frameContainer;
221 description =
"A number that encodes how contents of the %type% are aligned " +
222 " horizontally. The choices are: 1 = left aligned, 2 = right aligned, " +
223 " 3 = horizontally centered. Alignment has no effect if the arrangement's width is " +
226 return horizontalAlignment;
244 horizontalAlignment = alignment;
245 }
catch (IllegalArgumentException e) {
258 description =
"A number that encodes how the contents of the %type% are aligned " +
259 " vertically. The choices are: 1 = aligned at the top, 2 = vertically centered, " +
260 "3 = aligned at the bottom. Alignment has no effect if the arrangement's height " +
263 return verticalAlignment;
281 verticalAlignment = alignment;
282 }
catch (IllegalArgumentException e) {
295 description =
"Returns the background color of the %type%")
297 return backgroundColor;
312 @
SimpleProperty(description =
"Specifies the background color of the %type%. " +
313 "The background color will not be visible if an Image is being displayed.")
315 backgroundColor = argb;
342 @
SimpleProperty(description =
"Specifies the path of the background image for the %type%. " +
343 "If there is both an Image and a BackgroundColor, only the Image will be visible.")
347 if (path.equals(imagePath) && backgroundImageDrawable !=
null) {
351 imagePath = (path ==
null) ?
"" : path;
354 backgroundImageDrawable =
null;
357 if (imagePath.length() > 0) {
360 }
catch (IOException ioe) {
372 private void updateAppearance() {
375 if (backgroundImageDrawable ==
null) {
387 ViewUtil.setBackgroundImage(viewLayout.
getLayoutManager(), backgroundImageDrawable);