7 package com.google.appinventor.components.runtime;
12 import android.content.Context;
13 import android.view.ViewGroup;
22 private final android.widget.LinearLayout layoutManager;
33 this(context, orientation,
null,
null);
46 LinearLayout(Context context,
int orientation,
final Integer preferredEmptyWidth,
47 final Integer preferredEmptyHeight) {
48 if (preferredEmptyWidth ==
null && preferredEmptyHeight !=
null ||
49 preferredEmptyWidth !=
null && preferredEmptyHeight ==
null) {
50 throw new IllegalArgumentException(
"LinearLayout - preferredEmptyWidth and " +
51 "preferredEmptyHeight must be either both null or both not null");
56 layoutManager =
new android.widget.LinearLayout(context) {
58 protected void onMeasure(
int widthMeasureSpec,
int heightMeasureSpec) {
61 if (preferredEmptyWidth ==
null || preferredEmptyHeight ==
null) {
62 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
67 if (getChildCount() != 0) {
68 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
72 setMeasuredDimension(getSize(widthMeasureSpec, preferredEmptyWidth),
73 getSize(heightMeasureSpec, preferredEmptyHeight));
76 private int getSize(
int measureSpec,
int preferredSize) {
78 int specMode = MeasureSpec.getMode(measureSpec);
79 int specSize = MeasureSpec.getSize(measureSpec);
81 if (specMode == MeasureSpec.EXACTLY) {
86 result = preferredSize;
87 if (specMode == MeasureSpec.AT_MOST) {
89 result = Math.min(result, specSize);
97 layoutManager.setOrientation(
99 android.widget.LinearLayout.HORIZONTAL : android.widget.LinearLayout.VERTICAL);
105 return layoutManager;
109 layoutManager.addView(component.
getView(),
new android.widget.LinearLayout.LayoutParams(
110 ViewGroup.LayoutParams.WRAP_CONTENT,
111 ViewGroup.LayoutParams.WRAP_CONTENT,