From 08cad279c035a1efea2cb0f2b5270d8575a5cae6 Mon Sep 17 00:00:00 2001 From: Gautam Gupta Date: Mon, 11 Apr 2016 22:19:10 -0400 Subject: [PATCH 1/5] Add properties to upload to bintray maven Following http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en --- app/build.gradle | 6 ++-- build.gradle | 4 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- toolbarbutton/build.gradle | 37 ++++++++++++++++++------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2f7239a..8c0af2e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "23.0.2" defaultConfig { applicationId "com.support.android.designlibdemo" minSdkVersion 14 targetSdkVersion 23 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.1" } buildTypes { release { diff --git a/build.gradle b/build.gradle index c0b83ec..2efb9f7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,9 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:1.5.0' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c71e76..e7faee0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip diff --git a/toolbarbutton/build.gradle b/toolbarbutton/build.gradle index dfd43ea..09a1a17 100644 --- a/toolbarbutton/build.gradle +++ b/toolbarbutton/build.gradle @@ -1,20 +1,36 @@ apply plugin: 'com.android.library' +ext { + bintrayRepo = 'maven' + bintrayName = 'toolbar-button' + + publishedGroupId = 'am.gaut.android.toolbarbutton' + libraryName = 'ToolbarButton' + artifact = 'toolbarbutton' + + libraryDescription = 'FAB to Toolbar Button library for Android Material Collapsing Toolbar' + + siteUrl = 'https://github.com/GautamGupta/toolbar-button' + gitUrl = 'https://github.com/GautamGupta/toolbar-button.git' + + libraryVersion = '0.1.0' + + developerId = 'gautamgupta' + developerName = 'Gautam Gupta' + developerEmail = 'gautam@gaut.am' + + licenseName = 'The Apache Software License, Version 2.0' + licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + allLicenses = ["Apache-2.0"] +} + android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "23.0.2" defaultConfig { minSdkVersion 14 targetSdkVersion 23 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } } } @@ -24,3 +40,6 @@ dependencies { exclude module: 'shared' } } + +apply from: 'https://raw.githubusercontent.com/GautamGupta/JCenter/master/installv1.gradle' +apply from: 'https://raw.githubusercontent.com/GautamGupta/JCenter/master/bintrayv1.gradle' From 043e610ad20653f3daebbbaedc56e65df7c32234 Mon Sep 17 00:00:00 2001 From: Gautam Gupta Date: Mon, 11 Apr 2016 23:16:57 -0400 Subject: [PATCH 2/5] Upgrade grade, fix javadocs. --- gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 10 +- gradlew.bat | 180 +++++++++--------- .../helpers/CollapsingToolbarHelper.java | 8 +- 4 files changed, 99 insertions(+), 103 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e7faee0..3d08daf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Mon Apr 11 23:05:33 EDT 2016 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 +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/gradlew b/gradlew index 91a7e26..9d82f78 100755 --- a/gradlew +++ b/gradlew @@ -42,11 +42,6 @@ case "`uname`" in ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -114,6 +109,7 @@ fi 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` diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..aec9973 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,90 +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 +@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 diff --git a/toolbarbutton/src/main/java/am/gaut/android/toolbarbutton/helpers/CollapsingToolbarHelper.java b/toolbarbutton/src/main/java/am/gaut/android/toolbarbutton/helpers/CollapsingToolbarHelper.java index ab9a3e9..225e13e 100644 --- a/toolbarbutton/src/main/java/am/gaut/android/toolbarbutton/helpers/CollapsingToolbarHelper.java +++ b/toolbarbutton/src/main/java/am/gaut/android/toolbarbutton/helpers/CollapsingToolbarHelper.java @@ -18,7 +18,7 @@ public class CollapsingToolbarHelper { private static final Matrix IDENTITY = new Matrix(); /** - * Borrowed from {@link android.support.design.widget.AppBarLayout} + * Borrowed from android.support.design.widget.AppBarLayout */ public static int getMinimumHeightForVisibleOverlappingContent(ViewGroup appBarLayout) { final int topInset = getTopInset(appBarLayout); @@ -37,7 +37,7 @@ public static int getMinimumHeightForVisibleOverlappingContent(ViewGroup appBarL /** * Hack since we don't have access to the private - * {@link android.support.design.widget.AppBarLayout getTopInset()} method + * android.support.design.widget.AppBarLayout.getTopInset() method */ public static int getTopInset(ViewGroup appBarLayout) { int inset = 0; @@ -51,8 +51,8 @@ public static int getTopInset(ViewGroup appBarLayout) { } /** - * Honeycomb IMPL borrowed from {@link android.support.design.widget.ViewGroupUtils} and - * {@link android.support.design.widget.ViewGroupUtilsHoneycomb} + * Honeycomb IMPL borrowed from android.support.design.widget.ViewGroupUtils and + * android.support.design.widget.ViewGroupUtilsHoneycomb */ public static void getDescendantRect(ViewGroup parent, View descendant, Rect out) { From 477dfe388754aabdcfd5996001fecacf1f96ed76 Mon Sep 17 00:00:00 2001 From: Gautam Gupta Date: Tue, 12 Apr 2016 00:22:59 -0400 Subject: [PATCH 3/5] Update readme and gradle --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++--- build.gradle | 2 +- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 95c795b..5e4560b 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,78 @@ Android Toolbar Button Library ============================== +The problem with anchoring a floating action button to a collapsing toolbar is that the CTA gets +hidden on scroll. This library allows you to artificially add a button in the toolbar with an +animation as soon as the FAB hides itself. +Works with Android 4.0+ ( -Pre-requisites --------------- +Gradle +------ + +``` +dependencies { + ... + compile 'com.android.support:design:23.2.1' + compile 'am.gaut.android.toolbarbutton:toolbarbutton:0.1.0' +} +``` + +Usage +----- + +Add this at the same level where your floating action button is defined in the activity. +[Example](https://github.com/GautamGupta/toolbar-button/blob/master/app/src/main/res/layout/activity_detail.xml#L155-L169). + +```xml + +``` + +Treat the element as a button. Properties in the snippet produce a similar result as in the screen +capture. + +`@dimen/toolbar_button_padding` (16dp), `@drawable/selector_toolbar_button` +([see](https://github.com/GautamGupta/toolbar-button/blob/master/toolbarbutton/src/main/res/drawable/selector_toolbar_button.xml), +[v21](https://github.com/GautamGupta/toolbar-button/blob/master/toolbarbutton/src/main/res/drawable-v21/selector_toolbar_button.xml)) +are supplied by the library. + +`@drawable/ic_message_white_18dp` is a [material icon](https://design.google.com/icons/#ic_message). + +`?attr/borderlessButtonStyle` and `@style/TextAppearance.AppCompat.Widget.Button.Inverse` come from +the design support library. Credits ------- - [Gordon Evans](https://www.linkedin.com/in/gjrevans) for concept - - Awesome folks at [Wirkn](http://wirkn.com/) for letting me open source this (where the idea originated from) + - Awesome folks at [Wirkn](http://wirkn.com/) (where the idea originated from), h/t [Joseph Voung](https://www.linkedin.com/in/josephwongcl) - [Cheesesquare](https://github.com/chrisbanes/cheesesquare) by Chris Banes for the material design demo app +Troubleshooting +--------------- + +*Q. The button hides on scroll* +The default elevation of 6dp (elevation of a FAB) is getting overridden. Try adding +`elevation="6dp"` property on the element. + +*Q. Does this work for Android versions before 4.0?* +It can be made to work for previous Android versions as well, using different implementation classes +like the Floating Action Button. If you take up the initiative, please submit a PR. + License ------- diff --git a/build.gradle b/build.gradle index 2efb9f7..3bf4928 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.5.0' + classpath 'com.android.tools.build:gradle:2.0.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' } From 983c4375b2e6a9d522bec3094cd5a18c00ab9d5e Mon Sep 17 00:00:00 2001 From: Gautam Gupta Date: Tue, 12 Apr 2016 00:27:46 -0400 Subject: [PATCH 4/5] Update read --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5e4560b..ce58925 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The problem with anchoring a floating action button to a collapsing toolbar is t hidden on scroll. This library allows you to artificially add a button in the toolbar with an animation as soon as the FAB hides itself. -Works with Android 4.0+ ( +Works with Android 4.0+ (`minSdkVersion 14`). Gradle @@ -45,8 +45,9 @@ Add this at the same level where your floating action button is defined in the a app:layout_anchorGravity="right|end" /> ``` -Treat the element as a button. Properties in the snippet produce a similar result as in the screen -capture. +You can treat the view as a +[Button](http://developer.android.com/reference/android/widget/Button.html). +Properties in the snippet produce a similar result as in the screen capture. `@dimen/toolbar_button_padding` (16dp), `@drawable/selector_toolbar_button` ([see](https://github.com/GautamGupta/toolbar-button/blob/master/toolbarbutton/src/main/res/drawable/selector_toolbar_button.xml), @@ -67,17 +68,20 @@ Credits Troubleshooting --------------- -*Q. The button hides on scroll* +**Q. The button hides on scroll** + The default elevation of 6dp (elevation of a FAB) is getting overridden. Try adding `elevation="6dp"` property on the element. -*Q. Does this work for Android versions before 4.0?* +**Q. Does this work for Android versions before 4.0?** + It can be made to work for previous Android versions as well, using different implementation classes like the Floating Action Button. If you take up the initiative, please submit a PR. License ------- +``` Copyright 2016 Gautam Gupta Licensed to the Apache Software Foundation (ASF) under one or more contributor @@ -94,3 +98,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +``` \ No newline at end of file From 8c37f6f696213482b7e574f1307d862d89c0d196 Mon Sep 17 00:00:00 2001 From: Gautam Gupta Date: Tue, 12 Apr 2016 00:30:16 -0400 Subject: [PATCH 5/5] Update readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce58925..abac6cb 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,10 @@ Credits Troubleshooting --------------- -**Q. The button hides on scroll** +**Q. The button hides on scroll. Why is this happening?** -The default elevation of 6dp (elevation of a FAB) is getting overridden. Try adding -`elevation="6dp"` property on the element. +The default elevation of 6dp is getting overridden, making it compete with the elevation of the +appbar. Try adding `android:elevation="6dp"` property on the view. **Q. Does this work for Android versions before 4.0?**