diff --git a/src/org/nativescript/widgets/CommonLayoutParams.java b/src/org/nativescript/widgets/CommonLayoutParams.java index 79028628c..6e99a6e2c 100644 --- a/src/org/nativescript/widgets/CommonLayoutParams.java +++ b/src/org/nativescript/widgets/CommonLayoutParams.java @@ -20,7 +20,7 @@ import android.widget.FrameLayout; */ public class CommonLayoutParams extends FrameLayout.LayoutParams { - static final String tag = "NSLayout"; + static final String TAG = "NSLayout"; static int debuggable = -1; private static final StringBuilder sb = new StringBuilder(); @@ -154,7 +154,7 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { sb.append(MeasureSpec.toString(widthMeasureSpec)); sb.append(", "); sb.append(MeasureSpec.toString(heightMeasureSpec)); - log(tag, sb.toString()); + log(TAG, sb.toString()); } child.measure(widthMeasureSpec, heightMeasureSpec); @@ -174,7 +174,7 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { sb.append(childRight); sb.append(", "); sb.append(childBottom); - log(tag, sb.toString()); + log(TAG, sb.toString()); } child.layout(childLeft, childTop, childRight, childBottom); @@ -188,13 +188,18 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { // Negative means not initialized. if(debuggable < 0) { try { - Context context = child.getContext(); - int flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags; - debuggable = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 ? 1 : 0; - } - catch (NameNotFoundException e) { - debuggable = 0; - } + Context context = child.getContext(); + ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), android.content.pm.PackageManager.GET_META_DATA); + android.os.Bundle bundle = ai.metaData; + Boolean debugLayouts = bundle != null ? bundle.getBoolean("debugLayouts", false) : false; + debuggable = debugLayouts ? 1 : 0; + } catch (NameNotFoundException e) { + debuggable = 0; + Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage()); + } catch (NullPointerException e) { + debuggable = 0; + Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage()); + } } int childWidthMeasureSpec = getMeasureSpec(child, widthMeasureSpec, true); @@ -209,7 +214,7 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { sb.append(MeasureSpec.toString(childWidthMeasureSpec)); sb.append(", "); sb.append(MeasureSpec.toString(childHeightMeasureSpec)); - log(tag, sb.toString()); + log(TAG, sb.toString()); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); @@ -218,25 +223,38 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { public static void updateChildLayoutParams(View child, int widthMeasureSpec, int heightMeasureSpec) { int availableWidth = MeasureSpec.getSize(widthMeasureSpec); - int availableHeight = MeasureSpec.getSize(heightMeasureSpec); - CommonLayoutParams lp = (CommonLayoutParams)child.getLayoutParams(); - if (lp.widthPercent > 0) { - lp.width = (int)(availableWidth * lp.widthPercent); - } - if (lp.heightPercent > 0) { - lp.height = (int)(availableHeight * lp.heightPercent); - } - if (lp.leftMarginPercent > 0) { - lp.leftMargin = (int)(availableWidth * lp.leftMarginPercent); - } - if (lp.rightMarginPercent > 0) { - lp.rightMargin = (int)(availableWidth * lp.rightMarginPercent); - } - if (lp.topMarginPercent > 0) { - lp.topMargin = (int)(availableHeight * lp.topMarginPercent); - } - if (lp.bottomMarginPercent > 0) { - lp.bottomMargin = (int)(availableHeight * lp.bottomMarginPercent); + int widthSpec = MeasureSpec.getMode(widthMeasureSpec); + + int availableHeight = MeasureSpec.getSize(heightMeasureSpec); + int heightSpec = MeasureSpec.getMode(heightMeasureSpec); + + CommonLayoutParams lp = (CommonLayoutParams)child.getLayoutParams(); + if (widthSpec != MeasureSpec.UNSPECIFIED) { + if (lp.widthPercent > 0) { + lp.width = (int)(availableWidth * lp.widthPercent); + } + + if (lp.leftMarginPercent > 0) { + lp.leftMargin = (int)(availableWidth * lp.leftMarginPercent); + } + + if (lp.rightMarginPercent > 0) { + lp.rightMargin = (int)(availableWidth * lp.rightMarginPercent); + } + } + + if (heightSpec != MeasureSpec.UNSPECIFIED) { + if (lp.heightPercent > 0) { + lp.height = (int)(availableHeight * lp.heightPercent); + } + + if (lp.topMarginPercent > 0) { + lp.topMargin = (int)(availableHeight * lp.topMarginPercent); + } + + if (lp.bottomMarginPercent > 0) { + lp.bottomMargin = (int)(availableHeight * lp.bottomMarginPercent); + } } } diff --git a/src/org/nativescript/widgets/DockLayout.java b/src/org/nativescript/widgets/DockLayout.java index 5d27737c0..405b57cc3 100644 --- a/src/org/nativescript/widgets/DockLayout.java +++ b/src/org/nativescript/widgets/DockLayout.java @@ -11,9 +11,9 @@ import android.view.View; * */ public class DockLayout extends LayoutBase { - - private boolean _stretchLastChild = true; + private boolean _stretchLastChild = true; + public DockLayout(Context context) { super(context); } diff --git a/src/org/nativescript/widgets/GridLayout.java b/src/org/nativescript/widgets/GridLayout.java index 0c242ec10..0aa608967 100644 --- a/src/org/nativescript/widgets/GridLayout.java +++ b/src/org/nativescript/widgets/GridLayout.java @@ -700,10 +700,12 @@ class MeasureHelper { this.columnStarValue = columnStarCount > 0 ? (this.width - currentColumnWidth) / columnStarCount : 0; - for(int i = 0; i < columnCount; i++) { - ItemGroup item = this.columns.get(i); - if (item.getIsStar()) { - item.length = item.rowOrColumn.getValue() * this.columnStarValue; + if (this.stretchedHorizontally) { + for (int i = 0; i < columnCount; i++) { + ItemGroup item = this.columns.get(i); + if (item.getIsStar()) { + item.length = item.rowOrColumn.getValue() * this.columnStarValue; + } } } } @@ -725,12 +727,14 @@ class MeasureHelper { this.rowStarValue = rowStarCount > 0 ? (this.height - currentRowHeight) / rowStarCount : 0; - for(int i = 0; i < rowCount; i++) { - ItemGroup item = this.rows.get(i); - if (item.getIsStar()) { - item.length = item.rowOrColumn.getValue() * this.rowStarValue; - } - } + if(this.stretchedVertically) { + for (int i = 0; i < rowCount; i++) { + ItemGroup item = this.rows.get(i); + if (item.getIsStar()) { + item.length = item.rowOrColumn.getValue() * this.rowStarValue; + } + } + } } private void fakeMeasure() { diff --git a/src/org/nativescript/widgets/ImageView.java b/src/org/nativescript/widgets/ImageView.java index 4c6118b1d..d25a4954d 100644 --- a/src/org/nativescript/widgets/ImageView.java +++ b/src/org/nativescript/widgets/ImageView.java @@ -99,7 +99,7 @@ public class ImageView extends android.widget.ImageView { sb.append(", measureHeight: "); sb.append(measureHeight); - CommonLayoutParams.log(CommonLayoutParams.tag, sb.toString()); + CommonLayoutParams.log(CommonLayoutParams.TAG, sb.toString()); } int widthSizeAndState = resolveSizeAndState(measureWidth, widthMeasureSpec, 0); diff --git a/src/org/nativescript/widgets/LayoutBase.java b/src/org/nativescript/widgets/LayoutBase.java index 3f504485b..aa5d10cba 100644 --- a/src/org/nativescript/widgets/LayoutBase.java +++ b/src/org/nativescript/widgets/LayoutBase.java @@ -20,7 +20,6 @@ public abstract class LayoutBase extends ViewGroup { super(context); } - @Override protected LayoutParams generateDefaultLayoutParams() { return new CommonLayoutParams(); diff --git a/src/org/nativescript/widgets/TabItemSpec.java b/src/org/nativescript/widgets/TabItemSpec.java index dc6881f71..16bc1e021 100644 --- a/src/org/nativescript/widgets/TabItemSpec.java +++ b/src/org/nativescript/widgets/TabItemSpec.java @@ -6,4 +6,4 @@ public class TabItemSpec { public String title; public int iconId; public Drawable iconDrawable; -} \ No newline at end of file +} diff --git a/src/org/nativescript/widgets/TabStrip.java b/src/org/nativescript/widgets/TabStrip.java index c400bda3c..700d48fc0 100644 --- a/src/org/nativescript/widgets/TabStrip.java +++ b/src/org/nativescript/widgets/TabStrip.java @@ -27,7 +27,7 @@ import android.view.View; import android.widget.LinearLayout; class TabStrip extends LinearLayout { - + private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0; private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26; private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3; diff --git a/src/org/nativescript/widgets/WrapLayout.java b/src/org/nativescript/widgets/WrapLayout.java index a660aeeee..40858fd0f 100644 --- a/src/org/nativescript/widgets/WrapLayout.java +++ b/src/org/nativescript/widgets/WrapLayout.java @@ -21,7 +21,7 @@ public class WrapLayout extends LayoutBase { public WrapLayout(Context context) { super(context); } - + public Orientation getOrientation() { return this._orientation; }