├── .gitignore
├── LICENSE.txt
├── README.md
├── build.gradle
├── changelog.md
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── consumer-proguard-rules.pro
├── gradle-mvn-push.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ └── org.eclipse.jdt.core.prefs
│ ├── AndroidManifest.xml
│ ├── bin
│ ├── AndroidManifest.xml
│ └── classes
│ │ └── com
│ │ └── getbase
│ │ └── floatingactionbutton
│ │ ├── AddFloatingActionButton$1.class
│ │ ├── AddFloatingActionButton.class
│ │ ├── BuildConfig.class
│ │ ├── FloatingActionButton$1.class
│ │ ├── FloatingActionButton$FAB_SIZE.class
│ │ ├── FloatingActionButton$TranslucentLayerDrawable.class
│ │ ├── FloatingActionButton.class
│ │ ├── FloatingActionsMenu$LayoutParams.class
│ │ ├── FloatingActionsMenu$OnFloatingActionsMenuUpdateListener.class
│ │ ├── FloatingActionsMenu$RotatingDrawable.class
│ │ ├── FloatingActionsMenu$SavedState.class
│ │ ├── FloatingActionsMenu.class
│ │ ├── R$attr.class
│ │ ├── R$dimen.class
│ │ ├── R$drawable.class
│ │ ├── R$id.class
│ │ ├── R$styleable.class
│ │ └── R.class
│ ├── java
│ └── cc
│ │ └── trity
│ │ └── floatingactionbutton
│ │ ├── AddFloatingActionButton.java
│ │ ├── FloatingActionButton.java
│ │ ├── FloatingActionsMenu.java
│ │ └── TouchDelegateGroup.java
│ ├── project.properties
│ ├── res
│ ├── drawable-hdpi
│ │ ├── fab_bg_mini.png
│ │ └── fab_bg_normal.png
│ ├── drawable-mdpi
│ │ ├── fab_bg_mini.png
│ │ └── fab_bg_normal.png
│ ├── drawable-xhdpi
│ │ ├── club_icon_ubac.png
│ │ ├── fab_bg_mini.png
│ │ └── fab_bg_normal.png
│ ├── drawable-xxhdpi
│ │ ├── fab_bg_mini.png
│ │ └── fab_bg_normal.png
│ ├── drawable-xxxhdpi
│ │ ├── fab_bg_mini.png
│ │ └── fab_bg_normal.png
│ └── values
│ │ ├── attrs.xml
│ │ ├── dimens.xml
│ │ └── ids.xml
│ └── src
│ └── com
│ └── getbase
│ └── floatingactionbutton
│ ├── AddFloatingActionButton.java
│ ├── FloatingActionButton.java
│ └── FloatingActionsMenu.java
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── getbase
│ │ └── floatingactionbutton
│ │ └── sample
│ │ └── MainActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_fab_star.png
│ ├── drawable-mdpi
│ └── ic_fab_star.png
│ ├── drawable-xhdpi
│ └── ic_fab_star.png
│ ├── drawable-xxhdpi
│ └── ic_fab_star.png
│ ├── drawable
│ └── fab_label_background.xml
│ ├── layout
│ └── activity_main.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── themes.xml
├── screenshots
├── buttons.png
├── custom.png
├── labels.png
└── menu.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 |
8 | gen
9 |
10 | .idea
11 | *.iml
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2014 Jerzy Chalupski
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | FloatingActionButton
2 | ====================
3 | Yet another library for drawing [Material Design promoted actions](http://www.google.com/design/spec/patterns/promoted-actions.html).
4 |
5 | Features
6 | ========
7 | * Support for normal `56dp` and mini `40dp` buttons.
8 |
9 | 
10 |
11 | * Customizable background colors for normal and pressed states and icon drawable.
12 |
13 | 
14 |
15 | * Convenience `AddFloatingActionButton` class with plus icon drawn in code.
16 | * `FloatingActionsMenu` which can be expanded/collapsed to reveal multiple actions.
17 |
18 | 
19 |
20 | * Optional labels for buttons in `FloatingActionsMenu`.
21 |
22 | 
23 | * To change the menu icon ` fab:fab_bitmap="@drawable/club_icon_ubac"` and To change the button rotation `fab:fab_rotation="180"`
24 |
25 | 
26 |
27 |
28 | Usage
29 | =====
30 | Just add the dependency to your `build.gradle`:
31 |
32 | ```groovy
33 | dependencies {
34 | compile 'cc.trity.floatingactionbutton:library:1.0.0'
35 | }
36 | ```
37 |
38 | To see how the buttons are added to your xml layouts, check the sample project.
39 |
40 | Caveats
41 | =======
42 | The API is **extremely** limited at the moment. It solves few select use cases in the app I'm working on.
43 |
44 | Unlike some other FloatingActionButton libraries this library doesn't implement "quick return" pattern, i.e. hiding the button on scrolling down and showing it on scrolling up. That's intentional, I think that should be responsibility of another component, not the button itself.
45 |
46 | This library is `minSdkVersion=14` and if that changes, the version number will be increased, not decreased. It means that Honeycomb, Gingerbread or - gods forbid - Froyo, won't ever be supported. I won't even consider merging pull requests fully implementing support for older versions. We need to move on as Android community and focus on delivering value for 95% of users of modern Android OS instead of jumping through burning hoops to support ancient devices with ancient OS.
47 |
48 | If you **really** require support for older Android versions, [str4d](https://github.com/str4d) maintains [a version of this library with `minSdkVersion=4`](https://github.com/str4d/android-floating-action-button).
49 |
50 | Credits
51 | =======
52 | I used [FloatingActionButton](https://github.com/makovkastar/FloatingActionButton) library by [Oleksandr Melnykov](https://github.com/makovkastar) as a base for development.
53 |
54 | License
55 | =======
56 |
57 | Copyright (C) 2014 Jerzy Chalupski
58 |
59 | Licensed under the Apache License, Version 2.0 (the "License");
60 | you may not use this file except in compliance with the License.
61 | You may obtain a copy of the License at
62 |
63 | http://www.apache.org/licenses/LICENSE-2.0
64 |
65 | Unless required by applicable law or agreed to in writing, software
66 | distributed under the License is distributed on an "AS IS" BASIS,
67 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68 | See the License for the specific language governing permissions and
69 | limitations under the License.
70 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:1.0.0'
10 | classpath 'com.github.dcendents:android-maven-plugin:1.2'
11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.9.0 *(2015-03-14)*
5 | ----------------------------
6 |
7 | * Labels are now clickable
8 |
9 | Version 1.8.0 *(2015-02-18)*
10 | ----------------------------
11 |
12 | * Added `fab_labelsPosition` attribute
13 | * Fixed issue with labels style being overridden by theme style
14 |
15 | Version 1.7.0 *(2015-02-01)*
16 | ----------------------------
17 |
18 | * Added removeButton API to FloatingActionsMenu
19 | * Fixed NPEs related to incorrect animators initialization
20 | * Fixed labels positions for FloatingActionsMenu with mini add button
21 |
22 | Version 1.6.0 *(2015-01-16)*
23 | ----------------------------
24 |
25 | * Added disabled state for FloatingActionButton background
26 | * Added button size attribute for FloatingActionsMenu add button
27 |
28 | Version 1.5.1 *(2014-12-30)*
29 | ----------------------------
30 |
31 | * Fixed setting FloatingActionButton icon with `fab_icon` XML attribute
32 | * Fixed issues with changing visibility of FloatingActionButtons inside FloatingActionsMenu
33 |
34 |
35 | Version 1.5.0 *(2014-12-30)*
36 | ----------------------------
37 |
38 | * Added icon drawable setter for FloatingActionButton
39 | * Better looking strokes of FloatingActionButtons
40 | * Option to disable strokes of FloatingActionButton
41 |
42 | Version 1.4.0 *(2014-12-21)*
43 | ----------------------------
44 |
45 | * Added labels setter for FloatingActionButton
46 | * Reduce memory footprint of FloatingActionButton and fix OOM issues.
47 |
48 | Version 1.3.0 *(2014-12-08)*
49 | ----------------------------
50 |
51 | * Added support for labels in FloatingActionsMenu expanding in vertical direction.
52 |
53 | Version 1.2.1 *(2014-12-04)*
54 | ----------------------------
55 |
56 | * Fixed IDE error when using `setSize(FloatingActionButton.SIZE_FOO)` setter.
57 |
58 | Version 1.2.0 *(2014-12-02)*
59 | ----------------------------
60 |
61 | * Fixed horizontal alignment of mini FloatingActionButtons in FloatingActionsMenu
62 | * Added support for different FloatingActionsMenu expand directions
63 | * Support transparent buttons
64 | * Added xxxhdpi drawables
65 | * Added consumer proguard configuration to library
66 | * Added getters and setters for FloatingActionButton properties
67 | * Exposed FloatingActionsMenu isExpanded property
68 |
69 | Version 1.1.0 *(2014-10-23)*
70 | ----------------------------
71 |
72 | * Fixed issue with broken animation state after screen rotation
73 | * Fixed name clash with appcompat v21. All FloatingActionButton attributes are now prefixed with 'fab_' prefix
74 |
75 | Version 1.0.0 *(2014-09-19)*
76 | ----------------------------
77 |
78 | * Initial release.
79 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | VERSION_NAME=1.9.0
21 | VERSION_CODE=12
22 | GROUP=com.getbase
23 |
24 | POM_DESCRIPTION=Floating Action Button for Android based on Material Design specification
25 | POM_URL=https://github.com/futuresimple/android-floating-action-button
26 | POM_SCM_URL=https://github.com/futuresimple/android-floating-action-button
27 | POM_SCM_CONNECTION=scm:git:git://github.com/futuresimple/android-floating-action-button.git
28 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/futuresimple/android-floating-action-button.git
29 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
30 | POM_LICENCE_URL=https://github.com/futuresimple/android-floating-action-button/blob/master/LICENSE.txt
31 | POM_LICENCE_DIST=repo
32 | POM_DEVELOPER_ID=chalup
33 | POM_DEVELOPER_NAME=Jerzy Chalupski
34 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 27 11:18:21 CET 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/build.gradle
--------------------------------------------------------------------------------
/library/consumer-proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # keep getters/setters in RotatingDrawable so that animations can still work.
2 | -keepclassmembers class com.getbase.floatingactionbutton.FloatingActionsMenu$RotatingDrawable {
3 | void set*(***);
4 | *** get*();
5 | }
6 |
--------------------------------------------------------------------------------
/library/gradle-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return VERSION_NAME.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | def getRepositoryUsername() {
35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
36 | }
37 |
38 | def getRepositoryPassword() {
39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
40 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | repositories {
45 | mavenDeployer {
46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
47 |
48 | pom.groupId = GROUP
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.version = VERSION_NAME
51 |
52 | repository(url: getReleaseRepositoryUrl()) {
53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
57 | }
58 |
59 | pom.project {
60 | name POM_NAME
61 | packaging POM_PACKAGING
62 | description POM_DESCRIPTION
63 | url POM_URL
64 |
65 | scm {
66 | url POM_SCM_URL
67 | connection POM_SCM_CONNECTION
68 | developerConnection POM_SCM_DEV_CONNECTION
69 | }
70 |
71 | licenses {
72 | license {
73 | name POM_LICENCE_NAME
74 | url POM_LICENCE_URL
75 | distribution POM_LICENCE_DIST
76 | }
77 | }
78 |
79 | developers {
80 | developer {
81 | id POM_DEVELOPER_ID
82 | name POM_DEVELOPER_NAME
83 | }
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
90 | task installArchives(type: Upload) {
91 | description "Installs the artifacts to the local Maven repository."
92 | configuration = configurations['archives']
93 | repositories {
94 | mavenDeployer {
95 | pom.groupId = GROUP
96 | pom.artifactId = POM_ARTIFACT_ID
97 | pom.version = VERSION_NAME
98 |
99 | repository url: "file://${System.properties['user.home']}/.m2/repository"
100 | }
101 | }
102 | }
103 |
104 | signing {
105 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
106 | sign configurations.archives
107 | }
108 |
109 | task androidJavadocs(type: Javadoc) {
110 | source = android.sourceSets.main.java.srcDirs
111 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
112 | }
113 |
114 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
115 | classifier = 'javadoc'
116 | from androidJavadocs.destinationDir
117 | }
118 |
119 | task androidSourcesJar(type: Jar) {
120 | classifier = 'sources'
121 | from android.sourceSets.main.java.sourceFiles
122 | }
123 |
124 | artifacts {
125 | archives androidSourcesJar
126 | archives androidJavadocsJar
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=FloatingActionButton
2 | POM_ARTIFACT_ID=floatingactionbutton
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio Beta.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | main
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/library/src/main/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/AddFloatingActionButton$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/AddFloatingActionButton$1.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/AddFloatingActionButton.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/AddFloatingActionButton.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/BuildConfig.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton$1.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton$FAB_SIZE.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton$FAB_SIZE.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton$TranslucentLayerDrawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton$TranslucentLayerDrawable.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionButton.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$LayoutParams.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$LayoutParams.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$OnFloatingActionsMenuUpdateListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$OnFloatingActionsMenuUpdateListener.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$RotatingDrawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$RotatingDrawable.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$SavedState.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu$SavedState.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/FloatingActionsMenu.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$attr.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$dimen.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$drawable.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$id.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$styleable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/R$styleable.class
--------------------------------------------------------------------------------
/library/src/main/bin/classes/com/getbase/floatingactionbutton/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/bin/classes/com/getbase/floatingactionbutton/R.class
--------------------------------------------------------------------------------
/library/src/main/java/cc/trity/floatingactionbutton/AddFloatingActionButton.java:
--------------------------------------------------------------------------------
1 | package cc.trity.floatingactionbutton;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.Paint.Style;
10 | import android.graphics.drawable.Drawable;
11 | import android.graphics.drawable.ShapeDrawable;
12 | import android.graphics.drawable.shapes.Shape;
13 | import android.support.annotation.ColorRes;
14 | import android.support.annotation.DrawableRes;
15 | import android.util.AttributeSet;
16 |
17 | public class AddFloatingActionButton extends FloatingActionButton {
18 | int mPlusColor;
19 |
20 |
21 | public AddFloatingActionButton(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public AddFloatingActionButton(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public AddFloatingActionButton(Context context, AttributeSet attrs, int defStyle) {
30 | super(context, attrs, defStyle);
31 | }
32 |
33 | @Override
34 | void init(Context context, AttributeSet attributeSet) {
35 | TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.AddFloatingActionButton, 0, 0);
36 | mPlusColor = attr.getColor(R.styleable.AddFloatingActionButton_fab_plusIconColor, getColor(android.R.color.white));
37 | attr.recycle();
38 |
39 | super.init(context, attributeSet);
40 | }
41 |
42 | /**
43 | * @return the current Color of plus icon.
44 | */
45 | public int getPlusColor() {
46 | return mPlusColor;
47 | }
48 |
49 | public void setPlusColorResId(@ColorRes int plusColor) {
50 | setPlusColor(getColor(plusColor));
51 | }
52 |
53 | public void setPlusColor(int color) {
54 | if (mPlusColor != color) {
55 | mPlusColor = color;
56 | updateBackground();
57 | }
58 | }
59 |
60 | @Override
61 | public void setIcon(@DrawableRes int icon) {
62 | throw new UnsupportedOperationException("Use FloatingActionButton if you want to use custom icon");
63 | }
64 |
65 | @Override
66 | Drawable getIconDrawable() {
67 | final float iconSize = getDimension(R.dimen.fab_icon_size_12);
68 | final float iconHalfSize = iconSize / 2f;
69 |
70 | final float plusSize = getDimension(R.dimen.fab_plus_icon_size);
71 | final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f;
72 | final float plusOffset = (iconSize - plusSize) / 2f;
73 |
74 | final Shape shape = new Shape() {
75 | @Override
76 | public void draw(Canvas canvas, Paint paint) {
77 | canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint);
78 | canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint);
79 | }
80 | };
81 | ShapeDrawable drawable = new ShapeDrawable(shape);
82 |
83 | final Paint paint = drawable.getPaint();
84 | paint.setColor(mPlusColor);
85 | paint.setStyle(Style.FILL);
86 | paint.setAntiAlias(true);
87 |
88 | return drawable;
89 | }
90 | public Drawable getBitmapDrawable(final int resIcon) {
91 |
92 | final Shape shape = new Shape() {
93 | @Override
94 | public void draw(Canvas canvas, Paint paint) {
95 | Bitmap iconbit = BitmapFactory.decodeResource(getResources(), resIcon) ;
96 | canvas.drawBitmap(iconbit,0,0,paint);
97 | }
98 | };
99 | ShapeDrawable drawable = new ShapeDrawable(shape);
100 |
101 | final Paint paint = drawable.getPaint();
102 | paint.setColor(mPlusColor);
103 | paint.setStyle(Style.FILL);
104 | paint.setAntiAlias(true);
105 |
106 | return drawable;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/library/src/main/java/cc/trity/floatingactionbutton/FloatingActionButton.java:
--------------------------------------------------------------------------------
1 | package cc.trity.floatingactionbutton;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.LinearGradient;
9 | import android.graphics.Paint;
10 | import android.graphics.Paint.Style;
11 | import android.graphics.Rect;
12 | import android.graphics.Shader;
13 | import android.graphics.Shader.TileMode;
14 | import android.graphics.drawable.ColorDrawable;
15 | import android.graphics.drawable.Drawable;
16 | import android.graphics.drawable.LayerDrawable;
17 | import android.graphics.drawable.ShapeDrawable;
18 | import android.graphics.drawable.ShapeDrawable.ShaderFactory;
19 | import android.graphics.drawable.StateListDrawable;
20 | import android.graphics.drawable.shapes.OvalShape;
21 | import android.os.Build;
22 | import android.os.Build.VERSION_CODES;
23 | import android.support.annotation.ColorRes;
24 | import android.support.annotation.DimenRes;
25 | import android.support.annotation.DrawableRes;
26 | import android.support.annotation.IntDef;
27 | import android.support.annotation.NonNull;
28 | import android.util.AttributeSet;
29 | import android.widget.ImageButton;
30 | import android.widget.TextView;
31 |
32 | import java.lang.annotation.Retention;
33 | import java.lang.annotation.RetentionPolicy;
34 |
35 | public class FloatingActionButton extends ImageButton {
36 |
37 | public static final int SIZE_NORMAL = 0;
38 | public static final int SIZE_MINI = 1;
39 |
40 | @Retention(RetentionPolicy.SOURCE)
41 | @IntDef({ SIZE_NORMAL, SIZE_MINI })
42 | public @interface FAB_SIZE {
43 | }
44 |
45 | int mColorNormal;
46 | int mColorPressed;
47 | int mColorDisabled;
48 | String mTitle;
49 | @DrawableRes
50 | private int mIcon;
51 | private Drawable mIconDrawable;
52 | private int mSize;
53 |
54 | private float mCircleSize;
55 | private float mShadowRadius;
56 | private float mShadowOffset;
57 | private int mDrawableSize;
58 | boolean mStrokeVisible;
59 |
60 | public FloatingActionButton(Context context) {
61 | this(context, null);
62 | }
63 |
64 | public FloatingActionButton(Context context, AttributeSet attrs) {
65 | super(context, attrs);
66 | init(context, attrs);
67 | }
68 |
69 | public FloatingActionButton(Context context, AttributeSet attrs, int defStyle) {
70 | super(context, attrs, defStyle);
71 | init(context, attrs);
72 | }
73 |
74 | void init(Context context, AttributeSet attributeSet) {
75 | TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionButton, 0, 0);
76 | mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, getColor(android.R.color.holo_blue_dark));
77 | mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, getColor(android.R.color.holo_blue_light));
78 | mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, getColor(android.R.color.darker_gray));
79 | mSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
80 | mIcon = attr.getResourceId(R.styleable.FloatingActionButton_fab_icon, 0);
81 | mTitle = attr.getString(R.styleable.FloatingActionButton_fab_title);
82 | mStrokeVisible = attr.getBoolean(R.styleable.FloatingActionButton_fab_stroke_visible, true);
83 | attr.recycle();
84 |
85 | updateCircleSize();
86 | mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
87 | mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
88 | updateDrawableSize();
89 |
90 | updateBackground();
91 | }
92 |
93 | private void updateDrawableSize() {
94 | mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);
95 | }
96 |
97 | private void updateCircleSize() {
98 | mCircleSize = getDimension(mSize == SIZE_NORMAL ? R.dimen.fab_size_normal : R.dimen.fab_size_mini);
99 | }
100 |
101 | public void setSize(@FAB_SIZE int size) {
102 | if (size != SIZE_MINI && size != SIZE_NORMAL) {
103 | throw new IllegalArgumentException("Use @FAB_SIZE constants only!");
104 | }
105 |
106 | if (mSize != size) {
107 | mSize = size;
108 | updateCircleSize();
109 | updateDrawableSize();
110 | updateBackground();
111 | }
112 | }
113 |
114 | @FAB_SIZE
115 | public int getSize() {
116 | return mSize;
117 | }
118 |
119 | public void setIcon(@DrawableRes int icon) {
120 | if (mIcon != icon) {
121 | mIcon = icon;
122 | mIconDrawable = null;
123 | updateBackground();
124 | }
125 | }
126 |
127 | public void setIconDrawable(@NonNull Drawable iconDrawable) {
128 | if (mIconDrawable != iconDrawable) {
129 | mIcon = 0;
130 | mIconDrawable = iconDrawable;
131 | updateBackground();
132 | }
133 | }
134 |
135 | /**
136 | * @return the current Color for normal state.
137 | */
138 | public int getColorNormal() {
139 | return mColorNormal;
140 | }
141 |
142 | public void setColorNormalResId(@ColorRes int colorNormal) {
143 | setColorNormal(getColor(colorNormal));
144 | }
145 |
146 | public void setColorNormal(int color) {
147 | if (mColorNormal != color) {
148 | mColorNormal = color;
149 | updateBackground();
150 | }
151 | }
152 |
153 | /**
154 | * @return the current color for pressed state.
155 | */
156 | public int getColorPressed() {
157 | return mColorPressed;
158 | }
159 |
160 | public void setColorPressedResId(@ColorRes int colorPressed) {
161 | setColorPressed(getColor(colorPressed));
162 | }
163 |
164 | public void setColorPressed(int color) {
165 | if (mColorPressed != color) {
166 | mColorPressed = color;
167 | updateBackground();
168 | }
169 | }
170 |
171 | /**
172 | * @return the current color for disabled state.
173 | */
174 | public int getColorDisabled() {
175 | return mColorDisabled;
176 | }
177 |
178 | public void setColorDisabledResId(@ColorRes int colorDisabled) {
179 | setColorDisabled(getColor(colorDisabled));
180 | }
181 |
182 | public void setColorDisabled(int color) {
183 | if (mColorDisabled != color) {
184 | mColorDisabled = color;
185 | updateBackground();
186 | }
187 | }
188 |
189 | public void setStrokeVisible(boolean visible) {
190 | if (mStrokeVisible != visible) {
191 | mStrokeVisible = visible;
192 | updateBackground();
193 | }
194 | }
195 |
196 | public boolean isStrokeVisible() {
197 | return mStrokeVisible;
198 | }
199 |
200 | int getColor(@ColorRes int id) {
201 | return getResources().getColor(id);
202 | }
203 |
204 | float getDimension(@DimenRes int id) {
205 | return getResources().getDimension(id);
206 | }
207 |
208 | public void setTitle(String title) {
209 | mTitle = title;
210 | TextView label = getLabelView();
211 | if (label != null) {
212 | label.setText(title);
213 | }
214 | }
215 |
216 | TextView getLabelView() {
217 | return (TextView) getTag(R.id.fab_label);
218 | }
219 |
220 | public String getTitle() {
221 | return mTitle;
222 | }
223 |
224 | @Override
225 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
226 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
227 | setMeasuredDimension(mDrawableSize, mDrawableSize);
228 | }
229 |
230 | void updateBackground() {
231 | final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
232 | final float halfStrokeWidth = strokeWidth / 2f;
233 |
234 | LayerDrawable layerDrawable = new LayerDrawable(
235 | new Drawable[] {
236 | getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini),
237 | createFillDrawable(strokeWidth),
238 | createOuterStrokeDrawable(strokeWidth),
239 | getIconDrawable()
240 | });
241 |
242 | int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;
243 |
244 | int circleInsetHorizontal = (int) (mShadowRadius);
245 | int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
246 | int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);
247 |
248 | layerDrawable.setLayerInset(1,
249 | circleInsetHorizontal,
250 | circleInsetTop,
251 | circleInsetHorizontal,
252 | circleInsetBottom);
253 |
254 | layerDrawable.setLayerInset(2,
255 | (int) (circleInsetHorizontal - halfStrokeWidth),
256 | (int) (circleInsetTop - halfStrokeWidth),
257 | (int) (circleInsetHorizontal - halfStrokeWidth),
258 | (int) (circleInsetBottom - halfStrokeWidth));
259 |
260 | layerDrawable.setLayerInset(3,
261 | circleInsetHorizontal + iconOffset,
262 | circleInsetTop + iconOffset,
263 | circleInsetHorizontal + iconOffset,
264 | circleInsetBottom + iconOffset);
265 |
266 | setBackgroundCompat(layerDrawable);
267 | }
268 |
269 | Drawable getIconDrawable() {
270 | if (mIconDrawable != null) {
271 | return mIconDrawable;
272 | } else if (mIcon != 0) {
273 | return getResources().getDrawable(mIcon);
274 | } else {
275 | return new ColorDrawable(Color.TRANSPARENT);
276 | }
277 | }
278 |
279 | private StateListDrawable createFillDrawable(float strokeWidth) {
280 | StateListDrawable drawable = new StateListDrawable();
281 | drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled, strokeWidth));
282 | drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed, strokeWidth));
283 | drawable.addState(new int[] { }, createCircleDrawable(mColorNormal, strokeWidth));
284 | return drawable;
285 | }
286 |
287 | private Drawable createCircleDrawable(int color, float strokeWidth) {
288 | int alpha = Color.alpha(color);
289 | int opaqueColor = opaque(color);
290 |
291 | ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
292 |
293 | final Paint paint = fillDrawable.getPaint();
294 | paint.setAntiAlias(true);
295 | paint.setColor(opaqueColor);
296 |
297 | Drawable[] layers = {
298 | fillDrawable,
299 | createInnerStrokesDrawable(opaqueColor, strokeWidth)
300 | };
301 |
302 | LayerDrawable drawable = alpha == 255 || !mStrokeVisible
303 | ? new LayerDrawable(layers)
304 | : new TranslucentLayerDrawable(alpha, layers);
305 |
306 | int halfStrokeWidth = (int) (strokeWidth / 2f);
307 | drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
308 |
309 | return drawable;
310 | }
311 |
312 | private static class TranslucentLayerDrawable extends LayerDrawable {
313 | private final int mAlpha;
314 |
315 | public TranslucentLayerDrawable(int alpha, Drawable... layers) {
316 | super(layers);
317 | mAlpha = alpha;
318 | }
319 |
320 | @Override
321 | public void draw(Canvas canvas) {
322 | Rect bounds = getBounds();
323 | canvas.saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, mAlpha, Canvas.ALL_SAVE_FLAG);
324 | super.draw(canvas);
325 | canvas.restore();
326 | }
327 | }
328 |
329 | private Drawable createOuterStrokeDrawable(float strokeWidth) {
330 | ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
331 |
332 | final Paint paint = shapeDrawable.getPaint();
333 | paint.setAntiAlias(true);
334 | paint.setStrokeWidth(strokeWidth);
335 | paint.setStyle(Style.STROKE);
336 | paint.setColor(Color.BLACK);
337 | paint.setAlpha(opacityToAlpha(0.02f));
338 |
339 | return shapeDrawable;
340 | }
341 |
342 | private int opacityToAlpha(float opacity) {
343 | return (int) (255f * opacity);
344 | }
345 |
346 | private int darkenColor(int argb) {
347 | return adjustColorBrightness(argb, 0.9f);
348 | }
349 |
350 | private int lightenColor(int argb) {
351 | return adjustColorBrightness(argb, 1.1f);
352 | }
353 |
354 | private int adjustColorBrightness(int argb, float factor) {
355 | float[] hsv = new float[3];
356 | Color.colorToHSV(argb, hsv);
357 |
358 | hsv[2] = Math.min(hsv[2] * factor, 1f);
359 |
360 | return Color.HSVToColor(Color.alpha(argb), hsv);
361 | }
362 |
363 | private int halfTransparent(int argb) {
364 | return Color.argb(
365 | Color.alpha(argb) / 2,
366 | Color.red(argb),
367 | Color.green(argb),
368 | Color.blue(argb)
369 | );
370 | }
371 |
372 | private int opaque(int argb) {
373 | return Color.rgb(
374 | Color.red(argb),
375 | Color.green(argb),
376 | Color.blue(argb)
377 | );
378 | }
379 |
380 | private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
381 | if (!mStrokeVisible) {
382 | return new ColorDrawable(Color.TRANSPARENT);
383 | }
384 |
385 | ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
386 |
387 | final int bottomStrokeColor = darkenColor(color);
388 | final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
389 | final int topStrokeColor = lightenColor(color);
390 | final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
391 |
392 | final Paint paint = shapeDrawable.getPaint();
393 | paint.setAntiAlias(true);
394 | paint.setStrokeWidth(strokeWidth);
395 | paint.setStyle(Style.STROKE);
396 | shapeDrawable.setShaderFactory(new ShaderFactory() {
397 | @Override
398 | public Shader resize(int width, int height) {
399 | return new LinearGradient(width / 2, 0, width / 2, height,
400 | new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor },
401 | new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f },
402 | TileMode.CLAMP
403 | );
404 | }
405 | });
406 |
407 | return shapeDrawable;
408 | }
409 |
410 | @SuppressWarnings("deprecation")
411 | @SuppressLint("NewApi")
412 | private void setBackgroundCompat(Drawable drawable) {
413 | if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
414 | setBackground(drawable);
415 | } else {
416 | setBackgroundDrawable(drawable);
417 | }
418 | }
419 |
420 | @Override
421 | public void setVisibility(int visibility) {
422 | TextView label = getLabelView();
423 | if (label != null) {
424 | label.setVisibility(visibility);
425 | }
426 |
427 | super.setVisibility(visibility);
428 | }
429 | }
430 |
--------------------------------------------------------------------------------
/library/src/main/java/cc/trity/floatingactionbutton/FloatingActionsMenu.java:
--------------------------------------------------------------------------------
1 | package cc.trity.floatingactionbutton;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Canvas;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.Drawable;
10 | import android.graphics.drawable.LayerDrawable;
11 | import android.os.Parcel;
12 | import android.os.Parcelable;
13 | import android.support.annotation.ColorRes;
14 | import android.support.annotation.NonNull;
15 | import android.util.AttributeSet;
16 | import android.view.ContextThemeWrapper;
17 | import android.view.TouchDelegate;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.view.animation.DecelerateInterpolator;
21 | import android.view.animation.Interpolator;
22 | import android.view.animation.OvershootInterpolator;
23 | import android.widget.TextView;
24 |
25 | public class FloatingActionsMenu extends ViewGroup {
26 | public static final int EXPAND_UP = 0;
27 | public static final int EXPAND_DOWN = 1;
28 | public static final int EXPAND_LEFT = 2;
29 | public static final int EXPAND_RIGHT = 3;
30 |
31 | public static final int LABELS_ON_LEFT_SIDE = 0;
32 | public static final int LABELS_ON_RIGHT_SIDE = 1;
33 |
34 | private static final int ANIMATION_DURATION = 300;
35 | private static final float COLLAPSED_PLUS_ROTATION = 0f;
36 | private static final float EXPANDED_PLUS_ROTATION = 90f + 45f;//rorate
37 |
38 | private int mAddButtonPlusColor;
39 | private int mAddButtonColorNormal;
40 | private int mAddButtonColorPressed;
41 | private int mAddButtonSize;
42 | private boolean mAddButtonStrokeVisible;
43 | private int mExpandDirection;
44 |
45 | private int mButtonSpacing;
46 | private int mLabelsMargin;
47 | private int mLabelsVerticalOffset;
48 |
49 | private boolean mExpanded;
50 |
51 | private AnimatorSet mExpandAnimation = new AnimatorSet().setDuration(ANIMATION_DURATION);
52 | private AnimatorSet mCollapseAnimation = new AnimatorSet().setDuration(ANIMATION_DURATION);
53 | private AddFloatingActionButton mAddButton;
54 | private RotatingDrawable mRotatingDrawable;
55 | private int mMaxButtonWidth;
56 | private int mMaxButtonHeight;
57 | private int mLabelsStyle;
58 | private int mLabelsPosition;
59 | private int mButtonsCount;
60 | private int mResIcon=-1;
61 | private float rotate=EXPANDED_PLUS_ROTATION;
62 |
63 | private TouchDelegateGroup mTouchDelegateGroup;
64 |
65 | private OnFloatingActionsMenuUpdateListener mListener;
66 |
67 | public interface OnFloatingActionsMenuUpdateListener {
68 | void onMenuExpanded();
69 | void onMenuCollapsed();
70 | }
71 |
72 | public FloatingActionsMenu(Context context) {
73 | this(context, null);
74 | }
75 |
76 | public FloatingActionsMenu(Context context, AttributeSet attrs) {
77 | super(context, attrs);
78 | init(context, attrs);
79 | }
80 |
81 | public FloatingActionsMenu(Context context, AttributeSet attrs, int defStyle) {
82 | super(context, attrs, defStyle);
83 | init(context, attrs);
84 | }
85 |
86 | private void init(Context context, AttributeSet attributeSet) {
87 | mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));
88 | mLabelsMargin = getResources().getDimensionPixelSize(R.dimen.fab_labels_margin);
89 | mLabelsVerticalOffset = getResources().getDimensionPixelSize(R.dimen.fab_shadow_offset);
90 |
91 | mTouchDelegateGroup = new TouchDelegateGroup(this);
92 | setTouchDelegate(mTouchDelegateGroup);
93 |
94 | TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
95 | mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonPlusIconColor, getColor(android.R.color.white));
96 | mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
97 | mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
98 | mAddButtonSize = attr.getInt(R.styleable.FloatingActionsMenu_fab_addButtonSize, FloatingActionButton.SIZE_NORMAL);
99 | mAddButtonStrokeVisible = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_addButtonStrokeVisible, true);
100 | mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP);
101 | mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionsMenu_fab_labelStyle, 0);
102 | mLabelsPosition = attr.getInt(R.styleable.FloatingActionsMenu_fab_labelsPosition, LABELS_ON_LEFT_SIDE);
103 | mResIcon=attr.getResourceId(R.styleable.FloatingActionsMenu_fab_bitmap, -1);//get bitmap resource
104 | rotate=attr.getFloat(R.styleable.FloatingActionsMenu_fab_rotation,EXPANDED_PLUS_ROTATION);
105 | attr.recycle();
106 |
107 | if (mLabelsStyle != 0 && expandsHorizontally()) {
108 | throw new IllegalStateException("Action labels in horizontal expand orientation is not supported.");
109 | }
110 |
111 | createAddButton(context);
112 | }
113 |
114 | public void setOnFloatingActionsMenuUpdateListener(OnFloatingActionsMenuUpdateListener listener) {
115 | mListener = listener;
116 | }
117 |
118 | private boolean expandsHorizontally() {
119 | return mExpandDirection == EXPAND_LEFT || mExpandDirection == EXPAND_RIGHT;
120 | }
121 |
122 | private static class RotatingDrawable extends LayerDrawable {
123 | public RotatingDrawable(Drawable drawable) {
124 | super(new Drawable[] { drawable });
125 | }
126 |
127 | private float mRotation;
128 |
129 | @SuppressWarnings("UnusedDeclaration")
130 | public float getRotation() {
131 | return mRotation;
132 | }
133 |
134 | @SuppressWarnings("UnusedDeclaration")
135 | public void setRotation(float rotation) {
136 | mRotation = rotation;
137 | invalidateSelf();
138 | }
139 |
140 | @Override
141 | public void draw(Canvas canvas) {
142 | canvas.save();
143 | canvas.rotate(mRotation, getBounds().centerX(), getBounds().centerY());
144 | super.draw(canvas);
145 | canvas.restore();
146 | }
147 | }
148 |
149 | private void createAddButton(Context context) {
150 | mAddButton = new AddFloatingActionButton(context) {
151 | @Override
152 | void updateBackground() {
153 | mPlusColor = mAddButtonPlusColor;
154 | mColorNormal = mAddButtonColorNormal;
155 | mColorPressed = mAddButtonColorPressed;
156 | mStrokeVisible = mAddButtonStrokeVisible;
157 | super.updateBackground();
158 | }
159 |
160 | @Override
161 | Drawable getIconDrawable() {
162 | RotatingDrawable rotatingDrawable;
163 | if(mResIcon!=-1){
164 | rotatingDrawable = new RotatingDrawable(getBitmapDrawable(mResIcon));
165 | }
166 | else{
167 | rotatingDrawable = new RotatingDrawable(super.getIconDrawable());
168 | }
169 |
170 | mRotatingDrawable = rotatingDrawable;
171 |
172 | final OvershootInterpolator interpolator = new OvershootInterpolator();
173 |
174 | final ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", getRotate(), COLLAPSED_PLUS_ROTATION);
175 | final ObjectAnimator expandAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", COLLAPSED_PLUS_ROTATION, getRotate());
176 |
177 | collapseAnimator.setInterpolator(interpolator);
178 | expandAnimator.setInterpolator(interpolator);
179 |
180 | mExpandAnimation.play(expandAnimator);
181 | mCollapseAnimation.play(collapseAnimator);
182 |
183 | return rotatingDrawable;
184 | }
185 | };
186 |
187 | mAddButton.setId(R.id.fab_expand_menu_button);
188 | mAddButton.setSize(mAddButtonSize);
189 | mAddButton.setOnClickListener(new OnClickListener() {
190 | @Override
191 | public void onClick(View v) {
192 | toggle();
193 | }
194 | });
195 |
196 | addView(mAddButton, super.generateDefaultLayoutParams());
197 | }
198 |
199 | public void addButton(FloatingActionButton button) {
200 | addView(button, mButtonsCount - 1);
201 | mButtonsCount++;
202 |
203 | if (mLabelsStyle != 0) {
204 | createLabels();
205 | }
206 | }
207 |
208 | public void removeButton(FloatingActionButton button) {
209 | removeView(button.getLabelView());
210 | removeView(button);
211 | mButtonsCount--;
212 | }
213 |
214 | private int getColor(@ColorRes int id) {
215 | return getResources().getColor(id);
216 | }
217 |
218 | @Override
219 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
220 | measureChildren(widthMeasureSpec, heightMeasureSpec);
221 |
222 | int width = 0;
223 | int height = 0;
224 |
225 | mMaxButtonWidth = 0;
226 | mMaxButtonHeight = 0;
227 | int maxLabelWidth = 0;
228 |
229 | for (int i = 0; i < mButtonsCount; i++) {
230 | View child = getChildAt(i);
231 |
232 | if (child.getVisibility() == GONE) {
233 | continue;
234 | }
235 |
236 | switch (mExpandDirection) {
237 | case EXPAND_UP:
238 | case EXPAND_DOWN:
239 | mMaxButtonWidth = Math.max(mMaxButtonWidth, child.getMeasuredWidth());
240 | height += child.getMeasuredHeight();
241 | break;
242 | case EXPAND_LEFT:
243 | case EXPAND_RIGHT:
244 | width += child.getMeasuredWidth();
245 | mMaxButtonHeight = Math.max(mMaxButtonHeight, child.getMeasuredHeight());
246 | break;
247 | }
248 |
249 | if (!expandsHorizontally()) {
250 | TextView label = (TextView) child.getTag(R.id.fab_label);
251 | if (label != null) {
252 | maxLabelWidth = Math.max(maxLabelWidth, label.getMeasuredWidth());
253 | }
254 | }
255 | }
256 |
257 | if (!expandsHorizontally()) {
258 | width = mMaxButtonWidth + (maxLabelWidth > 0 ? maxLabelWidth + mLabelsMargin : 0);
259 | } else {
260 | height = mMaxButtonHeight;
261 | }
262 |
263 | switch (mExpandDirection) {
264 | case EXPAND_UP:
265 | case EXPAND_DOWN:
266 | height += mButtonSpacing * (getChildCount() - 1);
267 | height = adjustForOvershoot(height);
268 | break;
269 | case EXPAND_LEFT:
270 | case EXPAND_RIGHT:
271 | width += mButtonSpacing * (getChildCount() - 1);
272 | width = adjustForOvershoot(width);
273 | break;
274 | }
275 |
276 | setMeasuredDimension(width, height);
277 | }
278 |
279 | private int adjustForOvershoot(int dimension) {
280 | return dimension * 12 / 10;
281 | }
282 |
283 | @Override
284 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
285 | switch (mExpandDirection) {
286 | case EXPAND_UP:
287 | case EXPAND_DOWN:
288 | boolean expandUp = mExpandDirection == EXPAND_UP;
289 |
290 | if (changed) {
291 | mTouchDelegateGroup.clearTouchDelegates();
292 | }
293 |
294 | int addButtonY = expandUp ? b - t - mAddButton.getMeasuredHeight() : 0;
295 | // Ensure mAddButton is centered on the line where the buttons should be
296 | int buttonsHorizontalCenter = mLabelsPosition == LABELS_ON_LEFT_SIDE
297 | ? r - l - mMaxButtonWidth / 2
298 | : mMaxButtonWidth / 2;
299 | int addButtonLeft = buttonsHorizontalCenter - mAddButton.getMeasuredWidth() / 2;
300 | mAddButton.layout(addButtonLeft, addButtonY, addButtonLeft + mAddButton.getMeasuredWidth(), addButtonY + mAddButton.getMeasuredHeight());
301 |
302 | int labelsOffset = mMaxButtonWidth / 2 + mLabelsMargin;
303 | int labelsXNearButton = mLabelsPosition == LABELS_ON_LEFT_SIDE
304 | ? buttonsHorizontalCenter - labelsOffset
305 | : buttonsHorizontalCenter + labelsOffset;
306 |
307 | int nextY = expandUp ?
308 | addButtonY - mButtonSpacing :
309 | addButtonY + mAddButton.getMeasuredHeight() + mButtonSpacing;
310 |
311 | for (int i = mButtonsCount - 1; i >= 0; i--) {
312 | final View child = getChildAt(i);
313 |
314 | if (child == mAddButton || child.getVisibility() == GONE) continue;
315 |
316 | int childX = buttonsHorizontalCenter - child.getMeasuredWidth() / 2;
317 | int childY = expandUp ? nextY - child.getMeasuredHeight() : nextY;
318 | child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
319 |
320 | float collapsedTranslation = addButtonY - childY;
321 | float expandedTranslation = 0f;
322 |
323 | child.setTranslationY(mExpanded ? expandedTranslation : collapsedTranslation);
324 | child.setAlpha(mExpanded ? 1f : 0f);
325 |
326 | LayoutParams params = (LayoutParams) child.getLayoutParams();
327 | params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
328 | params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
329 | params.setAnimationsTarget(child);
330 |
331 | View label = (View) child.getTag(R.id.fab_label);
332 | if (label != null) {
333 | int labelXAwayFromButton = mLabelsPosition == LABELS_ON_LEFT_SIDE
334 | ? labelsXNearButton - label.getMeasuredWidth()
335 | : labelsXNearButton + label.getMeasuredWidth();
336 |
337 | int labelLeft = mLabelsPosition == LABELS_ON_LEFT_SIDE
338 | ? labelXAwayFromButton
339 | : labelsXNearButton;
340 |
341 | int labelRight = mLabelsPosition == LABELS_ON_LEFT_SIDE
342 | ? labelsXNearButton
343 | : labelXAwayFromButton;
344 |
345 | int labelTop = childY - mLabelsVerticalOffset + (child.getMeasuredHeight() - label.getMeasuredHeight()) / 2;
346 |
347 | label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());
348 |
349 | Rect touchArea = new Rect(
350 | Math.min(childX, labelLeft),
351 | childY - mButtonSpacing / 2,
352 | Math.max(childX + child.getMeasuredWidth(), labelRight),
353 | childY + child.getMeasuredHeight() + mButtonSpacing / 2);
354 | mTouchDelegateGroup.addTouchDelegate(new TouchDelegate(touchArea, child));
355 |
356 | label.setTranslationY(mExpanded ? expandedTranslation : collapsedTranslation);
357 | label.setAlpha(mExpanded ? 1f : 0f);
358 |
359 | LayoutParams labelParams = (LayoutParams) label.getLayoutParams();
360 | labelParams.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
361 | labelParams.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
362 | labelParams.setAnimationsTarget(label);
363 | }
364 |
365 | nextY = expandUp ?
366 | childY - mButtonSpacing :
367 | childY + child.getMeasuredHeight() + mButtonSpacing;
368 | }
369 | break;
370 |
371 | case EXPAND_LEFT:
372 | case EXPAND_RIGHT:
373 | boolean expandLeft = mExpandDirection == EXPAND_LEFT;
374 |
375 | int addButtonX = expandLeft ? r - l - mAddButton.getMeasuredWidth() : 0;
376 | // Ensure mAddButton is centered on the line where the buttons should be
377 | int addButtonTop = b - t - mMaxButtonHeight + (mMaxButtonHeight - mAddButton.getMeasuredHeight()) / 2;
378 | mAddButton.layout(addButtonX, addButtonTop, addButtonX + mAddButton.getMeasuredWidth(), addButtonTop + mAddButton.getMeasuredHeight());
379 |
380 | int nextX = expandLeft ?
381 | addButtonX - mButtonSpacing :
382 | addButtonX + mAddButton.getMeasuredWidth() + mButtonSpacing;
383 |
384 | for (int i = mButtonsCount - 1; i >= 0; i--) {
385 | final View child = getChildAt(i);
386 |
387 | if (child == mAddButton || child.getVisibility() == GONE) continue;
388 |
389 | int childX = expandLeft ? nextX - child.getMeasuredWidth() : nextX;
390 | int childY = addButtonTop + (mAddButton.getMeasuredHeight() - child.getMeasuredHeight()) / 2;
391 | child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
392 |
393 | float collapsedTranslation = addButtonX - childX;
394 | float expandedTranslation = 0f;
395 |
396 | child.setTranslationX(mExpanded ? expandedTranslation : collapsedTranslation);
397 | child.setAlpha(mExpanded ? 1f : 0f);
398 |
399 | LayoutParams params = (LayoutParams) child.getLayoutParams();
400 | params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
401 | params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
402 | params.setAnimationsTarget(child);
403 |
404 | nextX = expandLeft ?
405 | childX - mButtonSpacing :
406 | childX + child.getMeasuredWidth() + mButtonSpacing;
407 | }
408 |
409 | break;
410 | }
411 | }
412 |
413 | @Override
414 | protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
415 | return new LayoutParams(super.generateDefaultLayoutParams());
416 | }
417 |
418 | @Override
419 | public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
420 | return new LayoutParams(super.generateLayoutParams(attrs));
421 | }
422 |
423 | @Override
424 | protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
425 | return new LayoutParams(super.generateLayoutParams(p));
426 | }
427 |
428 | @Override
429 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
430 | return super.checkLayoutParams(p);
431 | }
432 |
433 | private static Interpolator sExpandInterpolator = new OvershootInterpolator();
434 | private static Interpolator sCollapseInterpolator = new DecelerateInterpolator(3f);
435 | private static Interpolator sAlphaExpandInterpolator = new DecelerateInterpolator();
436 |
437 | private class LayoutParams extends ViewGroup.LayoutParams {
438 |
439 | private ObjectAnimator mExpandDir = new ObjectAnimator();
440 | private ObjectAnimator mExpandAlpha = new ObjectAnimator();
441 | private ObjectAnimator mCollapseDir = new ObjectAnimator();
442 | private ObjectAnimator mCollapseAlpha = new ObjectAnimator();
443 | private boolean animationsSetToPlay;
444 |
445 | public LayoutParams(ViewGroup.LayoutParams source) {
446 | super(source);
447 |
448 | mExpandDir.setInterpolator(sExpandInterpolator);
449 | mExpandAlpha.setInterpolator(sAlphaExpandInterpolator);
450 | mCollapseDir.setInterpolator(sCollapseInterpolator);
451 | mCollapseAlpha.setInterpolator(sCollapseInterpolator);
452 |
453 | mCollapseAlpha.setProperty(View.ALPHA);
454 | mCollapseAlpha.setFloatValues(1f, 0f);
455 |
456 | mExpandAlpha.setProperty(View.ALPHA);
457 | mExpandAlpha.setFloatValues(0f, 1f);
458 |
459 | switch (mExpandDirection) {
460 | case EXPAND_UP:
461 | case EXPAND_DOWN:
462 | mCollapseDir.setProperty(View.TRANSLATION_Y);
463 | mExpandDir.setProperty(View.TRANSLATION_Y);
464 | break;
465 | case EXPAND_LEFT:
466 | case EXPAND_RIGHT:
467 | mCollapseDir.setProperty(View.TRANSLATION_X);
468 | mExpandDir.setProperty(View.TRANSLATION_X);
469 | break;
470 | }
471 | }
472 |
473 | public void setAnimationsTarget(View view) {
474 | mCollapseAlpha.setTarget(view);
475 | mCollapseDir.setTarget(view);
476 | mExpandAlpha.setTarget(view);
477 | mExpandDir.setTarget(view);
478 |
479 | // Now that the animations have targets, set them to be played
480 | if (!animationsSetToPlay) {
481 | mCollapseAnimation.play(mCollapseAlpha);
482 | mCollapseAnimation.play(mCollapseDir);
483 | mExpandAnimation.play(mExpandAlpha);
484 | mExpandAnimation.play(mExpandDir);
485 | animationsSetToPlay = true;
486 | }
487 | }
488 | }
489 |
490 | @Override
491 | protected void onFinishInflate() {
492 | super.onFinishInflate();
493 |
494 | bringChildToFront(mAddButton);
495 | mButtonsCount = getChildCount();
496 |
497 | if (mLabelsStyle != 0) {
498 | createLabels();
499 | }
500 | }
501 |
502 | private void createLabels() {
503 | Context context = new ContextThemeWrapper(getContext(), mLabelsStyle);
504 |
505 | for (int i = 0; i < mButtonsCount; i++) {
506 | FloatingActionButton button = (FloatingActionButton) getChildAt(i);
507 | String title = button.getTitle();
508 |
509 | if (button == mAddButton || title == null ||
510 | button.getTag(R.id.fab_label) != null) continue;
511 |
512 | TextView label = new TextView(context);
513 | label.setTextAppearance(getContext(), mLabelsStyle);
514 | label.setText(button.getTitle());
515 | addView(label);
516 |
517 | button.setTag(R.id.fab_label, label);
518 | }
519 | }
520 |
521 | public void collapse() {
522 | if (mExpanded) {
523 | mExpanded = false;
524 | mTouchDelegateGroup.setEnabled(false);
525 | mCollapseAnimation.start();
526 | mExpandAnimation.cancel();
527 |
528 | if (mListener != null) {
529 | mListener.onMenuCollapsed();
530 | }
531 | }
532 | }
533 |
534 | public void toggle() {
535 | if (mExpanded) {
536 | collapse();
537 | } else {
538 | expand();
539 | }
540 | }
541 |
542 | public void expand() {
543 | if (!mExpanded) {
544 | mExpanded = true;
545 | mTouchDelegateGroup.setEnabled(true);
546 | mCollapseAnimation.cancel();
547 | mExpandAnimation.start();
548 |
549 | if (mListener != null) {
550 | mListener.onMenuExpanded();
551 | }
552 | }
553 | }
554 |
555 | public boolean isExpanded() {
556 | return mExpanded;
557 | }
558 |
559 | @Override
560 | public Parcelable onSaveInstanceState() {
561 | Parcelable superState = super.onSaveInstanceState();
562 | SavedState savedState = new SavedState(superState);
563 | savedState.mExpanded = mExpanded;
564 |
565 | return savedState;
566 | }
567 |
568 | @Override
569 | public void onRestoreInstanceState(Parcelable state) {
570 | if (state instanceof SavedState) {
571 | SavedState savedState = (SavedState) state;
572 | mExpanded = savedState.mExpanded;
573 | mTouchDelegateGroup.setEnabled(mExpanded);
574 |
575 | if (mRotatingDrawable != null) {
576 | mRotatingDrawable.setRotation(mExpanded ? getRotation() : COLLAPSED_PLUS_ROTATION);
577 | }
578 |
579 | super.onRestoreInstanceState(savedState.getSuperState());
580 | } else {
581 | super.onRestoreInstanceState(state);
582 | }
583 | }
584 |
585 | public static class SavedState extends BaseSavedState {
586 | public boolean mExpanded;
587 |
588 | public SavedState(Parcelable parcel) {
589 | super(parcel);
590 | }
591 |
592 | private SavedState(Parcel in) {
593 | super(in);
594 | mExpanded = in.readInt() == 1;
595 | }
596 |
597 | @Override
598 | public void writeToParcel(@NonNull Parcel out, int flags) {
599 | super.writeToParcel(out, flags);
600 | out.writeInt(mExpanded ? 1 : 0);
601 | }
602 |
603 | public static final Creator CREATOR = new Creator() {
604 |
605 | @Override
606 | public SavedState createFromParcel(Parcel in) {
607 | return new SavedState(in);
608 | }
609 |
610 | @Override
611 | public SavedState[] newArray(int size) {
612 | return new SavedState[size];
613 | }
614 | };
615 | }
616 | public float getRotate() {
617 | return rotate;
618 | }
619 |
620 | public void setRotate(float rotate) {
621 | this.rotate = rotate;
622 | }
623 | }
624 |
--------------------------------------------------------------------------------
/library/src/main/java/cc/trity/floatingactionbutton/TouchDelegateGroup.java:
--------------------------------------------------------------------------------
1 | package cc.trity.floatingactionbutton;
2 |
3 | import android.graphics.Rect;
4 | import android.support.annotation.NonNull;
5 | import android.view.MotionEvent;
6 | import android.view.TouchDelegate;
7 | import android.view.View;
8 |
9 | import java.util.ArrayList;
10 |
11 | public class TouchDelegateGroup extends TouchDelegate {
12 | private static final Rect USELESS_HACKY_RECT = new Rect();
13 | private final ArrayList mTouchDelegates = new ArrayList();
14 | private TouchDelegate mCurrentTouchDelegate;
15 | private boolean mEnabled;
16 |
17 | public TouchDelegateGroup(View uselessHackyView) {
18 | super(USELESS_HACKY_RECT, uselessHackyView);
19 | }
20 |
21 | public void addTouchDelegate(@NonNull TouchDelegate touchDelegate) {
22 | mTouchDelegates.add(touchDelegate);
23 | }
24 |
25 | public void removeTouchDelegate(TouchDelegate touchDelegate) {
26 | mTouchDelegates.remove(touchDelegate);
27 | if (mCurrentTouchDelegate == touchDelegate) {
28 | mCurrentTouchDelegate = null;
29 | }
30 | }
31 |
32 | public void clearTouchDelegates() {
33 | mTouchDelegates.clear();
34 | mCurrentTouchDelegate = null;
35 | }
36 |
37 | @Override
38 | public boolean onTouchEvent(@NonNull MotionEvent event) {
39 | if (!mEnabled) return false;
40 |
41 | TouchDelegate delegate = null;
42 |
43 | switch (event.getAction()) {
44 | case MotionEvent.ACTION_DOWN:
45 | for (int i = 0; i < mTouchDelegates.size(); i++) {
46 | TouchDelegate touchDelegate = mTouchDelegates.get(i);
47 | if (touchDelegate.onTouchEvent(event)) {
48 | mCurrentTouchDelegate = touchDelegate;
49 | return true;
50 | }
51 | }
52 | break;
53 |
54 | case MotionEvent.ACTION_MOVE:
55 | delegate = mCurrentTouchDelegate;
56 | break;
57 |
58 | case MotionEvent.ACTION_CANCEL:
59 | case MotionEvent.ACTION_UP:
60 | delegate = mCurrentTouchDelegate;
61 | mCurrentTouchDelegate = null;
62 | break;
63 | }
64 |
65 | return delegate != null && delegate.onTouchEvent(event);
66 | }
67 |
68 | public void setEnabled(boolean enabled) {
69 | mEnabled = enabled;
70 | }
71 | }
--------------------------------------------------------------------------------
/library/src/main/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-9
15 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/fab_bg_mini.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-hdpi/fab_bg_mini.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/fab_bg_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-hdpi/fab_bg_normal.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/fab_bg_mini.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-mdpi/fab_bg_mini.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/fab_bg_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-mdpi/fab_bg_normal.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/club_icon_ubac.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xhdpi/club_icon_ubac.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fab_bg_mini.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xhdpi/fab_bg_mini.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fab_bg_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xhdpi/fab_bg_normal.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/fab_bg_mini.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xxhdpi/fab_bg_mini.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/fab_bg_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xxhdpi/fab_bg_normal.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/fab_bg_mini.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xxxhdpi/fab_bg_mini.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/fab_bg_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/library/src/main/res/drawable-xxxhdpi/fab_bg_normal.png
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 56dp
3 | 40dp
4 |
5 | 24dp
6 | 24dp
7 | 48dp
8 |
9 | 14dp
10 | 2dp
11 |
12 | 3dp
13 | 9dp
14 |
15 | 1dp
16 |
17 | 16dp
18 | 8dp
19 |
20 |
--------------------------------------------------------------------------------
/library/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/src/com/getbase/floatingactionbutton/AddFloatingActionButton.java:
--------------------------------------------------------------------------------
1 | package com.getbase.floatingactionbutton;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.Style;
8 | import android.graphics.drawable.Drawable;
9 | import android.graphics.drawable.ShapeDrawable;
10 | import android.graphics.drawable.shapes.Shape;
11 | import android.util.AttributeSet;
12 |
13 | public class AddFloatingActionButton extends FloatingActionButton {
14 | int mPlusColor;
15 |
16 | public AddFloatingActionButton(Context context) {
17 | this(context, null);
18 | }
19 |
20 | public AddFloatingActionButton(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | }
23 |
24 | public AddFloatingActionButton(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | }
27 |
28 | @Override
29 | void init(Context context, AttributeSet attributeSet) {
30 | TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.AddFloatingActionButton, 0, 0);
31 | mPlusColor = attr.getColor(R.styleable.AddFloatingActionButton_fab_plusIconColor, getColor(android.R.color.white));
32 | attr.recycle();
33 |
34 | super.init(context, attributeSet);
35 | }
36 |
37 | /**
38 | * @return the current Color of plus icon.
39 | */
40 | public int getPlusColor() {
41 | return mPlusColor;
42 | }
43 |
44 | public void setPlusColorResId( int plusColor) {
45 | setPlusColor(getColor(plusColor));
46 | }
47 |
48 | public void setPlusColor(int color) {
49 | if (mPlusColor != color) {
50 | mPlusColor = color;
51 | updateBackground();
52 | }
53 | }
54 |
55 | @Override
56 | public void setIcon( int icon) {
57 | throw new UnsupportedOperationException("Use FloatingActionButton if you want to use custom icon");
58 | }
59 |
60 | @Override
61 | Drawable getIconDrawable() {
62 | final float iconSize = getDimension(R.dimen.fab_icon_size);
63 | final float iconHalfSize = iconSize / 2f;
64 |
65 | final float plusSize = getDimension(R.dimen.fab_plus_icon_size);
66 | final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f;
67 | final float plusOffset = (iconSize - plusSize) / 2f;
68 |
69 | final Shape shape = new Shape() {
70 | @Override
71 | public void draw(Canvas canvas, Paint paint) {
72 | canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint);
73 | canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint);
74 | }
75 | };
76 |
77 | ShapeDrawable drawable = new ShapeDrawable(shape);
78 |
79 | final Paint paint = drawable.getPaint();
80 | paint.setColor(mPlusColor);
81 | paint.setStyle(Style.FILL);
82 | paint.setAntiAlias(true);
83 |
84 | return drawable;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/library/src/main/src/com/getbase/floatingactionbutton/FloatingActionButton.java:
--------------------------------------------------------------------------------
1 | package com.getbase.floatingactionbutton;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | import android.annotation.SuppressLint;
7 | import android.content.Context;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Canvas;
10 | import android.graphics.Color;
11 | import android.graphics.LinearGradient;
12 | import android.graphics.Paint;
13 | import android.graphics.Paint.Style;
14 | import android.graphics.Rect;
15 | import android.graphics.Shader;
16 | import android.graphics.Shader.TileMode;
17 | import android.graphics.drawable.ColorDrawable;
18 | import android.graphics.drawable.Drawable;
19 | import android.graphics.drawable.LayerDrawable;
20 | import android.graphics.drawable.ShapeDrawable;
21 | import android.graphics.drawable.ShapeDrawable.ShaderFactory;
22 | import android.graphics.drawable.StateListDrawable;
23 | import android.graphics.drawable.shapes.OvalShape;
24 | import android.os.Build;
25 | import android.os.Build.VERSION_CODES;
26 | import android.support.annotation.ColorRes;
27 | import android.support.annotation.DimenRes;
28 | import android.support.annotation.DrawableRes;
29 | import android.support.annotation.IntDef;
30 | import android.support.annotation.NonNull;
31 | import android.util.AttributeSet;
32 | import android.widget.ImageButton;
33 | import android.widget.TextView;
34 |
35 | public class FloatingActionButton extends ImageButton {
36 |
37 | public static final int SIZE_NORMAL = 0;
38 | public static final int SIZE_MINI = 1;
39 |
40 | @Retention(RetentionPolicy.SOURCE)
41 | @IntDef({ SIZE_NORMAL, SIZE_MINI })
42 | public @interface FAB_SIZE {
43 | }
44 |
45 | int mColorNormal;
46 | int mColorPressed;
47 | int mColorDisabled;
48 | String mTitle;
49 | @DrawableRes
50 | private int mIcon;
51 | private Drawable mIconDrawable;
52 | private int mSize;
53 |
54 | private float mCircleSize;
55 | private float mShadowRadius;
56 | private float mShadowOffset;
57 | private int mDrawableSize;
58 | boolean mStrokeVisible;
59 |
60 | public FloatingActionButton(Context context) {
61 | this(context, null);
62 | }
63 |
64 | public FloatingActionButton(Context context, AttributeSet attrs) {
65 | super(context, attrs);
66 | init(context, attrs);
67 | }
68 |
69 | public FloatingActionButton(Context context, AttributeSet attrs, int defStyle) {
70 | super(context, attrs, defStyle);
71 | init(context, attrs);
72 | }
73 |
74 | void init(Context context, AttributeSet attributeSet) {
75 | TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionButton, 0, 0);
76 | mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, getColor(android.R.color.background_dark));
77 | mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, getColor(android.R.color.background_dark));
78 | mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, getColor(android.R.color.darker_gray));
79 | mSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
80 | mIcon = attr.getResourceId(R.styleable.FloatingActionButton_fab_icon, 0);
81 | mTitle = attr.getString(R.styleable.FloatingActionButton_fab_title);
82 | mStrokeVisible = attr.getBoolean(R.styleable.FloatingActionButton_fab_stroke_visible, true);
83 | attr.recycle();
84 |
85 | updateCircleSize();
86 | mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
87 | mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
88 | updateDrawableSize();
89 |
90 | updateBackground();
91 | }
92 |
93 | private void updateDrawableSize() {
94 | mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);
95 | }
96 |
97 | private void updateCircleSize() {
98 | mCircleSize = getDimension(mSize == SIZE_NORMAL ? R.dimen.fab_size_normal : R.dimen.fab_size_mini);
99 | }
100 |
101 | public void setSize(@FAB_SIZE int size) {
102 | if (size != SIZE_MINI && size != SIZE_NORMAL) {
103 | throw new IllegalArgumentException("Use @FAB_SIZE constants only!");
104 | }
105 |
106 | if (mSize != size) {
107 | mSize = size;
108 | updateCircleSize();
109 | updateDrawableSize();
110 | updateBackground();
111 | }
112 | }
113 |
114 | @FAB_SIZE
115 | public int getSize() {
116 | return mSize;
117 | }
118 |
119 | public void setIcon(@DrawableRes int icon) {
120 | if (mIcon != icon) {
121 | mIcon = icon;
122 | mIconDrawable = null;
123 | updateBackground();
124 | }
125 | }
126 |
127 | public void setIconDrawable(@NonNull Drawable iconDrawable) {
128 | if (mIconDrawable != iconDrawable) {
129 | mIcon = 0;
130 | mIconDrawable = iconDrawable;
131 | updateBackground();
132 | }
133 | }
134 |
135 | /**
136 | * @return the current Color for normal state.
137 | */
138 | public int getColorNormal() {
139 | return mColorNormal;
140 | }
141 |
142 | public void setColorNormalResId(@ColorRes int colorNormal) {
143 | setColorNormal(getColor(colorNormal));
144 | }
145 |
146 | public void setColorNormal(int color) {
147 | if (mColorNormal != color) {
148 | mColorNormal = color;
149 | updateBackground();
150 | }
151 | }
152 |
153 | /**
154 | * @return the current color for pressed state.
155 | */
156 | public int getColorPressed() {
157 | return mColorPressed;
158 | }
159 |
160 | public void setColorPressedResId(@ColorRes int colorPressed) {
161 | setColorPressed(getColor(colorPressed));
162 | }
163 |
164 | public void setColorPressed(int color) {
165 | if (mColorPressed != color) {
166 | mColorPressed = color;
167 | updateBackground();
168 | }
169 | }
170 |
171 | /**
172 | * @return the current color for disabled state.
173 | */
174 | public int getColorDisabled() {
175 | return mColorDisabled;
176 | }
177 |
178 | public void setColorDisabledResId(@ColorRes int colorDisabled) {
179 | setColorDisabled(getColor(colorDisabled));
180 | }
181 |
182 | public void setColorDisabled(int color) {
183 | if (mColorDisabled != color) {
184 | mColorDisabled = color;
185 | updateBackground();
186 | }
187 | }
188 |
189 | public void setStrokeVisible(boolean visible) {
190 | if (mStrokeVisible != visible) {
191 | mStrokeVisible = visible;
192 | updateBackground();
193 | }
194 | }
195 |
196 | public boolean isStrokeVisible() {
197 | return mStrokeVisible;
198 | }
199 |
200 | int getColor(@ColorRes int id) {
201 | return getResources().getColor(id);
202 | }
203 |
204 | float getDimension(@DimenRes int id) {
205 | return getResources().getDimension(id);
206 | }
207 |
208 | public void setTitle(String title) {
209 | mTitle = title;
210 | TextView label = getLabelView();
211 | if (label != null) {
212 | label.setText(title);
213 | }
214 | }
215 |
216 | TextView getLabelView() {
217 | return (TextView) getTag(R.id.fab_label);
218 | }
219 |
220 | public String getTitle() {
221 | return mTitle;
222 | }
223 |
224 | @Override
225 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
226 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
227 | setMeasuredDimension(mDrawableSize, mDrawableSize);
228 | }
229 |
230 | void updateBackground() {
231 | final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
232 | final float halfStrokeWidth = strokeWidth / 2f;
233 |
234 | LayerDrawable layerDrawable = new LayerDrawable(
235 | new Drawable[] {
236 | getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini),
237 | createFillDrawable(strokeWidth),
238 | createOuterStrokeDrawable(strokeWidth),
239 | getIconDrawable()
240 | });
241 |
242 | int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;
243 |
244 | int circleInsetHorizontal = (int) (mShadowRadius);
245 | int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
246 | int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);
247 |
248 | layerDrawable.setLayerInset(1,
249 | circleInsetHorizontal,
250 | circleInsetTop,
251 | circleInsetHorizontal,
252 | circleInsetBottom);
253 |
254 | layerDrawable.setLayerInset(2,
255 | (int) (circleInsetHorizontal - halfStrokeWidth),
256 | (int) (circleInsetTop - halfStrokeWidth),
257 | (int) (circleInsetHorizontal - halfStrokeWidth),
258 | (int) (circleInsetBottom - halfStrokeWidth));
259 |
260 | layerDrawable.setLayerInset(3,
261 | circleInsetHorizontal + iconOffset,
262 | circleInsetTop + iconOffset,
263 | circleInsetHorizontal + iconOffset,
264 | circleInsetBottom + iconOffset);
265 |
266 | setBackgroundCompat(layerDrawable);
267 | }
268 |
269 | Drawable getIconDrawable() {
270 | if (mIconDrawable != null) {
271 | return mIconDrawable;
272 | } else if (mIcon != 0) {
273 | return getResources().getDrawable(mIcon);
274 | } else {
275 | return new ColorDrawable(Color.TRANSPARENT);
276 | }
277 | }
278 |
279 | private StateListDrawable createFillDrawable(float strokeWidth) {
280 | StateListDrawable drawable = new StateListDrawable();
281 | drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled, strokeWidth));
282 | drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed, strokeWidth));
283 | drawable.addState(new int[] { }, createCircleDrawable(mColorNormal, strokeWidth));
284 | return drawable;
285 | }
286 |
287 | private Drawable createCircleDrawable(int color, float strokeWidth) {
288 | int alpha = Color.alpha(color);
289 | int opaqueColor = opaque(color);
290 |
291 | ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
292 |
293 | final Paint paint = fillDrawable.getPaint();
294 | paint.setAntiAlias(true);
295 | paint.setColor(opaqueColor);
296 |
297 | Drawable[] layers = {
298 | fillDrawable,
299 | createInnerStrokesDrawable(opaqueColor, strokeWidth)
300 | };
301 |
302 | LayerDrawable drawable = alpha == 255 || !mStrokeVisible
303 | ? new LayerDrawable(layers)
304 | : new TranslucentLayerDrawable(alpha, layers);
305 |
306 | int halfStrokeWidth = (int) (strokeWidth / 2f);
307 | drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
308 |
309 | return drawable;
310 | }
311 |
312 | private static class TranslucentLayerDrawable extends LayerDrawable {
313 | private final int mAlpha;
314 |
315 | public TranslucentLayerDrawable(int alpha, Drawable... layers) {
316 | super(layers);
317 | mAlpha = alpha;
318 | }
319 |
320 | @Override
321 | public void draw(Canvas canvas) {
322 | Rect bounds = getBounds();
323 | canvas.saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, mAlpha, Canvas.ALL_SAVE_FLAG);
324 | super.draw(canvas);
325 | canvas.restore();
326 | }
327 | }
328 |
329 | private Drawable createOuterStrokeDrawable(float strokeWidth) {
330 | ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
331 |
332 | final Paint paint = shapeDrawable.getPaint();
333 | paint.setAntiAlias(true);
334 | paint.setStrokeWidth(strokeWidth);
335 | paint.setStyle(Style.STROKE);
336 | paint.setColor(Color.BLACK);
337 | paint.setAlpha(opacityToAlpha(0.02f));
338 |
339 | return shapeDrawable;
340 | }
341 |
342 | private int opacityToAlpha(float opacity) {
343 | return (int) (255f * opacity);
344 | }
345 |
346 | private int darkenColor(int argb) {
347 | return adjustColorBrightness(argb, 0.9f);
348 | }
349 |
350 | private int lightenColor(int argb) {
351 | return adjustColorBrightness(argb, 1.1f);
352 | }
353 |
354 | private int adjustColorBrightness(int argb, float factor) {
355 | float[] hsv = new float[3];
356 | Color.colorToHSV(argb, hsv);
357 |
358 | hsv[2] = Math.min(hsv[2] * factor, 1f);
359 |
360 | return Color.HSVToColor(Color.alpha(argb), hsv);
361 | }
362 |
363 | private int halfTransparent(int argb) {
364 | return Color.argb(
365 | Color.alpha(argb) / 2,
366 | Color.red(argb),
367 | Color.green(argb),
368 | Color.blue(argb)
369 | );
370 | }
371 |
372 | private int opaque(int argb) {
373 | return Color.rgb(
374 | Color.red(argb),
375 | Color.green(argb),
376 | Color.blue(argb)
377 | );
378 | }
379 |
380 | private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
381 | if (!mStrokeVisible) {
382 | return new ColorDrawable(Color.TRANSPARENT);
383 | }
384 |
385 | ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
386 |
387 | final int bottomStrokeColor = darkenColor(color);
388 | final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
389 | final int topStrokeColor = lightenColor(color);
390 | final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
391 |
392 | final Paint paint = shapeDrawable.getPaint();
393 | paint.setAntiAlias(true);
394 | paint.setStrokeWidth(strokeWidth);
395 | paint.setStyle(Style.STROKE);
396 | shapeDrawable.setShaderFactory(new ShaderFactory() {
397 | @Override
398 | public Shader resize(int width, int height) {
399 | return new LinearGradient(width / 2, 0, width / 2, height,
400 | new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor },
401 | new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f },
402 | TileMode.CLAMP
403 | );
404 | }
405 | });
406 |
407 | return shapeDrawable;
408 | }
409 |
410 | @SuppressWarnings("deprecation")
411 | @SuppressLint("NewApi")
412 | private void setBackgroundCompat(Drawable drawable) {
413 | if (Build.VERSION.SDK_INT >= VERSION_CODES.BASE) {
414 | setBackgroundDrawable(drawable);
415 | } else {
416 | setBackgroundDrawable(drawable);
417 | }
418 | }
419 |
420 | @Override
421 | public void setVisibility(int visibility) {
422 | TextView label = getLabelView();
423 | if (label != null) {
424 | label.setVisibility(visibility);
425 | }
426 |
427 | super.setVisibility(visibility);
428 | }
429 | }
430 |
--------------------------------------------------------------------------------
/library/src/main/src/com/getbase/floatingactionbutton/FloatingActionsMenu.java:
--------------------------------------------------------------------------------
1 | package com.getbase.floatingactionbutton;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Canvas;
8 | import android.graphics.drawable.Drawable;
9 | import android.graphics.drawable.LayerDrawable;
10 | import android.os.Parcel;
11 | import android.os.Parcelable;
12 | import android.support.annotation.ColorRes;
13 | import android.support.annotation.NonNull;
14 | import android.util.AttributeSet;
15 | import android.view.ContextThemeWrapper;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.animation.DecelerateInterpolator;
19 | import android.view.animation.Interpolator;
20 | import android.view.animation.OvershootInterpolator;
21 | import android.widget.TextView;
22 |
23 | public class FloatingActionsMenu extends ViewGroup {
24 | public static final int EXPAND_UP = 0;
25 | public static final int EXPAND_DOWN = 1;
26 | public static final int EXPAND_LEFT = 2;
27 | public static final int EXPAND_RIGHT = 3;
28 |
29 | public static final int LABELS_ON_LEFT_SIDE = 0;
30 | public static final int LABELS_ON_RIGHT_SIDE = 1;
31 |
32 | private static final int ANIMATION_DURATION = 300;
33 | private static final float COLLAPSED_PLUS_ROTATION = 0f;
34 | private static final float EXPANDED_PLUS_ROTATION = 90f + 45f;
35 |
36 | private int mAddButtonPlusColor;
37 | private int mAddButtonColorNormal;
38 | private int mAddButtonColorPressed;
39 | private int mAddButtonSize;
40 | private boolean mAddButtonStrokeVisible;
41 | private int mExpandDirection;
42 |
43 | private int mButtonSpacing;
44 | private int mLabelsMargin;
45 | private int mLabelsVerticalOffset;
46 |
47 | private boolean mExpanded;
48 |
49 | private AnimatorSet mExpandAnimation = new AnimatorSet().setDuration(ANIMATION_DURATION);
50 | private AnimatorSet mCollapseAnimation = new AnimatorSet().setDuration(ANIMATION_DURATION);
51 | private AddFloatingActionButton mAddButton;
52 | private RotatingDrawable mRotatingDrawable;
53 | private int mMaxButtonWidth;
54 | private int mMaxButtonHeight;
55 | private int mLabelsStyle;
56 | private int mLabelsPosition;
57 | private int mButtonsCount;
58 |
59 | private OnFloatingActionsMenuUpdateListener mListener;
60 |
61 | public interface OnFloatingActionsMenuUpdateListener {
62 | void onMenuExpanded();
63 | void onMenuCollapsed();
64 | }
65 |
66 | public FloatingActionsMenu(Context context) {
67 | this(context, null);
68 | }
69 |
70 | public FloatingActionsMenu(Context context, AttributeSet attrs) {
71 | super(context, attrs);
72 | init(context, attrs);
73 | }
74 |
75 | public FloatingActionsMenu(Context context, AttributeSet attrs, int defStyle) {
76 | super(context, attrs, defStyle);
77 | init(context, attrs);
78 | }
79 |
80 | private void init(Context context, AttributeSet attributeSet) {
81 | mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));
82 | mLabelsMargin = getResources().getDimensionPixelSize(R.dimen.fab_labels_margin);
83 | mLabelsVerticalOffset = getResources().getDimensionPixelSize(R.dimen.fab_shadow_offset);
84 |
85 | TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
86 | mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonPlusIconColor, getColor(android.R.color.white));
87 | mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
88 | mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
89 | mAddButtonSize = attr.getInt(R.styleable.FloatingActionsMenu_fab_addButtonSize, FloatingActionButton.SIZE_NORMAL);
90 | mAddButtonStrokeVisible = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_addButtonStrokeVisible, true);
91 | mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP);
92 | mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionsMenu_fab_labelStyle, 0);
93 | mLabelsPosition = attr.getInt(R.styleable.FloatingActionsMenu_fab_labelsPosition, LABELS_ON_LEFT_SIDE);
94 | attr.recycle();
95 |
96 | if (mLabelsStyle != 0 && expandsHorizontally()) {
97 | throw new IllegalStateException("Action labels in horizontal expand orientation is not supported.");
98 | }
99 |
100 | createAddButton(context);
101 | }
102 |
103 | public void setOnFloatingActionsMenuUpdateListener(OnFloatingActionsMenuUpdateListener listener) {
104 | mListener = listener;
105 | }
106 |
107 | private boolean expandsHorizontally() {
108 | return mExpandDirection == EXPAND_LEFT || mExpandDirection == EXPAND_RIGHT;
109 | }
110 |
111 | private static class RotatingDrawable extends LayerDrawable {
112 | public RotatingDrawable(Drawable drawable) {
113 | super(new Drawable[] { drawable });
114 | }
115 |
116 | private float mRotation;
117 |
118 | @SuppressWarnings("UnusedDeclaration")
119 | public float getRotation() {
120 | return mRotation;
121 | }
122 |
123 | @SuppressWarnings("UnusedDeclaration")
124 | public void setRotation(float rotation) {
125 | mRotation = rotation;
126 | invalidateSelf();
127 | }
128 |
129 | @Override
130 | public void draw(Canvas canvas) {
131 | canvas.save();
132 | canvas.rotate(mRotation, getBounds().centerX(), getBounds().centerY());
133 | super.draw(canvas);
134 | canvas.restore();
135 | }
136 | }
137 |
138 | private void createAddButton(Context context) {
139 | mAddButton = new AddFloatingActionButton(context) {
140 | @Override
141 | void updateBackground() {
142 | mPlusColor = mAddButtonPlusColor;
143 | mColorNormal = mAddButtonColorNormal;
144 | mColorPressed = mAddButtonColorPressed;
145 | mStrokeVisible = mAddButtonStrokeVisible;
146 | super.updateBackground();
147 | }
148 |
149 | @Override
150 | Drawable getIconDrawable() {
151 | final RotatingDrawable rotatingDrawable = new RotatingDrawable(super.getIconDrawable());
152 | mRotatingDrawable = rotatingDrawable;
153 |
154 | final OvershootInterpolator interpolator = new OvershootInterpolator();
155 |
156 | final ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", EXPANDED_PLUS_ROTATION, COLLAPSED_PLUS_ROTATION);
157 | final ObjectAnimator expandAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", COLLAPSED_PLUS_ROTATION, EXPANDED_PLUS_ROTATION);
158 |
159 | collapseAnimator.setInterpolator(interpolator);
160 | expandAnimator.setInterpolator(interpolator);
161 |
162 | mExpandAnimation.play(expandAnimator);
163 | mCollapseAnimation.play(collapseAnimator);
164 |
165 | return rotatingDrawable;
166 | }
167 | };
168 |
169 | mAddButton.setId(R.id.fab_expand_menu_button);
170 | mAddButton.setSize(mAddButtonSize);
171 | mAddButton.setOnClickListener(new OnClickListener() {
172 | @Override
173 | public void onClick(View v) {
174 | toggle();
175 | }
176 | });
177 |
178 | addView(mAddButton, super.generateDefaultLayoutParams());
179 | }
180 |
181 | public void addButton(FloatingActionButton button) {
182 | addView(button, mButtonsCount - 1);
183 | mButtonsCount++;
184 |
185 | if (mLabelsStyle != 0) {
186 | createLabels();
187 | }
188 | }
189 |
190 | public void removeButton(FloatingActionButton button) {
191 | removeView(button.getLabelView());
192 | removeView(button);
193 | mButtonsCount--;
194 | }
195 |
196 | private int getColor(@ColorRes int id) {
197 | return getResources().getColor(id);
198 | }
199 |
200 | @Override
201 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
202 | measureChildren(widthMeasureSpec, heightMeasureSpec);
203 |
204 | int width = 0;
205 | int height = 0;
206 |
207 | mMaxButtonWidth = 0;
208 | mMaxButtonHeight = 0;
209 | int maxLabelWidth = 0;
210 |
211 | for (int i = 0; i < mButtonsCount; i++) {
212 | View child = getChildAt(i);
213 |
214 | if (child.getVisibility() == GONE) {
215 | continue;
216 | }
217 |
218 | switch (mExpandDirection) {
219 | case EXPAND_UP:
220 | case EXPAND_DOWN:
221 | mMaxButtonWidth = Math.max(mMaxButtonWidth, child.getMeasuredWidth());
222 | height += child.getMeasuredHeight();
223 | break;
224 | case EXPAND_LEFT:
225 | case EXPAND_RIGHT:
226 | width += child.getMeasuredWidth();
227 | mMaxButtonHeight = Math.max(mMaxButtonHeight, child.getMeasuredHeight());
228 | break;
229 | }
230 |
231 | if (!expandsHorizontally()) {
232 | TextView label = (TextView) child.getTag(R.id.fab_label);
233 | if (label != null) {
234 | maxLabelWidth = Math.max(maxLabelWidth, label.getMeasuredWidth());
235 | }
236 | }
237 | }
238 |
239 | if (!expandsHorizontally()) {
240 | width = mMaxButtonWidth + (maxLabelWidth > 0 ? maxLabelWidth + mLabelsMargin : 0);
241 | } else {
242 | height = mMaxButtonHeight;
243 | }
244 |
245 | switch (mExpandDirection) {
246 | case EXPAND_UP:
247 | case EXPAND_DOWN:
248 | height += mButtonSpacing * (getChildCount() - 1);
249 | height = adjustForOvershoot(height);
250 | break;
251 | case EXPAND_LEFT:
252 | case EXPAND_RIGHT:
253 | width += mButtonSpacing * (getChildCount() - 1);
254 | width = adjustForOvershoot(width);
255 | break;
256 | }
257 |
258 | setMeasuredDimension(width, height);
259 | }
260 |
261 | private int adjustForOvershoot(int dimension) {
262 | return dimension * 12 / 10;
263 | }
264 |
265 | @Override
266 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
267 | switch (mExpandDirection) {
268 | case EXPAND_UP:
269 | case EXPAND_DOWN:
270 | boolean expandUp = mExpandDirection == EXPAND_UP;
271 |
272 | int addButtonY = expandUp ? b - t - mAddButton.getMeasuredHeight() : 0;
273 | // Ensure mAddButton is centered on the line where the buttons should be
274 | int buttonsHorizontalCenter = mLabelsPosition == LABELS_ON_LEFT_SIDE
275 | ? r - l - mMaxButtonWidth / 2
276 | : mMaxButtonWidth / 2;
277 | int addButtonLeft = buttonsHorizontalCenter - mAddButton.getMeasuredWidth() / 2;
278 | mAddButton.layout(addButtonLeft, addButtonY, addButtonLeft + mAddButton.getMeasuredWidth(), addButtonY + mAddButton.getMeasuredHeight());
279 |
280 | int labelsOffset = mMaxButtonWidth / 2 + mLabelsMargin;
281 | int labelsXNearButton = mLabelsPosition == LABELS_ON_LEFT_SIDE
282 | ? buttonsHorizontalCenter - labelsOffset
283 | : buttonsHorizontalCenter + labelsOffset;
284 |
285 | int nextY = expandUp ?
286 | addButtonY - mButtonSpacing :
287 | addButtonY + mAddButton.getMeasuredHeight() + mButtonSpacing;
288 |
289 | for (int i = mButtonsCount - 1; i >= 0; i--) {
290 | final View child = getChildAt(i);
291 |
292 | if (child == mAddButton || child.getVisibility() == GONE) continue;
293 |
294 | int childX = buttonsHorizontalCenter - child.getMeasuredWidth() / 2;
295 | int childY = expandUp ? nextY - child.getMeasuredHeight() : nextY;
296 | child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
297 |
298 | float collapsedTranslation = addButtonY - childY;
299 | float expandedTranslation = 0f;
300 |
301 | child.setTranslationY(mExpanded ? expandedTranslation : collapsedTranslation);
302 | child.setAlpha(mExpanded ? 1f : 0f);
303 |
304 | LayoutParams params = (LayoutParams) child.getLayoutParams();
305 | params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
306 | params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
307 | params.setAnimationsTarget(child);
308 |
309 | View label = (View) child.getTag(R.id.fab_label);
310 | if (label != null) {
311 | int labelXAwayFromButton = mLabelsPosition == LABELS_ON_LEFT_SIDE
312 | ? labelsXNearButton - label.getMeasuredWidth()
313 | : labelsXNearButton + label.getMeasuredWidth();
314 |
315 | int labelLeft = mLabelsPosition == LABELS_ON_LEFT_SIDE
316 | ? labelXAwayFromButton
317 | : labelsXNearButton;
318 |
319 | int labelRight = mLabelsPosition == LABELS_ON_LEFT_SIDE
320 | ? labelsXNearButton
321 | : labelXAwayFromButton;
322 |
323 | int labelTop = childY - mLabelsVerticalOffset + (child.getMeasuredHeight() - label.getMeasuredHeight()) / 2;
324 |
325 | label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());
326 |
327 | label.setTranslationY(mExpanded ? expandedTranslation : collapsedTranslation);
328 | label.setAlpha(mExpanded ? 1f : 0f);
329 |
330 | LayoutParams labelParams = (LayoutParams) label.getLayoutParams();
331 | labelParams.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
332 | labelParams.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
333 | labelParams.setAnimationsTarget(label);
334 | }
335 |
336 | nextY = expandUp ?
337 | childY - mButtonSpacing :
338 | childY + child.getMeasuredHeight() + mButtonSpacing;
339 | }
340 | break;
341 |
342 | case EXPAND_LEFT:
343 | case EXPAND_RIGHT:
344 | boolean expandLeft = mExpandDirection == EXPAND_LEFT;
345 |
346 | int addButtonX = expandLeft ? r - l - mAddButton.getMeasuredWidth() : 0;
347 | // Ensure mAddButton is centered on the line where the buttons should be
348 | int addButtonTop = b - t - mMaxButtonHeight + (mMaxButtonHeight - mAddButton.getMeasuredHeight()) / 2;
349 | mAddButton.layout(addButtonX, addButtonTop, addButtonX + mAddButton.getMeasuredWidth(), addButtonTop + mAddButton.getMeasuredHeight());
350 |
351 | int nextX = expandLeft ?
352 | addButtonX - mButtonSpacing :
353 | addButtonX + mAddButton.getMeasuredWidth() + mButtonSpacing;
354 |
355 | for (int i = mButtonsCount - 1; i >= 0; i--) {
356 | final View child = getChildAt(i);
357 |
358 | if (child == mAddButton || child.getVisibility() == GONE) continue;
359 |
360 | int childX = expandLeft ? nextX - child.getMeasuredWidth() : nextX;
361 | int childY = addButtonTop + (mAddButton.getMeasuredHeight() - child.getMeasuredHeight()) / 2;
362 | child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
363 |
364 | float collapsedTranslation = addButtonX - childX;
365 | float expandedTranslation = 0f;
366 |
367 | child.setTranslationX(mExpanded ? expandedTranslation : collapsedTranslation);
368 | child.setAlpha(mExpanded ? 1f : 0f);
369 |
370 | LayoutParams params = (LayoutParams) child.getLayoutParams();
371 | params.mCollapseDir.setFloatValues(expandedTranslation, collapsedTranslation);
372 | params.mExpandDir.setFloatValues(collapsedTranslation, expandedTranslation);
373 | params.setAnimationsTarget(child);
374 |
375 | nextX = expandLeft ?
376 | childX - mButtonSpacing :
377 | childX + child.getMeasuredWidth() + mButtonSpacing;
378 | }
379 |
380 | break;
381 | }
382 | }
383 |
384 | @Override
385 | protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
386 | return new LayoutParams(super.generateDefaultLayoutParams());
387 | }
388 |
389 | @Override
390 | public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
391 | return new LayoutParams(super.generateLayoutParams(attrs));
392 | }
393 |
394 | @Override
395 | protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
396 | return new LayoutParams(super.generateLayoutParams(p));
397 | }
398 |
399 | @Override
400 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
401 | return super.checkLayoutParams(p);
402 | }
403 |
404 | private static Interpolator sExpandInterpolator = new OvershootInterpolator();
405 | private static Interpolator sCollapseInterpolator = new DecelerateInterpolator(3f);
406 | private static Interpolator sAlphaExpandInterpolator = new DecelerateInterpolator();
407 |
408 | private class LayoutParams extends ViewGroup.LayoutParams {
409 |
410 | private ObjectAnimator mExpandDir = new ObjectAnimator();
411 | private ObjectAnimator mExpandAlpha = new ObjectAnimator();
412 | private ObjectAnimator mCollapseDir = new ObjectAnimator();
413 | private ObjectAnimator mCollapseAlpha = new ObjectAnimator();
414 | private boolean animationsSetToPlay;
415 |
416 | public LayoutParams(ViewGroup.LayoutParams source) {
417 | super(source);
418 |
419 | mExpandDir.setInterpolator(sExpandInterpolator);
420 | mExpandAlpha.setInterpolator(sAlphaExpandInterpolator);
421 | mCollapseDir.setInterpolator(sCollapseInterpolator);
422 | mCollapseAlpha.setInterpolator(sCollapseInterpolator);
423 |
424 | mCollapseAlpha.setProperty(View.ALPHA);
425 | mCollapseAlpha.setFloatValues(1f, 0f);
426 |
427 | mExpandAlpha.setProperty(View.ALPHA);
428 | mExpandAlpha.setFloatValues(0f, 1f);
429 |
430 | switch (mExpandDirection) {
431 | case EXPAND_UP:
432 | case EXPAND_DOWN:
433 | mCollapseDir.setProperty(View.TRANSLATION_Y);
434 | mExpandDir.setProperty(View.TRANSLATION_Y);
435 | break;
436 | case EXPAND_LEFT:
437 | case EXPAND_RIGHT:
438 | mCollapseDir.setProperty(View.TRANSLATION_X);
439 | mExpandDir.setProperty(View.TRANSLATION_X);
440 | break;
441 | }
442 | }
443 |
444 | public void setAnimationsTarget(View view) {
445 | mCollapseAlpha.setTarget(view);
446 | mCollapseDir.setTarget(view);
447 | mExpandAlpha.setTarget(view);
448 | mExpandDir.setTarget(view);
449 |
450 | // Now that the animations have targets, set them to be played
451 | if (!animationsSetToPlay) {
452 | mCollapseAnimation.play(mCollapseAlpha);
453 | mCollapseAnimation.play(mCollapseDir);
454 | mExpandAnimation.play(mExpandAlpha);
455 | mExpandAnimation.play(mExpandDir);
456 | animationsSetToPlay = true;
457 | }
458 | }
459 | }
460 |
461 | @Override
462 | protected void onFinishInflate() {
463 | super.onFinishInflate();
464 |
465 | bringChildToFront(mAddButton);
466 | mButtonsCount = getChildCount();
467 |
468 | if (mLabelsStyle != 0) {
469 | createLabels();
470 | }
471 | }
472 |
473 | private void createLabels() {
474 | Context context = new ContextThemeWrapper(getContext(), mLabelsStyle);
475 |
476 | for (int i = 0; i < mButtonsCount; i++) {
477 | FloatingActionButton button = (FloatingActionButton) getChildAt(i);
478 | String title = button.getTitle();
479 |
480 | if (button == mAddButton || title == null ||
481 | button.getTag(R.id.fab_label) != null) continue;
482 |
483 | TextView label = new TextView(context);
484 | label.setText(button.getTitle());
485 | addView(label);
486 |
487 | button.setTag(R.id.fab_label, label);
488 | }
489 | }
490 |
491 | public void collapse() {
492 | if (mExpanded) {
493 | mExpanded = false;
494 | mCollapseAnimation.start();
495 | mExpandAnimation.cancel();
496 |
497 | if (mListener != null) {
498 | mListener.onMenuCollapsed();
499 | }
500 | }
501 | }
502 |
503 | public void toggle() {
504 | if (mExpanded) {
505 | collapse();
506 | } else {
507 | expand();
508 | }
509 | }
510 |
511 | public void expand() {
512 | if (!mExpanded) {
513 | mExpanded = true;
514 | mCollapseAnimation.cancel();
515 | mExpandAnimation.start();
516 |
517 | if (mListener != null) {
518 | mListener.onMenuExpanded();
519 | }
520 | }
521 | }
522 |
523 | public boolean isExpanded() {
524 | return mExpanded;
525 | }
526 |
527 | @Override
528 | public Parcelable onSaveInstanceState() {
529 | Parcelable superState = super.onSaveInstanceState();
530 | SavedState savedState = new SavedState(superState);
531 | savedState.mExpanded = mExpanded;
532 |
533 | return savedState;
534 | }
535 |
536 | @Override
537 | public void onRestoreInstanceState(Parcelable state) {
538 | if (state instanceof SavedState) {
539 | SavedState savedState = (SavedState) state;
540 | mExpanded = savedState.mExpanded;
541 |
542 | if (mRotatingDrawable != null) {
543 | mRotatingDrawable.setRotation(mExpanded ? EXPANDED_PLUS_ROTATION : COLLAPSED_PLUS_ROTATION);
544 | }
545 |
546 | super.onRestoreInstanceState(savedState.getSuperState());
547 | } else {
548 | super.onRestoreInstanceState(state);
549 | }
550 | }
551 |
552 | public static class SavedState extends BaseSavedState {
553 | public boolean mExpanded;
554 |
555 | public SavedState(Parcelable parcel) {
556 | super(parcel);
557 | }
558 |
559 | private SavedState(Parcel in) {
560 | super(in);
561 | mExpanded = in.readInt() == 1;
562 | }
563 |
564 | @Override
565 | public void writeToParcel(@NonNull Parcel out, int flags) {
566 | super.writeToParcel(out, flags);
567 | out.writeInt(mExpanded ? 1 : 0);
568 | }
569 |
570 | public static final Creator CREATOR = new Creator() {
571 |
572 | @Override
573 | public SavedState createFromParcel(Parcel in) {
574 | return new SavedState(in);
575 | }
576 |
577 | @Override
578 | public SavedState[] newArray(int size) {
579 | return new SavedState[size];
580 | }
581 | };
582 | }
583 | }
584 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.getbase.floatingactionbutton.sample"
9 | minSdkVersion 14
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled true
17 | signingConfig signingConfigs.debug
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile project(':library')
25 | }
26 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio Beta.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/getbase/floatingactionbutton/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.getbase.floatingactionbutton.sample;
2 |
3 | import android.app.Activity;
4 | import android.graphics.drawable.ShapeDrawable;
5 | import android.graphics.drawable.shapes.OvalShape;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Toast;
10 |
11 | import cc.trity.floatingactionbutton.FloatingActionButton;
12 | import cc.trity.floatingactionbutton.FloatingActionsMenu;
13 |
14 | public class MainActivity extends Activity {
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 | findViewById(R.id.pink_icon).setOnClickListener(new OnClickListener() {
21 | @Override
22 | public void onClick(View v) {
23 | Toast.makeText(MainActivity.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT).show();
24 | }
25 | });
26 |
27 | FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
28 | button.setSize(FloatingActionButton.SIZE_MINI);
29 | button.setColorNormalResId(R.color.pink);
30 | button.setColorPressedResId(R.color.pink_pressed);
31 | button.setIcon(R.drawable.ic_fab_star);
32 | button.setStrokeVisible(false);
33 |
34 | final View actionB = findViewById(R.id.action_b);
35 |
36 | FloatingActionButton actionC = new FloatingActionButton(getBaseContext());
37 | actionC.setTitle("Hide/Show Action above");
38 | actionC.setOnClickListener(new OnClickListener() {
39 | @Override
40 | public void onClick(View v) {
41 | actionB.setVisibility(actionB.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
42 | }
43 | });
44 | ((FloatingActionsMenu) findViewById(R.id.multiple_actions)).addButton(actionC);
45 |
46 | final FloatingActionButton removeAction = (FloatingActionButton) findViewById(R.id.button_remove);
47 | removeAction.setOnClickListener(new OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | ((FloatingActionsMenu) findViewById(R.id.multiple_actions_down)).removeButton(removeAction);
51 | }
52 | });
53 |
54 | ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
55 | drawable.getPaint().setColor(getResources().getColor(R.color.white));
56 | ((FloatingActionButton) findViewById(R.id.setter_drawable)).setIconDrawable(drawable);
57 |
58 | final FloatingActionButton actionA = (FloatingActionButton) findViewById(R.id.action_a);
59 | actionA.setOnClickListener(new OnClickListener() {
60 | @Override
61 | public void onClick(View view) {
62 | actionA.setTitle("Action A clicked");
63 | }
64 | });
65 |
66 | // Test that FAMs containing FABs with visibility GONE do not cause crashes
67 | findViewById(R.id.button_gone).setVisibility(View.GONE);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_fab_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/sample/src/main/res/drawable-hdpi/ic_fab_star.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-mdpi/ic_fab_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/sample/src/main/res/drawable-mdpi/ic_fab_star.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_fab_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/sample/src/main/res/drawable-xhdpi/ic_fab_star.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_fab_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/sample/src/main/res/drawable-xxhdpi/ic_fab_star.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/fab_label_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
17 |
18 |
26 |
27 |
37 |
38 |
45 |
46 |
59 |
60 |
74 |
75 |
81 |
82 |
89 |
90 |
91 |
92 |
108 |
109 |
116 |
117 |
124 |
125 |
126 |
127 |
143 |
144 |
150 |
151 |
158 |
159 |
165 |
166 |
167 |
168 |
184 |
185 |
190 |
191 |
197 |
198 |
205 |
206 |
207 |
208 |
214 |
215 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #B2000000
4 | #e5e5e5
5 | #808080
6 | #fafafa
7 | #f1f1f1
8 | #e91e63
9 | #ec407a
10 | #805677fc
11 | #80738ffe
12 |
13 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Floating Action Button
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/screenshots/buttons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/screenshots/buttons.png
--------------------------------------------------------------------------------
/screenshots/custom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/screenshots/custom.png
--------------------------------------------------------------------------------
/screenshots/labels.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/screenshots/labels.png
--------------------------------------------------------------------------------
/screenshots/menu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trity1993/FloatingActionButton/cb7ad6bf81c40c7280c59747c7102dc2565ee4fb/screenshots/menu.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library', ':sample'
2 |
--------------------------------------------------------------------------------