Skip to content

Commit

Permalink
Merge pull request #3 from GautamGupta/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
GautamGupta committed Apr 12, 2016
2 parents de385e0 + 5563dd2 commit faf25d5
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 119 deletions.
71 changes: 68 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,85 @@
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+ (`minSdkVersion 14`).

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
<am.gaut.android.toolbarbutton.ToolbarButton
android:id="@+id/btn_toolbar_checkin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/borderlessButtonStyle"
android:background="@drawable/selector_toolbar_button"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.Button.Inverse"
android:paddingLeft="@dimen/toolbar_button_padding"
android:paddingRight="@dimen/toolbar_button_padding"
android:drawablePadding="@dimen/toolbar_button_padding"
android:drawableLeft="@drawable/ic_message_white_18dp"
android:drawableStart="@drawable/ic_message_white_18dp"
android:text="@string/checkin"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="right|end" />
```

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),
[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. Why is this happening?**

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?**

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
Expand All @@ -34,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.
```
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
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'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
10 changes: 3 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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`
Expand Down
180 changes: 90 additions & 90 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -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
37 changes: 28 additions & 9 deletions toolbarbutton/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
}
}

Expand All @@ -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'
Loading

0 comments on commit faf25d5

Please sign in to comment.