Fixed percent margins

Fixed WrapLayout
Code formatting
This commit is contained in:
Hristo Hristov
2016-01-11 11:49:20 +02:00
parent 9884a78e42
commit 375a8d2592
32 changed files with 443 additions and 193 deletions

55
.gitignore vendored
View File

@@ -1,10 +1,49 @@
/dist
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Built application files
/*/build/
## File-based project format:
*.ipr
*.iws
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
## Directory-based project format:
.idea/
# Local configuration file (sdk path, etc)
local.properties
# Gradle generated files
.gradle/
# Signing files
.signing/
# OS-specific files
.DS_Store
/build
/captures
/node_modules
/dist
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

1
.idea/.name generated
View File

@@ -1 +0,0 @@
android-widgets

22
.idea/compiler.xml generated
View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@@ -1,3 +0,0 @@
<component name="CopyrightManager">
<settings default="" />
</component>

6
.idea/encodings.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

26
.idea/gradle.xml generated
View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/widgets" />
</set>
</option>
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/widgets" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

19
.idea/misc.xml generated
View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

10
.idea/modules.xml generated
View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/android-widgets.iml" filepath="$PROJECT_DIR$/android-widgets.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/widgets/widgets.iml" filepath="$PROJECT_DIR$/widgets/widgets.iml" />
</modules>
</component>
</project>

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

Binary file not shown.

View File

@@ -1,6 +0,0 @@
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

40
widgets/.gitignore vendored
View File

@@ -1 +1,41 @@
/build
/dist
*.iml
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Built application files
/*/build/
## File-based project format:
*.ipr
*.iws
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
## Directory-based project format:
.idea/
# Local configuration file (sdk path, etc)
local.properties
# Gradle generated files
.gradle/
# Signing files
.signing/

160
widgets/gradlew vendored Normal file
View File

@@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
widgets/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -23,9 +23,8 @@ public class AbsoluteLayout extends LayoutBase {
int measureWidth = 0;
int measureHeight = 0;
int childMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
int count = this.getChildCount();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -58,9 +57,8 @@ public class AbsoluteLayout extends LayoutBase {
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();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -80,4 +78,4 @@ public class AbsoluteLayout extends LayoutBase {
CommonLayoutParams.restoreOriginalParams(this);
}
}
}

View File

@@ -22,6 +22,7 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
static final String TAG = "NSLayout";
static int debuggable = -1;
private static final int NOT_SET = Integer.MIN_VALUE;
private static final StringBuilder sb = new StringBuilder();
public CommonLayoutParams() {
@@ -36,13 +37,13 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
public float bottomMarginPercent = 0;
public float rightMarginPercent = 0;
public int widthOriginal = -1;
public int heightOriginal = -1;
public int widthOriginal = NOT_SET;
public int heightOriginal = NOT_SET;
public int topMarginOriginal = -1;
public int leftMarginOriginal = -1;
public int bottomMarginOriginal = -1;
public int rightMarginOriginal = -1;
public int topMarginOriginal = NOT_SET;
public int leftMarginOriginal = NOT_SET;
public int bottomMarginOriginal = NOT_SET;
public int rightMarginOriginal = NOT_SET;
public int left = 0;
public int top = 0;
@@ -252,53 +253,67 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
CommonLayoutParams lp = (CommonLayoutParams) child.getLayoutParams();
if (widthSpec != MeasureSpec.UNSPECIFIED) {
if (lp.widthPercent > 0) {
lp.widthOriginal = lp.width;
// If we get measured twice we will override the original value with the one calculated from percentValue from the first measure.
// So we set originalValue only the first time.
if (lp.widthOriginal == NOT_SET) {
lp.widthOriginal = lp.width;
}
lp.width = (int) (availableWidth * lp.widthPercent);
}
else {
lp.widthOriginal = -1;
lp.widthOriginal = NOT_SET;
}
if (lp.leftMarginPercent > 0) {
lp.leftMarginOriginal = lp.leftMargin;
if (lp.leftMarginOriginal == NOT_SET) {
lp.leftMarginOriginal = lp.leftMargin;
}
lp.leftMargin = (int) (availableWidth * lp.leftMarginPercent);
}
else {
lp.leftMarginOriginal = -1;
lp.leftMarginOriginal = NOT_SET;
}
if (lp.rightMarginPercent > 0) {
lp.rightMarginOriginal = lp.rightMargin;
if (lp.rightMarginOriginal == NOT_SET) {
lp.rightMarginOriginal = lp.rightMargin;
}
lp.rightMargin = (int) (availableWidth * lp.rightMarginPercent);
}
else {
lp.rightMarginOriginal = -1;
lp.rightMarginOriginal = NOT_SET;
}
}
if (heightSpec != MeasureSpec.UNSPECIFIED) {
if (lp.heightPercent > 0) {
lp.heightOriginal = lp.height;
if (lp.heightOriginal == NOT_SET) {
lp.heightOriginal = lp.height;
}
lp.height = (int) (availableHeight * lp.heightPercent);
}
else {
lp.heightOriginal = -1;
lp.heightOriginal = NOT_SET;
}
if (lp.topMarginPercent > 0) {
lp.topMarginOriginal = lp.topMargin;
if (lp.topMarginOriginal == NOT_SET) {
lp.topMarginOriginal = lp.topMargin;
}
lp.topMargin = (int) (availableHeight * lp.topMarginPercent);
}
else {
lp.topMarginOriginal = -1;
lp.topMarginOriginal = NOT_SET;
}
if (lp.bottomMarginPercent > 0) {
lp.bottomMarginOriginal = lp.bottomMargin;
if (lp.bottomMarginOriginal == NOT_SET) {
lp.bottomMarginOriginal = lp.bottomMargin;
}
lp.bottomMargin = (int) (availableHeight * lp.bottomMarginPercent);
}
else {
lp.bottomMarginOriginal = -1;
lp.bottomMarginOriginal = NOT_SET;
}
}
}
@@ -333,6 +348,13 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
if (lp.bottomMarginPercent > 0) {
lp.bottomMargin = lp.bottomMarginOriginal;
}
lp.widthOriginal = NOT_SET;
lp.heightOriginal = NOT_SET;
lp.leftMarginOriginal = NOT_SET;
lp.topMarginOriginal = NOT_SET;
lp.rightMarginOriginal = NOT_SET;
lp.bottomMarginOriginal = NOT_SET;
}
}
}

