diff --git a/.classpath b/.classpath
deleted file mode 100644
index 1457e3c35..000000000
--- a/.classpath
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
index 334396f27..24fae1d9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,8 @@
-/.metadata/
-node_modules/
-dist/
-
-local.properties
-
-gen/
-armeabi-v7a/
-x86/
-obj/
-bin/
-.svn/
-.settings/
-test/
+.gradle
+/local.properties
+.idea/
+.DS_Store/
+build/
+gradlew
+gradlew.bat
+gradle/
\ No newline at end of file
diff --git a/.project b/.project
deleted file mode 100644
index bd27c6d4c..000000000
--- a/.project
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- widgets
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/POM.xml b/POM.xml
deleted file mode 100644
index a131cf7af..000000000
--- a/POM.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
- 4.0.0
- org.nativescript.widgets
- nativescript-widgets
- 0.1.0
-
\ No newline at end of file
diff --git a/android-widgets.iml b/android-widgets.iml
new file mode 100644
index 000000000..4b78a5b32
--- /dev/null
+++ b/android-widgets.iml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 000000000..6a5c233c5
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,15 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:1.3.0'
+ }
+}
+
+allprojects {
+ repositories {
+ jcenter()
+ }
+}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..55bcce01b
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Nov 03 10:36:19 EET 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar
deleted file mode 100644
index 1780ad3d5..000000000
Binary files a/libs/android-support-v4.jar and /dev/null differ
diff --git a/lint.xml b/lint.xml
deleted file mode 100644
index ee0eead5b..000000000
--- a/lint.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/proguard-project.txt b/proguard-project.txt
deleted file mode 100644
index f2fe1559a..000000000
--- a/proguard-project.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-# To enable ProGuard in your project, edit project.properties
-# to define the proguard.config property as described in that file.
-#
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in ${sdk.dir}/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the ProGuard
-# include property in project.properties.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/project.properties b/project.properties
deleted file mode 100644
index 484dab075..000000000
--- a/project.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-17
-android.library=true
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 000000000..09ee5ce4c
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':widgets'
diff --git a/src/org/nativescript/widgets/CommonLayoutParams.java b/src/org/nativescript/widgets/CommonLayoutParams.java
deleted file mode 100644
index 6e99a6e2c..000000000
--- a/src/org/nativescript/widgets/CommonLayoutParams.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/**
- *
- */
-package org.nativescript.widgets;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.util.Log;
-import android.view.Gravity;
-import android.view.View;
-import android.view.View.MeasureSpec;
-import android.view.ViewGroup.LayoutParams;
-import android.widget.FrameLayout;
-
-/**
- * @author hhristov
- *
- */
-public class CommonLayoutParams extends FrameLayout.LayoutParams {
-
- static final String TAG = "NSLayout";
- static int debuggable = -1;
- private static final StringBuilder sb = new StringBuilder();
-
- public CommonLayoutParams() {
- super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- }
-
- public float widthPercent = 0;
- public float heightPercent = 0;
-
- public float topMarginPercent = 0;
- public float leftMarginPercent = 0;
- public float bottomMarginPercent = 0;
- public float rightMarginPercent = 0;
-
- public int left = 0;
- public int top = 0;
- public int row = 0;
- public int column = 0;
- public int rowSpan = 1;
- public int columnSpan = 1;
- public Dock dock = Dock.left;
-
- public static int getDesiredWidth(View view) {
- CommonLayoutParams lp = (CommonLayoutParams)view.getLayoutParams();
- return view.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
- }
-
- public static int getDesiredHeight(View view) {
- CommonLayoutParams lp = (CommonLayoutParams)view.getLayoutParams();
- return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
- }
-
- // We use our own layout method because the one in FrameLayout is broken when margins are set and gravity is CENTER_VERTICAL or CENTER_HORIZONTAL.
- @SuppressLint("RtlHardcoded")
- public static void layoutChild(View child, int left, int top, int right, int bottom) {
- if (child.getVisibility() == View.GONE) {
- return;
- }
-
- int childTop = 0;
- int childLeft = 0;
-
- int childWidth = child.getMeasuredWidth();
- int childHeight = child.getMeasuredHeight();
-
- CommonLayoutParams lp = (CommonLayoutParams)child.getLayoutParams();
- int gravity = lp.gravity;
- if (gravity == -1) {
- gravity = Gravity.FILL;
- }
-
- int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
-
- // If we have explicit height and gravity is FILL we need to be centered otherwise our explicit height won't be taken into account.
- if (lp.height >= 0 && verticalGravity == Gravity.FILL_VERTICAL) {
- verticalGravity = Gravity.CENTER_VERTICAL;
- }
-
- switch (verticalGravity) {
- case Gravity.TOP:
- childTop = top + lp.topMargin;
- break;
-
- case Gravity.CENTER_VERTICAL:
- childTop = top + (bottom - top - childHeight + lp.topMargin - lp.bottomMargin) / 2;
- break;
-
- case Gravity.BOTTOM:
- childTop = bottom - childHeight - lp.bottomMargin;
- break;
-
- case Gravity.FILL_VERTICAL:
- default:
- childTop = top + lp.topMargin;
- childHeight = bottom - top - (lp.topMargin + lp.bottomMargin);
- break;
- }
-
- int horizontalGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
-
- // If we have explicit width and gravity is FILL we need to be centered otherwise our explicit width won't be taken into account.
- if (lp.width >= 0 && horizontalGravity == Gravity.FILL_HORIZONTAL) {
- horizontalGravity = Gravity.CENTER_HORIZONTAL;
- }
-
- switch (horizontalGravity) {
- case Gravity.LEFT:
- childLeft = left + lp.leftMargin;
- break;
-
- case Gravity.CENTER_HORIZONTAL:
- childLeft = left + (right - left - childWidth + lp.leftMargin - lp.rightMargin) / 2;
- break;
-
- case Gravity.RIGHT:
- childLeft = right - childWidth - lp.rightMargin;
- break;
-
- case Gravity.FILL_HORIZONTAL:
- default:
- childLeft = left + lp.leftMargin;
- childWidth = right - left - (lp.leftMargin + lp.rightMargin);
- break;
- }
-
- int childRight = Math.round(childLeft + childWidth);
- int childBottom = Math.round(childTop + childHeight);
- childLeft = Math.round(childLeft);
- childTop = Math.round(childTop);
-
- // Re-measure TextView because it is not centered if layout width is larger than measure width.
- if (child instanceof android.widget.TextView) {
-
- boolean canChangeWidth = lp.width < 0;
- boolean canChangeHeight = lp.height < 0;
-
- int measuredWidth = child.getMeasuredWidth();
- int measuredHeight = child.getMeasuredHeight();
-
- int width = childRight - childLeft;
- int height = childBottom - childTop;
- if ((Math.abs(measuredWidth - width) > 1 && canChangeWidth) || (Math.abs(measuredHeight - height) > 1 && canChangeHeight)) {
- int widthMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeWidth ? width : lp.width, MeasureSpec.EXACTLY);
- int heightMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeHeight ? height : lp.height, MeasureSpec.EXACTLY);
- if (debuggable > 0) {
- sb.setLength(0);
- sb.append("remeasure ");
- sb.append(child);
- sb.append(" with ");
- sb.append(MeasureSpec.toString(widthMeasureSpec));
- sb.append(", ");
- sb.append(MeasureSpec.toString(heightMeasureSpec));
- log(TAG, sb.toString());
- }
-
- child.measure(widthMeasureSpec, heightMeasureSpec);
- }
- }
-
- if (debuggable > 0) {
- sb.setLength(0);
- sb.append(child.getParent().toString());
- sb.append(" :layoutChild: ");
- sb.append(child.toString());
- sb.append(" ");
- sb.append(childLeft);
- sb.append(", ");
- sb.append(childTop);
- sb.append(", ");
- sb.append(childRight);
- sb.append(", ");
- sb.append(childBottom);
- log(TAG, sb.toString());
- }
-
- child.layout(childLeft, childTop, childRight, childBottom);
- }
-
- public static void measureChild(View child, int widthMeasureSpec, int heightMeasureSpec) {
- if (child.getVisibility() == View.GONE) {
- return;
- }
-
- // Negative means not initialized.
- if(debuggable < 0) {
- try {
- 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);
- int childHeightMeasureSpec = getMeasureSpec(child, heightMeasureSpec, false);
-
- if (debuggable > 0) {
- sb.setLength(0);
- sb.append(child.getParent().toString());
- sb.append(" :measureChild: ");
- sb.append(child.toString());
- sb.append(" ");
- sb.append(MeasureSpec.toString(childWidthMeasureSpec));
- sb.append(", ");
- sb.append(MeasureSpec.toString(childHeightMeasureSpec));
- log(TAG, sb.toString());
- }
-
- child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
- }
-
- public static void updateChildLayoutParams(View child, int widthMeasureSpec, int heightMeasureSpec) {
-
- int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
- 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);
- }
- }
- }
-
- static void log(String tag, String message) {
- Log.d(tag, message);
- }
-
- static StringBuilder getStringBuilder() {
- sb.setLength(0);
- return sb;
- }
-
- private static int getMeasureSpec(View view, int parentMeasureSpec, boolean horizontal) {
-
- int parentLength = MeasureSpec.getSize(parentMeasureSpec);
- int parentSpecMode = MeasureSpec.getMode(parentMeasureSpec);
-
- CommonLayoutParams lp = (CommonLayoutParams)view.getLayoutParams();
- final int margins = horizontal ? lp.leftMargin + lp.rightMargin : lp.topMargin + lp.bottomMargin;
-
- int resultSize = 0;
- int resultMode = 0;
-
- int measureLength = Math.max(0, parentLength - margins);
- int childLength = horizontal ? lp.width : lp.height;
-
- // We want a specific size... let be it.
- if (childLength >= 0) {
- if (parentSpecMode != MeasureSpec.UNSPECIFIED) {
- resultSize = Math.min(parentLength, childLength);
- }
- else {
- resultSize = childLength;
- }
-
- resultMode = MeasureSpec.EXACTLY;
- }
- else {
- switch (parentSpecMode) {
- // Parent has imposed an exact size on us
- case MeasureSpec.EXACTLY:
- resultSize = measureLength;
- int gravity = LayoutBase.getGravity(view);
- boolean stretched;
- if (horizontal) {
- final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, view.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
- stretched = horizontalGravity == Gravity.FILL_HORIZONTAL;
- }
- else {
- final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
- stretched = verticalGravity == Gravity.FILL_VERTICAL;
- }
-
- // if stretched - view wants to be our size. So be it.
- // else - view wants to determine its own size. It can't be bigger than us.
- resultMode = stretched ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
- break;
-
- // Parent has imposed a maximum size on us
- case MeasureSpec.AT_MOST:
- resultSize = measureLength;
- resultMode = MeasureSpec.AT_MOST;
- break;
-
- case MeasureSpec.UNSPECIFIED:
- resultSize = 0;
- resultMode = MeasureSpec.UNSPECIFIED;
- break;
- }
- }
-
- return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
- }
-}
diff --git a/widgets/build.gradle b/widgets/build.gradle
new file mode 100644
index 000000000..06d5d5968
--- /dev/null
+++ b/widgets/build.gradle
@@ -0,0 +1,22 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 17
+ buildToolsVersion "23.0.1"
+
+ defaultConfig {
+ minSdkVersion 17
+ targetSdkVersion 21
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.android.support:support-v4:23.0.1'
+}
diff --git a/AndroidManifest.xml b/widgets/src/main/AndroidManifest.xml
similarity index 100%
rename from AndroidManifest.xml
rename to widgets/src/main/AndroidManifest.xml
diff --git a/src/org/nativescript/widgets/AbsoluteLayout.java b/widgets/src/main/java/org/nativescript/widgets/AbsoluteLayout.java
similarity index 95%
rename from src/org/nativescript/widgets/AbsoluteLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/AbsoluteLayout.java
index aaee2f6a8..21ebd1fd8 100644
--- a/src/org/nativescript/widgets/AbsoluteLayout.java
+++ b/widgets/src/main/java/org/nativescript/widgets/AbsoluteLayout.java
@@ -18,7 +18,8 @@ public class AbsoluteLayout extends LayoutBase {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
+
int measureWidth = 0;
int measureHeight = 0;
int childMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
@@ -29,8 +30,7 @@ public class AbsoluteLayout extends LayoutBase {
if (child.getVisibility() == View.GONE) {
continue;
}
-
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
+
CommonLayoutParams.measureChild(child, childMeasureSpec, childMeasureSpec);
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -56,7 +56,6 @@ public class AbsoluteLayout extends LayoutBase {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-
int leftPadding = this.getPaddingLeft();
int topPadding = this.getPaddingTop();
int count = this.getChildCount();
@@ -78,5 +77,7 @@ public class AbsoluteLayout extends LayoutBase {
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childBottom);
}
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
}
diff --git a/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java b/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java
new file mode 100644
index 000000000..d35faf6d0
--- /dev/null
+++ b/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java
@@ -0,0 +1,407 @@
+/**
+ *
+ */
+package org.nativescript.widgets;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.view.View.MeasureSpec;
+import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.widget.FrameLayout;
+
+/**
+ * @author hhristov
+ */
+public class CommonLayoutParams extends FrameLayout.LayoutParams {
+
+ static final String TAG = "NSLayout";
+ static int debuggable = -1;
+ private static final StringBuilder sb = new StringBuilder();
+
+ public CommonLayoutParams() {
+ super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ }
+
+ public float widthPercent = 0;
+ public float heightPercent = 0;
+
+ public float topMarginPercent = 0;
+ public float leftMarginPercent = 0;
+ public float bottomMarginPercent = 0;
+ public float rightMarginPercent = 0;
+
+ public int widthOriginal = -1;
+ public int heightOriginal = -1;
+
+ public int topMarginOriginal = -1;
+ public int leftMarginOriginal = -1;
+ public int bottomMarginOriginal = -1;
+ public int rightMarginOriginal = -1;
+
+ public int left = 0;
+ public int top = 0;
+ public int row = 0;
+ public int column = 0;
+ public int rowSpan = 1;
+ public int columnSpan = 1;
+ public Dock dock = Dock.left;
+
+ protected static int getDesiredWidth(View view) {
+ CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
+ return view.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
+ }
+
+ protected static int getDesiredHeight(View view) {
+ CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
+ return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
+ }
+
+ // We use our own layout method because the one in FrameLayout is broken when margins are set and gravity is CENTER_VERTICAL or CENTER_HORIZONTAL.
+ @SuppressLint("RtlHardcoded")
+ protected static void layoutChild(View child, int left, int top, int right, int bottom) {
+ if (child.getVisibility() == View.GONE) {
+ return;
+ }
+
+ int childTop = 0;
+ int childLeft = 0;
+
+ int childWidth = child.getMeasuredWidth();
+ int childHeight = child.getMeasuredHeight();
+
+ CommonLayoutParams lp = (CommonLayoutParams) child.getLayoutParams();
+ int gravity = lp.gravity;
+ if (gravity == -1) {
+ gravity = Gravity.FILL;
+ }
+
+ int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
+
+ // If we have explicit height and gravity is FILL we need to be centered otherwise our explicit height won't be taken into account.
+ if (lp.height >= 0 && verticalGravity == Gravity.FILL_VERTICAL) {
+ verticalGravity = Gravity.CENTER_VERTICAL;
+ }
+
+ switch (verticalGravity) {
+ case Gravity.TOP:
+ childTop = top + lp.topMargin;
+ break;
+
+ case Gravity.CENTER_VERTICAL:
+ childTop = top + (bottom - top - childHeight + lp.topMargin - lp.bottomMargin) / 2;
+ break;
+
+ case Gravity.BOTTOM:
+ childTop = bottom - childHeight - lp.bottomMargin;
+ break;
+
+ case Gravity.FILL_VERTICAL:
+ default:
+ childTop = top + lp.topMargin;
+ childHeight = bottom - top - (lp.topMargin + lp.bottomMargin);
+ break;
+ }
+
+ int horizontalGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
+
+ // If we have explicit width and gravity is FILL we need to be centered otherwise our explicit width won't be taken into account.
+ if (lp.width >= 0 && horizontalGravity == Gravity.FILL_HORIZONTAL) {
+ horizontalGravity = Gravity.CENTER_HORIZONTAL;
+ }
+
+ switch (horizontalGravity) {
+ case Gravity.LEFT:
+ childLeft = left + lp.leftMargin;
+ break;
+
+ case Gravity.CENTER_HORIZONTAL:
+ childLeft = left + (right - left - childWidth + lp.leftMargin - lp.rightMargin) / 2;
+ break;
+
+ case Gravity.RIGHT:
+ childLeft = right - childWidth - lp.rightMargin;
+ break;
+
+ case Gravity.FILL_HORIZONTAL:
+ default:
+ childLeft = left + lp.leftMargin;
+ childWidth = right - left - (lp.leftMargin + lp.rightMargin);
+ break;
+ }
+
+ int childRight = Math.round(childLeft + childWidth);
+ int childBottom = Math.round(childTop + childHeight);
+ childLeft = Math.round(childLeft);
+ childTop = Math.round(childTop);
+
+ // Re-measure TextView because it is not centered if layout width is larger than measure width.
+ if (child instanceof android.widget.TextView) {
+
+ boolean canChangeWidth = lp.width < 0;
+ boolean canChangeHeight = lp.height < 0;
+
+ int measuredWidth = child.getMeasuredWidth();
+ int measuredHeight = child.getMeasuredHeight();
+
+ int width = childRight - childLeft;
+ int height = childBottom - childTop;
+ if ((Math.abs(measuredWidth - width) > 1 && canChangeWidth) || (Math.abs(measuredHeight - height) > 1 && canChangeHeight)) {
+ int widthMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeWidth ? width : lp.width, MeasureSpec.EXACTLY);
+ int heightMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeHeight ? height : lp.height, MeasureSpec.EXACTLY);
+ if (debuggable > 0) {
+ sb.setLength(0);
+ sb.append("remeasure ");
+ sb.append(child);
+ sb.append(" with ");
+ sb.append(MeasureSpec.toString(widthMeasureSpec));
+ sb.append(", ");
+ sb.append(MeasureSpec.toString(heightMeasureSpec));
+ log(TAG, sb.toString());
+ }
+
+ child.measure(widthMeasureSpec, heightMeasureSpec);
+ }
+ }
+
+ if (debuggable > 0) {
+ sb.setLength(0);
+ sb.append(child.getParent().toString());
+ sb.append(" :layoutChild: ");
+ sb.append(child.toString());
+ sb.append(" ");
+ sb.append(childLeft);
+ sb.append(", ");
+ sb.append(childTop);
+ sb.append(", ");
+ sb.append(childRight);
+ sb.append(", ");
+ sb.append(childBottom);
+ log(TAG, sb.toString());
+ }
+
+ child.layout(childLeft, childTop, childRight, childBottom);
+ }
+
+ protected static void measureChild(View child, int widthMeasureSpec, int heightMeasureSpec) {
+ if (child.getVisibility() == View.GONE) {
+ return;
+ }
+
+ // Negative means not initialized.
+ if (debuggable < 0) {
+ try {
+ 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);
+ int childHeightMeasureSpec = getMeasureSpec(child, heightMeasureSpec, false);
+
+ if (debuggable > 0) {
+ sb.setLength(0);
+ sb.append(child.getParent().toString());
+ sb.append(" :measureChild: ");
+ sb.append(child.toString());
+ sb.append(" ");
+ sb.append(MeasureSpec.toString(childWidthMeasureSpec));
+ sb.append(", ");
+ sb.append(MeasureSpec.toString(childHeightMeasureSpec));
+ log(TAG, sb.toString());
+ }
+
+ child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
+ }
+
+ /**
+ * Iterates over children and changes their width and height to one calculated from percentage
+ * values.
+ *
+ * @param viewGroup The parent ViewGroup.
+ * @param widthMeasureSpec Width MeasureSpec of the parent ViewGroup.
+ * @param heightMeasureSpec Height MeasureSpec of the parent ViewGroup.
+ */
+ protected static void adjustChildrenLayoutParams(ViewGroup viewGroup, int widthMeasureSpec, int heightMeasureSpec) {
+
+ int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
+ int widthSpec = MeasureSpec.getMode(widthMeasureSpec);
+
+ int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
+ int heightSpec = MeasureSpec.getMode(heightMeasureSpec);
+
+ for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
+ View child = viewGroup.getChildAt(i);
+ ViewGroup.LayoutParams params = child.getLayoutParams();
+
+ if (params instanceof CommonLayoutParams) {
+ CommonLayoutParams lp = (CommonLayoutParams) child.getLayoutParams();
+ if (widthSpec != MeasureSpec.UNSPECIFIED) {
+ if (lp.widthPercent > 0) {
+ lp.widthOriginal = lp.width;
+ lp.width = (int) (availableWidth * lp.widthPercent);
+ }
+ else {
+ lp.widthOriginal = -1;
+ }
+
+ if (lp.leftMarginPercent > 0) {
+ lp.leftMarginOriginal = lp.leftMargin;
+ lp.leftMargin = (int) (availableWidth * lp.leftMarginPercent);
+ }
+ else {
+ lp.leftMarginOriginal = -1;
+ }
+
+ if (lp.rightMarginPercent > 0) {
+ lp.rightMarginOriginal = lp.rightMargin;
+ lp.rightMargin = (int) (availableWidth * lp.rightMarginPercent);
+ }
+ else {
+ lp.rightMarginOriginal = -1;
+ }
+ }
+
+ if (heightSpec != MeasureSpec.UNSPECIFIED) {
+ if (lp.heightPercent > 0) {
+ lp.heightOriginal = lp.height;
+ lp.height = (int) (availableHeight * lp.heightPercent);
+ }
+ else {
+ lp.heightOriginal = -1;
+ }
+
+ if (lp.topMarginPercent > 0) {
+ lp.topMarginOriginal = lp.topMargin;
+ lp.topMargin = (int) (availableHeight * lp.topMarginPercent);
+ }
+ else {
+ lp.topMarginOriginal = -1;
+ }
+
+ if (lp.bottomMarginPercent > 0) {
+ lp.bottomMarginOriginal = lp.bottomMargin;
+ lp.bottomMargin = (int) (availableHeight * lp.bottomMarginPercent);
+ }
+ else {
+ lp.bottomMarginOriginal = -1;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Iterates over children and restores their original dimensions that were changed for
+ * percentage values.
+ */
+ protected static void restoreOriginalParams(ViewGroup viewGroup) {
+ for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
+ View view = viewGroup.getChildAt(i);
+ ViewGroup.LayoutParams params = view.getLayoutParams();
+ if (params instanceof CommonLayoutParams) {
+ CommonLayoutParams lp = (CommonLayoutParams) params;
+ if (lp.widthPercent > 0) {
+ lp.width = lp.widthOriginal;
+ }
+ if (lp.heightPercent > 0) {
+ lp.height = lp.heightOriginal;
+ }
+ if (lp.leftMarginPercent > 0) {
+ lp.leftMargin = lp.leftMarginOriginal;
+ }
+ if (lp.topMarginPercent > 0) {
+ lp.topMargin = lp.topMarginOriginal;
+ }
+ if (lp.rightMarginPercent > 0) {
+ lp.rightMargin = lp.rightMarginOriginal;
+ }
+ if (lp.bottomMarginPercent > 0) {
+ lp.bottomMargin = lp.bottomMarginOriginal;
+ }
+ }
+ }
+ }
+
+ static void log(String tag, String message) {
+ Log.d(tag, message);
+ }
+
+ static StringBuilder getStringBuilder() {
+ sb.setLength(0);
+ return sb;
+ }
+
+ private static int getMeasureSpec(View view, int parentMeasureSpec, boolean horizontal) {
+
+ int parentLength = MeasureSpec.getSize(parentMeasureSpec);
+ int parentSpecMode = MeasureSpec.getMode(parentMeasureSpec);
+
+ CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
+ final int margins = horizontal ? lp.leftMargin + lp.rightMargin : lp.topMargin + lp.bottomMargin;
+
+ int resultSize = 0;
+ int resultMode = MeasureSpec.UNSPECIFIED;
+
+ int measureLength = Math.max(0, parentLength - margins);
+ int childLength = horizontal ? lp.width : lp.height;
+
+ // We want a specific size... let be it.
+ if (childLength >= 0) {
+ if (parentSpecMode != MeasureSpec.UNSPECIFIED) {
+ resultSize = Math.min(parentLength, childLength);
+ } else {
+ resultSize = childLength;
+ }
+
+ resultMode = MeasureSpec.EXACTLY;
+ } else {
+ switch (parentSpecMode) {
+ // Parent has imposed an exact size on us
+ case MeasureSpec.EXACTLY:
+ resultSize = measureLength;
+ int gravity = LayoutBase.getGravity(view);
+ boolean stretched;
+ if (horizontal) {
+ final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, view.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
+ stretched = horizontalGravity == Gravity.FILL_HORIZONTAL;
+ } else {
+ final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
+ stretched = verticalGravity == Gravity.FILL_VERTICAL;
+ }
+
+ // if stretched - view wants to be our size. So be it.
+ // else - view wants to determine its own size. It can't be bigger than us.
+ resultMode = stretched ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
+ break;
+
+ // Parent has imposed a maximum size on us
+ case MeasureSpec.AT_MOST:
+ resultSize = measureLength;
+ resultMode = MeasureSpec.AT_MOST;
+ break;
+
+ case MeasureSpec.UNSPECIFIED:
+ resultSize = 0;
+ resultMode = MeasureSpec.UNSPECIFIED;
+ break;
+ }
+ }
+
+ return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
+ }
+}
\ No newline at end of file
diff --git a/src/org/nativescript/widgets/ContentLayout.java b/widgets/src/main/java/org/nativescript/widgets/ContentLayout.java
similarity index 94%
rename from src/org/nativescript/widgets/ContentLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/ContentLayout.java
index e2459027a..283436dda 100644
--- a/src/org/nativescript/widgets/ContentLayout.java
+++ b/widgets/src/main/java/org/nativescript/widgets/ContentLayout.java
@@ -18,7 +18,8 @@ public class ContentLayout extends LayoutBase {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
+
int measureWidth = 0;
int measureHeight = 0;
@@ -29,7 +30,6 @@ public class ContentLayout extends LayoutBase {
continue;
}
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
CommonLayoutParams.measureChild(child, widthMeasureSpec, heightMeasureSpec);
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -54,7 +54,6 @@ public class ContentLayout extends LayoutBase {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-
int paddingLeft = this.getPaddingLeft();
int paddingRight = this.getPaddingRight();
int paddingTop = this.getPaddingTop();
@@ -75,5 +74,7 @@ public class ContentLayout extends LayoutBase {
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childBottom);
}
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
}
diff --git a/src/org/nativescript/widgets/Dock.java b/widgets/src/main/java/org/nativescript/widgets/Dock.java
similarity index 100%
rename from src/org/nativescript/widgets/Dock.java
rename to widgets/src/main/java/org/nativescript/widgets/Dock.java
diff --git a/src/org/nativescript/widgets/DockLayout.java b/widgets/src/main/java/org/nativescript/widgets/DockLayout.java
similarity index 97%
rename from src/org/nativescript/widgets/DockLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/DockLayout.java
index 405b57cc3..cee18e54a 100644
--- a/src/org/nativescript/widgets/DockLayout.java
+++ b/widgets/src/main/java/org/nativescript/widgets/DockLayout.java
@@ -27,6 +27,7 @@ public class DockLayout extends LayoutBase {
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
int measureWidth = 0;
int measureHeight = 0;
@@ -64,7 +65,6 @@ public class DockLayout extends LayoutBase {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(remainingHeight, heightMode == MeasureSpec.EXACTLY ? MeasureSpec.AT_MOST : heightMode);
}
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -107,7 +107,6 @@ public class DockLayout extends LayoutBase {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-
int childLeft = this.getPaddingLeft();
int childTop = this.getPaddingTop();
@@ -173,5 +172,7 @@ public class DockLayout extends LayoutBase {
if (childToStretch != null) {
CommonLayoutParams.layoutChild(childToStretch, x, y, x + remainingWidth, y + remainingHeight);
}
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
}
diff --git a/src/org/nativescript/widgets/GridLayout.java b/widgets/src/main/java/org/nativescript/widgets/GridLayout.java
similarity index 99%
rename from src/org/nativescript/widgets/GridLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/GridLayout.java
index 0aa608967..fb6cca819 100644
--- a/src/org/nativescript/widgets/GridLayout.java
+++ b/widgets/src/main/java/org/nativescript/widgets/GridLayout.java
@@ -232,8 +232,9 @@ public class GridLayout extends LayoutBase {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
- int measureWidth = 0;
+ int measureWidth = 0;
int measureHeight = 0;
int width = View.MeasureSpec.getSize(widthMeasureSpec);
@@ -251,7 +252,7 @@ public class GridLayout extends LayoutBase {
this.helper.width = width - horizontalPadding;
this.helper.height = height - verticalPadding;
- int gravity = getGravity(this);
+ int gravity = LayoutBase.getGravity(this);
int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
final int layoutDirection = this.getLayoutDirection();
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection) & Gravity.HORIZONTAL_GRAVITY_MASK;
@@ -272,7 +273,6 @@ public class GridLayout extends LayoutBase {
continue;
}
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
MeasureSpecs measureSpecs = this.map.get(child);
this.updateMeasureSpecs(child, measureSpecs);
this.helper.addMeasureSpec(measureSpecs);
@@ -296,7 +296,6 @@ public class GridLayout extends LayoutBase {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
-
int paddingLeft = this.getPaddingLeft();
int paddingTop = this.getPaddingTop();
@@ -356,6 +355,8 @@ public class GridLayout extends LayoutBase {
CommonLayoutParams.layoutChild(measureSpec.child, childLeft, childTop, childRight, childBottom);
}
}
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
}
diff --git a/src/org/nativescript/widgets/GridUnitType.java b/widgets/src/main/java/org/nativescript/widgets/GridUnitType.java
similarity index 100%
rename from src/org/nativescript/widgets/GridUnitType.java
rename to widgets/src/main/java/org/nativescript/widgets/GridUnitType.java
diff --git a/src/org/nativescript/widgets/HorizontalScrollView.java b/widgets/src/main/java/org/nativescript/widgets/HorizontalScrollView.java
similarity index 95%
rename from src/org/nativescript/widgets/HorizontalScrollView.java
rename to widgets/src/main/java/org/nativescript/widgets/HorizontalScrollView.java
index 18f597446..d09441f6c 100644
--- a/src/org/nativescript/widgets/HorizontalScrollView.java
+++ b/widgets/src/main/java/org/nativescript/widgets/HorizontalScrollView.java
@@ -65,7 +65,9 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- // Don't call measure because it will measure content twice.
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
+
+ // Don't call measure because it will measure content twice.
// ScrollView is expected to have single child so we measure only the first child.
View child = this.getChildCount() > 0 ? this.getChildAt(0) : null;
if (child == null) {
@@ -74,7 +76,6 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
this.contentMeasuredHeight = 0;
}
else {
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
CommonLayoutParams.measureChild(child, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), heightMeasureSpec);
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -86,8 +87,8 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
// Don't add in our paddings because they are already added as child margins. (we will include them twice if we add them).
// Check the previous line - this.setPadding(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
-// this.contentMeasuredWidth += this.getPaddingLeft() + this.getPaddingRight();
-// this.contentMeasuredHeight += this.getPaddingTop() + this.getPaddingBottom();
+ //this.contentMeasuredWidth += this.getPaddingLeft() + this.getPaddingRight();
+ //this.contentMeasuredHeight += this.getPaddingTop() + this.getPaddingBottom();
// Check against our minimum height
this.contentMeasuredWidth = Math.max(this.contentMeasuredWidth, this.getSuggestedMinimumWidth());
@@ -147,6 +148,7 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
// Calling this with the present values causes it to re-claim them
this.scrollTo(scrollX, scrollY);
+ CommonLayoutParams.restoreOriginalParams(this);
}
@Override
diff --git a/src/org/nativescript/widgets/ImageView.java b/widgets/src/main/java/org/nativescript/widgets/ImageView.java
similarity index 100%
rename from src/org/nativescript/widgets/ImageView.java
rename to widgets/src/main/java/org/nativescript/widgets/ImageView.java
diff --git a/src/org/nativescript/widgets/ItemSpec.java b/widgets/src/main/java/org/nativescript/widgets/ItemSpec.java
similarity index 100%
rename from src/org/nativescript/widgets/ItemSpec.java
rename to widgets/src/main/java/org/nativescript/widgets/ItemSpec.java
diff --git a/src/org/nativescript/widgets/LayoutBase.java b/widgets/src/main/java/org/nativescript/widgets/LayoutBase.java
similarity index 100%
rename from src/org/nativescript/widgets/LayoutBase.java
rename to widgets/src/main/java/org/nativescript/widgets/LayoutBase.java
diff --git a/src/org/nativescript/widgets/Orientation.java b/widgets/src/main/java/org/nativescript/widgets/Orientation.java
similarity index 100%
rename from src/org/nativescript/widgets/Orientation.java
rename to widgets/src/main/java/org/nativescript/widgets/Orientation.java
diff --git a/src/org/nativescript/widgets/StackLayout.java b/widgets/src/main/java/org/nativescript/widgets/StackLayout.java
similarity index 92%
rename from src/org/nativescript/widgets/StackLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/StackLayout.java
index 73d83b061..4186ffac7 100644
--- a/src/org/nativescript/widgets/StackLayout.java
+++ b/widgets/src/main/java/org/nativescript/widgets/StackLayout.java
@@ -31,7 +31,9 @@ public class StackLayout extends LayoutBase {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int childState = 0;
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
+
+ int childState = 0;
int measureWidth = 0;
int measureHeight = 0;
@@ -77,7 +79,6 @@ public class StackLayout extends LayoutBase {
continue;
}
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
if (isVertical) {
CommonLayoutParams.measureChild(child, childMeasureSpec, MeasureSpec.makeMeasureSpec(remainingLength, measureSpecMode));
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
@@ -118,13 +119,14 @@ public class StackLayout extends LayoutBase {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
-
if (this._orientation == Orientation.vertical) {
this.layoutVertical(l, t, r, b);
}
else {
this.layoutHorizontal(l, t, r, b);
}
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
private void layoutVertical(int left, int top, int right, int bottom) {
@@ -138,7 +140,7 @@ public class StackLayout extends LayoutBase {
int childLeft = paddingLeft;
int childRight = right - left - paddingRight;
- int gravity = getGravity(this);
+ int gravity = LayoutBase.getGravity(this);
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (verticalGravity) {
@@ -164,8 +166,7 @@ public class StackLayout extends LayoutBase {
continue;
}
- CommonLayoutParams childLayoutParams = (CommonLayoutParams)child.getLayoutParams();
- int childHeight = child.getMeasuredHeight() + childLayoutParams.topMargin + childLayoutParams.bottomMargin;
+ int childHeight = CommonLayoutParams.getDesiredHeight(child);
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childTop + childHeight);
childTop += childHeight;
}
@@ -183,7 +184,7 @@ public class StackLayout extends LayoutBase {
int childLeft = 0;
int childBottom = bottom - top - paddingBottom;
- int gravity = getGravity(this);
+ int gravity = LayoutBase.getGravity(this);
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
switch (horizontalGravity) {
@@ -209,8 +210,7 @@ public class StackLayout extends LayoutBase {
continue;
}
- CommonLayoutParams childLayoutParams = (CommonLayoutParams)child.getLayoutParams();
- int childWidth = child.getMeasuredWidth() + childLayoutParams.leftMargin + childLayoutParams.rightMargin;
+ int childWidth = CommonLayoutParams.getDesiredWidth(child);
CommonLayoutParams.layoutChild(child, childLeft, childTop, childLeft + childWidth, childBottom);
childLeft += childWidth;
}
diff --git a/src/org/nativescript/widgets/TabItemSpec.java b/widgets/src/main/java/org/nativescript/widgets/TabItemSpec.java
similarity index 100%
rename from src/org/nativescript/widgets/TabItemSpec.java
rename to widgets/src/main/java/org/nativescript/widgets/TabItemSpec.java
diff --git a/src/org/nativescript/widgets/TabLayout.java b/widgets/src/main/java/org/nativescript/widgets/TabLayout.java
similarity index 100%
rename from src/org/nativescript/widgets/TabLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/TabLayout.java
diff --git a/src/org/nativescript/widgets/TabStrip.java b/widgets/src/main/java/org/nativescript/widgets/TabStrip.java
similarity index 99%
rename from src/org/nativescript/widgets/TabStrip.java
rename to widgets/src/main/java/org/nativescript/widgets/TabStrip.java
index 700d48fc0..fa6636e16 100644
--- a/src/org/nativescript/widgets/TabStrip.java
+++ b/widgets/src/main/java/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;
@@ -53,13 +53,14 @@ class TabStrip extends LinearLayout {
TabStrip(Context context, AttributeSet attrs) {
super(context, attrs);
+
setWillNotDraw(false);
final float density = getResources().getDisplayMetrics().density;
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.colorForeground, outValue, true);
- final int themeForegroundColor = outValue.data;
+ final int themeForegroundColor = outValue.data;
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
diff --git a/src/org/nativescript/widgets/VerticalScrollView.java b/widgets/src/main/java/org/nativescript/widgets/VerticalScrollView.java
similarity index 96%
rename from src/org/nativescript/widgets/VerticalScrollView.java
rename to widgets/src/main/java/org/nativescript/widgets/VerticalScrollView.java
index e03a1f9e7..53aa9d817 100644
--- a/src/org/nativescript/widgets/VerticalScrollView.java
+++ b/widgets/src/main/java/org/nativescript/widgets/VerticalScrollView.java
@@ -65,7 +65,9 @@ public class VerticalScrollView extends ScrollView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- // Don't call measure because it will measure content twice.
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
+
+ // Don't call measure because it will measure content twice.
// ScrollView is expected to have single child so we measure only the first child.
View child = this.getChildCount() > 0 ? this.getChildAt(0) : null;
if (child == null) {
@@ -75,7 +77,6 @@ public class VerticalScrollView extends ScrollView {
this.setPadding(0, 0, 0, 0);
}
else {
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
CommonLayoutParams.measureChild(child, widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -144,6 +145,8 @@ public class VerticalScrollView extends ScrollView {
// Calling this with the present values causes it to re-claim them
this.scrollTo(scrollX, scrollY);
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
@Override
diff --git a/src/org/nativescript/widgets/WrapLayout.java b/widgets/src/main/java/org/nativescript/widgets/WrapLayout.java
similarity index 97%
rename from src/org/nativescript/widgets/WrapLayout.java
rename to widgets/src/main/java/org/nativescript/widgets/WrapLayout.java
index 40858fd0f..e246ed923 100644
--- a/src/org/nativescript/widgets/WrapLayout.java
+++ b/widgets/src/main/java/org/nativescript/widgets/WrapLayout.java
@@ -60,8 +60,9 @@ public class WrapLayout extends LayoutBase {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-
- int measureWidth = 0;
+ CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
+
+ int measureWidth = 0;
int measureHeight = 0;
int width = MeasureSpec.getSize(widthMeasureSpec);
@@ -91,8 +92,7 @@ public class WrapLayout extends LayoutBase {
if (child.getVisibility() == View.GONE) {
continue;
}
-
- CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
+
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -162,7 +162,6 @@ public class WrapLayout extends LayoutBase {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-
boolean isVertical = this._orientation == Orientation.vertical;
int paddingLeft = this.getPaddingLeft();
int paddingRight = this.getPaddingRight();
@@ -187,7 +186,6 @@ public class WrapLayout extends LayoutBase {
int length = this._lengths.get(rowOrColumn);
if (isVertical) {
-
childWidth = length;
childHeight = this._itemHeight > 0 ? this._itemHeight : childHeight;
if (childTop + childHeight > childrenLength) {
@@ -233,5 +231,7 @@ public class WrapLayout extends LayoutBase {
childLeft += childWidth;
}
}
+
+ CommonLayoutParams.restoreOriginalParams(this);
}
-}
+}
\ No newline at end of file
diff --git a/res/.gitkeep b/widgets/src/main/res/.gitkeep
similarity index 100%
rename from res/.gitkeep
rename to widgets/src/main/res/.gitkeep
diff --git a/widgets/widgets.iml b/widgets/widgets.iml
new file mode 100644
index 000000000..30f3119ae
--- /dev/null
+++ b/widgets/widgets.iml
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ generateDebugAndroidTestSources
+ generateDebugSources
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file