View File

@@ -23,8 +23,7 @@ public class ContentLayout extends LayoutBase {
int measureWidth = 0;
int measureHeight = 0;
int count = this.getChildCount();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -64,9 +63,8 @@ public class ContentLayout extends LayoutBase {
int childRight = right - left - (paddingLeft + paddingRight);
int childBottom = bottom - top - (paddingRight + paddingBottom);
int count = this.getChildCount();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -77,4 +75,4 @@ public class ContentLayout extends LayoutBase {
CommonLayoutParams.restoreOriginalParams(this);
}
}
}

View File

@@ -12,4 +12,4 @@ public enum Dock {
top,
right,
bottom
}
}

View File

@@ -175,4 +175,4 @@ public class DockLayout extends LayoutBase {
CommonLayoutParams.restoreOriginalParams(this);
}
}
}

View File

@@ -266,8 +266,7 @@ public class GridLayout extends LayoutBase {
this.helper.clearMeasureSpecs();
this.helper.init();
int childrenCount = this.getChildCount();
for (int i = 0; i < childrenCount; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -1163,4 +1162,4 @@ class MeasureHelper {
this.itemMeasured(measureSpec, false);
}
}
}

View File

@@ -11,4 +11,4 @@ public enum GridUnitType {
auto,
pixel,
star
}
}

View File

@@ -248,4 +248,4 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
}
};
}
}
}

View File

@@ -165,4 +165,4 @@ public class ImageView extends android.widget.ImageView {
super.onDraw(canvas);
}
}
}

View File

@@ -57,4 +57,4 @@ public class ItemSpec {
public int getActualLength() {
return this._actualLength;
}
}
}

View File

@@ -64,4 +64,4 @@ public abstract class LayoutBase extends ViewGroup {
return gravity;
}
}
}

View File

@@ -8,6 +8,6 @@ package org.nativescript.widgets;
*
*/
public enum Orientation {
horzontal,
horizontal,
vertical
}
}

View File

@@ -159,8 +159,7 @@ public class StackLayout extends LayoutBase {
break;
}
int count = this.getChildCount();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -203,8 +202,7 @@ public class StackLayout extends LayoutBase {
break;
}
int count = this.getChildCount();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -215,4 +213,4 @@ public class StackLayout extends LayoutBase {
childLeft += childWidth;
}
}
}
}

View File

@@ -6,4 +6,4 @@ public class TabItemSpec {
public String title;
public int iconId;
public Drawable iconDrawable;
}
}

View File

@@ -166,4 +166,4 @@ class TabStrip extends LinearLayout {
mIndicatorColors = colors;
}
}
}
}

View File

@@ -77,7 +77,7 @@ public class VerticalScrollView extends ScrollView {
this.setPadding(0, 0, 0, 0);
}
else {
CommonLayoutParams.measureChild(child, widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
CommonLayoutParams.measureChild(child, widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
@@ -188,4 +188,4 @@ public class VerticalScrollView extends ScrollView {
this.scrollBy(scrollDelta, 0);
}
}
}
}

View File

@@ -15,7 +15,7 @@ public class WrapLayout extends LayoutBase {
private int _itemWidth = -1;
private int _itemHeight = -1;
private Orientation _orientation = Orientation.horzontal;
private Orientation _orientation = Orientation.horizontal;
private ArrayList<Integer> _lengths = new ArrayList<Integer>();
public WrapLayout(Context context) {
@@ -58,6 +58,24 @@ public class WrapLayout extends LayoutBase {
}
}
private int getDesiredWidth(View child) {
if (this._itemWidth > 0) {
return this._itemWidth;
}
// Add margins because layoutChild will subtract them.
return CommonLayoutParams.getDesiredWidth(child);
}
private int getDesiredHeight(View child) {
if (this._itemHeight > 0) {
return this._itemHeight;
}
// Add margins because layoutChild will subtract them.
return CommonLayoutParams.getDesiredHeight(child);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
@@ -65,44 +83,42 @@ public class WrapLayout extends LayoutBase {
int measureWidth = 0;
int measureHeight = 0;
int width = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
boolean isVertical = this._orientation == Orientation.vertical;
int verticalPadding = this.getPaddingTop() + this.getPaddingBottom();
int horizontalPadding = this.getPaddingLeft() + this.getPaddingRight();
int childWidthMeasureSpec = getViewMeasureSpec(widthMode, width, this._itemWidth);
int childHeightMeasureSpec = getViewMeasureSpec(heightMode, height, this._itemHeight);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int remainingWidth = widthMode == MeasureSpec.UNSPECIFIED ? Integer.MAX_VALUE : width - horizontalPadding;
int remainingHeight = heightMode == MeasureSpec.UNSPECIFIED ? Integer.MAX_VALUE : height - verticalPadding;
int availableWidth = widthMode == MeasureSpec.UNSPECIFIED ? Integer.MAX_VALUE : MeasureSpec.getSize(widthMeasureSpec) - horizontalPadding;
int availableHeight = heightMode == MeasureSpec.UNSPECIFIED ? Integer.MAX_VALUE : MeasureSpec.getSize(heightMeasureSpec) - verticalPadding;
int childWidthMeasureSpec = getViewMeasureSpec(widthMode, availableWidth, this._itemWidth);
int childHeightMeasureSpec = getViewMeasureSpec(heightMode, availableHeight, this._itemHeight);
int remainingWidth = availableWidth;
int remainingHeight = availableHeight;
int count = this.getChildCount();
this._lengths.clear();
int rowOrColumn = 0;
int maxLength = 0;
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
}
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
final int childMeasuredWidth = this.getDesiredWidth(child);
final int childMeasuredHeight = this.getDesiredHeight(child);
if (isVertical) {
if (childMeasuredHeight > remainingHeight) {
rowOrColumn++;
maxLength = Math.max(maxLength, measureHeight);
measureHeight = childMeasuredHeight;
remainingWidth = height - childMeasuredHeight;
remainingWidth = availableHeight - childMeasuredHeight;
this._lengths.add(rowOrColumn, childMeasuredWidth);
}
else {
@@ -115,7 +131,7 @@ public class WrapLayout extends LayoutBase {
rowOrColumn++;
maxLength = Math.max(maxLength, measureWidth);
measureWidth = childMeasuredWidth;
remainingWidth = width - childMeasuredWidth;
remainingWidth = availableWidth - childMeasuredWidth;
this._lengths.add(rowOrColumn, childMeasuredHeight);
}
else {
@@ -132,16 +148,15 @@ public class WrapLayout extends LayoutBase {
}
}
count = this._lengths.size();
if (isVertical) {
measureHeight = Math.max(maxLength, measureHeight);
for (int i = 0; i < count; i++) {
for (int i = 0, count = this._lengths.size(); i < count; i++) {
measureWidth += this._lengths.get(i);
}
}
else {
measureWidth = Math.max(maxLength, measureWidth);
for (int i = 0; i < count; i++) {
for (int i = 0, count = this._lengths.size(); i < count; i++) {
measureHeight += this._lengths.get(i);
}
}
@@ -173,21 +188,18 @@ public class WrapLayout extends LayoutBase {
int childrenLength = isVertical ? bottom - top - paddingBottom : right - left - paddingRight;
int rowOrColumn = 0;
int count = this.getChildCount();
for (int i = 0; i < count; i++) {
for (int i = 0, count = this.getChildCount(); i < count; i++) {
View child = this.getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
}
// Add margins because layoutChild will subtract them.
int childWidth = CommonLayoutParams.getDesiredWidth(child);
int childHeight = CommonLayoutParams.getDesiredHeight(child);
int childWidth = this.getDesiredWidth(child);
int childHeight = this.getDesiredHeight(child);
int length = this._lengths.get(rowOrColumn);
if (isVertical) {
childWidth = length;
childHeight = this._itemHeight > 0 ? this._itemHeight : childHeight;
if (childTop + childHeight > childrenLength) {
// Move to top.
childTop = paddingTop;
@@ -203,7 +215,6 @@ public class WrapLayout extends LayoutBase {
}
}
else {
childWidth = this._itemWidth > 0 ? this._itemWidth : childWidth;
childHeight = length;
if (childLeft + childWidth > childrenLength) {
// Move to left.