├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ └── layout
│ │ │ │ ├── content_main.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── appnirman
│ │ │ └── sampleapp
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── appnirman
│ │ │ └── sampleapp
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── appnirman
│ │ └── sampleapp
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── viewclickanimation
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── attr.xml
│ │ │ └── layout
│ │ │ │ ├── bottom_sheet_layout.xml
│ │ │ │ └── footer_layout.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── appnirman
│ │ │ └── viewclickanimation
│ │ │ ├── ViewUtils.java
│ │ │ ├── AppUtils.java
│ │ │ ├── FooterBehavior.java
│ │ │ ├── SpringList.java
│ │ │ ├── SheetLayoutCustom.java
│ │ │ └── FooterLayout.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── appnirman
│ │ │ └── viewclickanimation
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── appnirman
│ │ └── viewclickanimation
│ │ └── ExampleInstrumentationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── Screen
└── videotogif_2016.12.30_02.23.16.gif
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | Sample App
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/viewclickanimation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':viewclickanimation'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ViewClickAnimation
3 |
4 |
--------------------------------------------------------------------------------
/Screen/videotogif_2016.12.30_02.23.16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/Screen/videotogif_2016.12.30_02.23.16.gif
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sgaikar1/ViewClickAnimation/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Sample App
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4dp
4 | 56dp
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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.10-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/appnirman/sampleapp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.sampleapp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/appnirman/sampleapp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.sampleapp;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/viewclickanimation/src/test/java/com/appnirman/viewclickanimation/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/res/layout/bottom_sheet_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
--------------------------------------------------------------------------------
/app/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 G:\Android\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 |
--------------------------------------------------------------------------------
/viewclickanimation/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 D:\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 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
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
--------------------------------------------------------------------------------
/viewclickanimation/src/main/res/layout/footer_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.appnirman.sampleapp"
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | repositories {
23 | mavenCentral()
24 |
25 | maven {
26 | url "https://jitpack.io"
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(include: ['*.jar'], dir: 'libs')
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.android.support:appcompat-v7:24.2.1'
34 | compile 'com.android.support:design:24.2.1'
35 | compile project(':viewclickanimation')
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/gradle.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 |
--------------------------------------------------------------------------------
/viewclickanimation/src/androidTest/java/com/appnirman/viewclickanimation/ExampleInstrumentationTest.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.filters.MediumTest;
6 | import android.support.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 |
12 | import static junit.framework.Assert.assertEquals;
13 | import static org.junit.Assert.*;
14 |
15 | /**
16 | * Instrumentation test, which will execute on an Android device.
17 | *
18 | * @see Testing documentation
19 | */
20 | @MediumTest
21 | @RunWith(AndroidJUnit4.class)
22 | public class ExampleInstrumentationTest {
23 | @Test
24 | public void useAppContext() throws Exception {
25 | // Context of the app under test.
26 | Context appContext = InstrumentationRegistry.getTargetContext();
27 |
28 | assertEquals("com.appnirman.viewclickanimation.test", appContext.getPackageName());
29 | }
30 | }
--------------------------------------------------------------------------------
/viewclickanimation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | repositories {
24 | mavenCentral()
25 |
26 | maven {
27 | url "https://jitpack.io"
28 | }
29 | }
30 |
31 | dependencies {
32 | compile fileTree(dir: 'libs', include: ['*.jar'])
33 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
34 | exclude group: 'com.android.support', module: 'support-annotations'
35 | })
36 | testCompile 'junit:junit:4.12'
37 | compile 'com.facebook.rebound:rebound:0.3.8'
38 | compile 'com.android.support:design:24.2.1'
39 | compile ('com.github.ozodrukh:CircularReveal:1.3.1@aar') {
40 | transitive = true;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/java/com/appnirman/viewclickanimation/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import android.support.v4.view.ViewCompat;
4 | import android.view.View;
5 |
6 |
7 | public class ViewUtils {
8 |
9 | public static boolean setVisibility(View v, boolean visible) {
10 | int visibility;
11 | if (visible) {
12 | visibility = View.VISIBLE;
13 | } else {
14 | visibility = View.GONE;
15 | }
16 | v.setVisibility(visibility);
17 | return visible;
18 | }
19 |
20 | public static boolean setInVisibility(View v, boolean visible) {
21 | int visibility;
22 | if (visible) {
23 | visibility = View.VISIBLE;
24 | } else {
25 | visibility = View.INVISIBLE;
26 | }
27 | v.setVisibility(visibility);
28 | return visible;
29 | }
30 |
31 | public static float centerX(View view) {
32 | return ViewCompat.getX(view) + view.getWidth() / 2f;
33 | }
34 |
35 | public static float centerY(View view) {
36 | return ViewCompat.getY(view) + view.getHeight() / 2f;
37 | }
38 |
39 | public static int getRelativeTop(View myView) {
40 | if (myView.getParent() == myView.getRootView()) {
41 | return myView.getTop();
42 | } else {
43 | return myView.getTop() + getRelativeTop((View) myView.getParent());
44 | }
45 | }
46 |
47 | private ViewUtils() {
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ViewClickAnimation
2 |
3 |
4 | The goal of this library is to allow your app to support Facebooks Rebound effect on all views, with circular reveal effect and also provides bottom bar with circular reveal effect.
5 | ram size depending animation play support.
6 |
7 | ##Preview
8 | 
9 |
10 |
11 |
12 | ### Installation
13 |
14 | ```
15 | allprojects {
16 | repositories {
17 | ...
18 | maven { url 'https://jitpack.io' }
19 | }
20 | }
21 |
22 | //import this library as module
23 | compile project(':viewclickanimation')
24 | ```
25 |
26 | ### Usage
27 |
28 | * For implementation please refer to the sample app.
29 |
30 | ##Credits
31 |
32 | * [ozodrukh](https://github.com/ozodrukh/CircularReveal)
33 | * [coyarzun89](https://github.com/coyarzun89/FabTransitionActivity)
34 | * [Facebook - rebound](https://github.com/facebook/rebound)
35 | * [Support by Rehan Kodekar](https://github.com/mkodekar)
36 |
37 |
38 | ## License
39 |
40 | * [Apache Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
41 |
42 | ```
43 | Copyright 2016 Santosh Gaikar....
44 |
45 | Licensed under the Apache License, Version 2.0 (the "License");
46 | you may not use this file except in compliance with the License.
47 | You may obtain a copy of the License at
48 |
49 | http://www.apache.org/licenses/LICENSE-2.0
50 |
51 | Unless required by applicable law or agreed to in writing, software
52 | distributed under the License is distributed on an "AS IS" BASIS,
53 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
54 | See the License for the specific language governing permissions and
55 | limitations under the License.
56 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/java/com/appnirman/viewclickanimation/AppUtils.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import java.io.IOException;
4 | import java.io.RandomAccessFile;
5 | import java.text.DecimalFormat;
6 | import java.util.regex.Matcher;
7 | import java.util.regex.Pattern;
8 |
9 | public class AppUtils {
10 |
11 |
12 | public static boolean isLowRAM() {
13 |
14 | RandomAccessFile reader = null;
15 | String load = null;
16 | DecimalFormat twoDecimalForm = new DecimalFormat("#.##");
17 | double totRam = 0;
18 | String lastValue = "";
19 | boolean sizeFlag=false;
20 | try {
21 | reader = new RandomAccessFile("/proc/meminfo", "r");
22 | load = reader.readLine();
23 |
24 | // Get the Number value from the string
25 | Pattern p = Pattern.compile("(\\d+)");
26 | Matcher m = p.matcher(load);
27 | String value = "";
28 | while (m.find()) {
29 | value = m.group(1);
30 | // System.out.println("Ram : " + value);
31 | }
32 | reader.close();
33 |
34 | totRam = Double.parseDouble(value);
35 | // totRam = totRam / 1024;
36 |
37 | double mb = totRam / 1024.0;
38 | double gb = totRam / 1048576.0;
39 | double tb = totRam / 1073741824.0;
40 |
41 | if (tb > 1) {
42 | lastValue = twoDecimalForm.format(tb).concat(" TB");
43 | sizeFlag=false;
44 | } else if (gb > 1) {
45 | lastValue = twoDecimalForm.format(gb).concat(" GB");
46 | sizeFlag=false;
47 | } else if (mb > 1) {
48 | lastValue = twoDecimalForm.format(mb).concat(" MB");
49 | sizeFlag=true;
50 | } else {
51 | lastValue = twoDecimalForm.format(totRam).concat(" KB");
52 | sizeFlag=true;
53 | }
54 |
55 | } catch (IOException ex) {
56 | ex.printStackTrace();
57 | } finally {
58 | // Streams.close(reader);
59 | }
60 |
61 | return sizeFlag;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/misc.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 | Android > Lint > Correctness
39 |
40 |
41 | Android > Lint > Usability
42 |
43 |
44 | Google Cloud Endpoints
45 |
46 |
47 |
48 |
49 | AndroidLintGoogleAppIndexingUrlError
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/java/com/appnirman/viewclickanimation/FooterBehavior.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import android.support.design.widget.CoordinatorLayout;
4 |
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.os.Build;
8 | import android.support.design.widget.CoordinatorLayout;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v4.view.ViewCompat;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 | import java.util.List;
14 |
15 | public class FooterBehavior extends CoordinatorLayout.Behavior {
16 |
17 | private static final boolean SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
18 |
19 | private ValueAnimator mTranslationYAnimator;
20 | private float mFooterTranslationY;
21 |
22 | public FooterBehavior() {
23 | super();
24 | }
25 |
26 | public FooterBehavior(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | @Override
31 | public void onNestedScroll(CoordinatorLayout coordinatorLayout, FooterLayout child, View target,
32 | int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
33 |
34 | super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
35 | dyUnconsumed);
36 |
37 | if (dyConsumed > 0) {
38 | child.contractFab();
39 | } else if (dyConsumed < 0) {
40 | child.contractFab();
41 | }
42 | }
43 |
44 | @Override
45 | public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FooterLayout child,
46 | View directTargetChild, View target, int nestedScrollAxes) {
47 |
48 | return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL || super.onStartNestedScroll(
49 | coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
50 | }
51 |
52 | @Override
53 | public boolean layoutDependsOn(CoordinatorLayout parent, FooterLayout child, View dependency) {
54 |
55 | return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
56 | }
57 |
58 | @Override public boolean onDependentViewChanged(CoordinatorLayout parent, FooterLayout child,
59 | View dependency) {
60 | if (dependency instanceof Snackbar.SnackbarLayout) {
61 | updateTranslationForSnackbar(parent, child);
62 | }
63 | return false;
64 | }
65 |
66 | private void updateTranslationForSnackbar(CoordinatorLayout parent,
67 | final FooterLayout footerLayout) {
68 | final float targetTransY = getTranslationYForSnackbar(parent, footerLayout);
69 | if (mFooterTranslationY == targetTransY) {
70 | return;
71 | }
72 |
73 | final float currentTransY = ViewCompat.getTranslationY(footerLayout);
74 |
75 | if (mTranslationYAnimator != null && mTranslationYAnimator.isRunning()) {
76 | mTranslationYAnimator.cancel();
77 | }
78 |
79 | if (footerLayout.isShown() && Math.abs(currentTransY - targetTransY) > (footerLayout.getHeight()
80 | * 0.667f)) {
81 | mTranslationYAnimator.setFloatValues(currentTransY, targetTransY);
82 | mTranslationYAnimator.start();
83 | } else {
84 |
85 | ViewCompat.setTranslationY(footerLayout, targetTransY);
86 | }
87 |
88 | mFooterTranslationY = targetTransY;
89 | }
90 |
91 | private float getTranslationYForSnackbar(CoordinatorLayout parent, FooterLayout footerLayout) {
92 |
93 | float minOffset = 0;
94 | final List dependencies = parent.getDependencies(footerLayout);
95 | for (int i = 0, z = dependencies.size(); i < z; i++) {
96 | final View view = dependencies.get(i);
97 | if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(footerLayout, view)) {
98 | minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - view.getHeight());
99 | }
100 | }
101 |
102 | return minOffset;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
43 |
44 |
52 |
53 |
61 |
62 |
71 |
72 |
79 |
80 |
87 |
88 |
92 |
93 |
97 |
98 |
99 |
106 |
107 |
111 |
112 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/java/com/appnirman/viewclickanimation/SpringList.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import android.content.Context;
4 | import android.view.MotionEvent;
5 | import android.view.View;
6 |
7 | import com.facebook.rebound.BaseSpringSystem;
8 | import com.facebook.rebound.SimpleSpringListener;
9 | import com.facebook.rebound.Spring;
10 | import com.facebook.rebound.SpringSystem;
11 | import com.facebook.rebound.SpringUtil;
12 |
13 | public class SpringList {
14 | private final Spring spring;
15 | private final SheetLayoutCustom mSheetLayout;
16 | private final boolean ramSizeCheck;
17 | Context context;
18 | View view;
19 |
20 | private final BaseSpringSystem mSpringSystem = SpringSystem.create();
21 | private final ExampleSpringListener mSpringListener = new ExampleSpringListener();
22 | private SpringCompleteListsener springCompleteListener;
23 | private boolean useFloatSheetAnim = true;
24 | private boolean useSpinAnim = true;
25 |
26 | public void useSpringAnim(boolean useSpinAnim) {
27 | this.useSpinAnim = useSpinAnim;
28 | }
29 |
30 | public void useFloatingSheetAnim(boolean useFloatSheetAnim) {
31 | this.useFloatSheetAnim = useFloatSheetAnim;
32 | }
33 |
34 | public void setView(View view) {
35 | this.view = view;
36 | }
37 |
38 |
39 | public static class Builder {
40 | Context context;
41 | View view;
42 | private SheetLayoutCustom mSheetLayout;
43 | private boolean ramSizeCheck = true;
44 | private SpringCompleteListsener springCompleteListener;
45 |
46 | public Builder setContext(Context context) {
47 | this.context = context;
48 | return this;
49 | }
50 |
51 |
52 | public Builder setSheet(SheetLayoutCustom mSheetLayout) {
53 | this.mSheetLayout = mSheetLayout;
54 | return this;
55 | }
56 |
57 |
58 | public Builder registerSpringListener(SpringCompleteListsener springCompleteListsener) {
59 | this.springCompleteListener = springCompleteListsener;
60 | return this;
61 | }
62 |
63 | public SpringList build() {
64 | return new SpringList(this);
65 | }
66 |
67 |
68 | public Builder checkRam(boolean check) {
69 | this.ramSizeCheck = check;
70 | return this;
71 | }
72 | }
73 |
74 | private SpringList(Builder builder) {
75 | this.context = builder.context;
76 | this.view = builder.view;
77 | this.mSheetLayout = builder.mSheetLayout;
78 | this.ramSizeCheck = builder.ramSizeCheck;
79 | this.springCompleteListener = builder.springCompleteListener;
80 |
81 | spring = mSpringSystem.createSpring();
82 | spring.addListener(mSpringListener);
83 | }
84 |
85 | private class ExampleSpringListener extends SimpleSpringListener {
86 | @Override
87 | public void onSpringUpdate(Spring spring) {
88 | if (ramSizeCheck) {
89 | if (AppUtils.isLowRAM()) {
90 | springCompleteListener.onSpringCompleteListener(view);
91 | } else {
92 | if(useSpinAnim) {
93 | double value = spring.getCurrentValue();
94 | float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0.5);
95 | view.setScaleX(mappedValue);
96 | view.setScaleY(mappedValue);
97 | }
98 | }
99 | } else {
100 | if(useSpinAnim) {
101 | double value = spring.getCurrentValue();
102 | float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, 1, 0.5);
103 | view.setScaleX(mappedValue);
104 | view.setScaleY(mappedValue);
105 | }
106 | }
107 | }
108 |
109 | @Override
110 | public void onSpringAtRest(Spring spring) {
111 | super.onSpringAtRest(spring);
112 |
113 | if (ramSizeCheck) {
114 | if (AppUtils.isLowRAM()) {
115 | springCompleteListener.onSpringCompleteListener(view);
116 | } else {
117 | if(useFloatSheetAnim) {
118 | mSheetLayout.setFab(view);
119 | mSheetLayout.expandFab();
120 | }else{
121 | springCompleteListener.onSpringCompleteListener(view);
122 | }
123 | }
124 | }else{
125 | if(useFloatSheetAnim) {
126 | mSheetLayout.setFab(view);
127 | mSheetLayout.expandFab();
128 | }else{
129 | springCompleteListener.onSpringCompleteListener(view);
130 | }
131 | }
132 | if(useFloatSheetAnim) {
133 | mSheetLayout.setFabAnimationEndListener(new SheetLayoutCustom.OnFabAnimationEndListener() {
134 | @Override
135 | public void onFabAnimationEnd() {
136 | springCompleteListener.onSpringCompleteListener(view);
137 | }
138 | });
139 | }
140 | }
141 | }
142 |
143 | public boolean onTouch(MotionEvent motionEvent) {
144 |
145 | switch (motionEvent.getAction()) {
146 | case MotionEvent.ACTION_DOWN:
147 | spring.setEndValue(1);
148 | break;
149 | case MotionEvent.ACTION_UP:
150 | case MotionEvent.ACTION_CANCEL:
151 | spring.setEndValue(0);
152 | break;
153 | }
154 | return true;
155 | }
156 |
157 | public void registerSpringListener(SpringCompleteListsener springCompleteListsener) {
158 | this.springCompleteListener = springCompleteListsener;
159 | }
160 |
161 | public interface SpringCompleteListsener {
162 | void onSpringCompleteListener(View view);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/appnirman/sampleapp/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.sampleapp;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.PropertyValuesHolder;
6 | import android.os.Bundle;
7 | import android.support.design.widget.FloatingActionButton;
8 | import android.support.design.widget.Snackbar;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.view.WindowManager;
14 | import android.widget.LinearLayout;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import com.appnirman.viewclickanimation.FooterLayout;
19 | import com.appnirman.viewclickanimation.SheetLayoutCustom;
20 | import com.appnirman.viewclickanimation.SpringList;
21 |
22 | public class MainActivity extends AppCompatActivity implements SpringList.SpringCompleteListsener {
23 |
24 | private FloatingActionButton fab,fabAdd;
25 | private SheetLayoutCustom mSheetLayout;
26 | private FooterLayout fabToolbar;
27 | private LinearLayout llLogout,llNewPatient;
28 | private FloatingActionButton fab2;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
35 | setSupportActionBar(toolbar);
36 | mSheetLayout = (SheetLayoutCustom) findViewById(R.id.bottom_sheet);
37 | final TextView tv =(TextView)findViewById(R.id.tv_hello);
38 | fab = (FloatingActionButton) findViewById(R.id.fab);
39 | fab2 = (FloatingActionButton) findViewById(R.id.fab2);
40 |
41 | fabAdd = (FloatingActionButton) findViewById(R.id.fab_add);
42 | fabToolbar = (FooterLayout) findViewById(R.id.fabtoolbar);
43 |
44 | llLogout = (LinearLayout)findViewById(R.id.ll_logout);
45 | llNewPatient = (LinearLayout)findViewById(R.id.ll_new_patient);
46 |
47 |
48 | final com.appnirman.viewclickanimation.SpringList springList = new SpringList.Builder()
49 | .checkRam(true)
50 | .setSheet(mSheetLayout)
51 | .setContext(MainActivity.this)
52 | .registerSpringListener(MainActivity.this)
53 | .build();
54 |
55 |
56 |
57 | /*Fab click circular reveal animation with facebooks rebound animation sample*/
58 | fab.setOnTouchListener(new View.OnTouchListener() {
59 | @Override
60 | public boolean onTouch(View view, MotionEvent motionEvent) {
61 | springList.setView(fab);
62 | springList.useSpringAnim(true);
63 | springList.useFloatingSheetAnim(true);
64 | return springList.onTouch(motionEvent);
65 | }
66 | });
67 |
68 | tv.setOnTouchListener(new View.OnTouchListener() {
69 | @Override
70 | public boolean onTouch(View view, MotionEvent motionEvent) {
71 | springList.setView(tv);
72 | springList.useSpringAnim(true);
73 | springList.useFloatingSheetAnim(true);
74 | return springList.onTouch(motionEvent);
75 | }
76 | });
77 |
78 | fab2.setOnTouchListener(new View.OnTouchListener() {
79 | @Override
80 | public boolean onTouch(View view, MotionEvent motionEvent) {
81 | springList.setView(fab2);
82 | springList.useSpringAnim(true);
83 | springList.useFloatingSheetAnim(false);
84 | return springList.onTouch(motionEvent);
85 | }
86 | });
87 |
88 |
89 | /*fab click circular reveal toolbar animation*/
90 | fabToolbar.setFab(fabAdd);
91 | fabToolbar.setClosedOnTouchOutside(true);
92 |
93 | fabAdd.setOnClickListener(new View.OnClickListener() {
94 | @Override
95 | public void onClick(View v) {
96 | fabToolbar.expandFab();
97 | WindowManager.LayoutParams windowManager = getWindow().getAttributes();
98 | windowManager.dimAmount = 0.75f;
99 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
100 | }
101 | });
102 |
103 | llNewPatient.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | iconAnim(llNewPatient);
107 | Toast.makeText(MainActivity.this,"New Patient Clicked",Toast.LENGTH_SHORT).show();
108 | }
109 | });
110 | llLogout.setOnClickListener(new View.OnClickListener() {
111 | @Override
112 | public void onClick(View v) {
113 | iconAnim(llLogout);
114 | Toast.makeText(MainActivity.this,"Logout Clicked",Toast.LENGTH_SHORT).show();
115 | }
116 | });
117 | }
118 |
119 | private void iconAnim(View icon) {
120 | Animator iconAnim = ObjectAnimator.ofPropertyValuesHolder(icon,
121 | PropertyValuesHolder.ofFloat(View.SCALE_X, 1f, 1.5f, 1f),
122 | PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 1.5f, 1f));
123 | iconAnim.start();
124 | }
125 |
126 | private void openSnackbar(View view) {
127 | Snackbar.make(fab, "Replace with your own action", Snackbar.LENGTH_LONG)
128 | .setAction("Action", null).show();
129 | }
130 |
131 | private void contractFabToolbar() {
132 | fabToolbar.contractFab();
133 | }
134 |
135 |
136 | @Override
137 | public void onSpringCompleteListener(View view) {
138 | if(view == fab) {
139 | openSnackbar(view);
140 | }
141 | }
142 |
143 | @Override
144 | public void onBackPressed() {
145 | if(mSheetLayout.isFabExpanded()||fabToolbar.isFabExpanded()){
146 | if(mSheetLayout.isFabExpanded()){
147 | mSheetLayout.contractFab();
148 | }
149 | if(fabToolbar.isFabExpanded()){
150 | contractFabToolbar();
151 | }
152 | }
153 | else{
154 | super.onBackPressed();
155 | }
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/java/com/appnirman/viewclickanimation/SheetLayoutCustom.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.annotation.TargetApi;
6 | import android.content.Context;
7 | import android.content.res.Resources;
8 | import android.content.res.TypedArray;
9 | import android.os.Build;
10 | import android.support.annotation.IntDef;
11 | import android.support.annotation.NonNull;
12 | import android.support.v4.view.ViewCompat;
13 | import android.util.AttributeSet;
14 | import android.util.DisplayMetrics;
15 | import android.util.TypedValue;
16 | import android.view.Gravity;
17 | import android.view.View;
18 | import android.view.ViewAnimationUtils;
19 | import android.view.ViewGroup;
20 | import android.widget.FrameLayout;
21 | import android.widget.LinearLayout;
22 |
23 | import io.codetail.animation.SupportAnimator;
24 |
25 | public class SheetLayoutCustom extends FrameLayout {
26 |
27 | private static final int DEFAULT_ANIMATION_DURATION = 350;
28 | private static final int DEFAULT_FAB_SIZE = 56;
29 |
30 | private static final int FAB_CIRCLE = 0;
31 | private static final int FAB_EXPAND = 1;
32 |
33 | @IntDef({FAB_CIRCLE, FAB_EXPAND})
34 | private @interface Fab {
35 | }
36 |
37 | private LinearLayout mFabExpandLayout;
38 | private View mFab;
39 |
40 | int mFabType = FAB_CIRCLE;
41 | boolean mAnimatingFab = false;
42 | private int animationDuration;
43 | private int mFabSize;
44 |
45 | OnFabAnimationEndListener mListener;
46 |
47 | public SheetLayoutCustom(Context context) {
48 | super(context);
49 | init();
50 | }
51 |
52 | public SheetLayoutCustom(Context context, AttributeSet attrs) {
53 | super(context, attrs);
54 | init();
55 | loadAttributes(context, attrs);
56 | }
57 |
58 | public SheetLayoutCustom(Context context, AttributeSet attrs, int defStyle) {
59 | super(context, attrs, defStyle);
60 | init();
61 | loadAttributes(context, attrs);
62 | }
63 |
64 | private void init() {
65 | inflate(getContext(), R.layout.bottom_sheet_layout, this);
66 | mFabExpandLayout = ((LinearLayout) findViewById(R.id.ft_container));
67 | }
68 |
69 | private void loadAttributes(Context context, AttributeSet attrs) {
70 | TypedValue outValue = new TypedValue();
71 | Resources.Theme theme = context.getTheme();
72 |
73 | // use ?attr/colorPrimary as background color
74 | theme.resolveAttribute(R.attr.colorPrimary, outValue, true);
75 |
76 | TypedArray a = getContext().getTheme().obtainStyledAttributes(
77 | attrs,
78 | R.styleable.FooterLayout,
79 | 0, 0);
80 |
81 | int containerGravity;
82 | try {
83 | setColor(a.getColor(R.styleable.FooterLayout_ft_color,
84 | outValue.data));
85 | animationDuration = a.getInteger(R.styleable.FooterLayout_ft_anim_duration,
86 | DEFAULT_ANIMATION_DURATION);
87 | containerGravity = a.getInteger(R.styleable.FooterLayout_ft_container_gravity, 1);
88 | mFabSize = a.getInteger(R.styleable.FooterLayout_ft_fab_type, DEFAULT_FAB_SIZE);
89 | } finally {
90 | a.recycle();
91 | }
92 |
93 | mFabExpandLayout.setGravity(getGravity(containerGravity));
94 | }
95 |
96 | public void setFab(View view) {
97 | mFab = view;
98 | }
99 |
100 | private int getGravity(int gravityEnum) {
101 | return (gravityEnum == 0 ? Gravity.START
102 | : gravityEnum == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.END)
103 | | Gravity.CENTER_VERTICAL;
104 | }
105 |
106 | public void setColor(int color) {
107 | mFabExpandLayout.setBackgroundColor(color);
108 | }
109 |
110 | @Override
111 | public void addView(@NonNull View child) {
112 | if (canAddViewToContainer()) {
113 | mFabExpandLayout.addView(child);
114 | } else {
115 | super.addView(child);
116 | }
117 | }
118 |
119 | @Override
120 | public void addView(@NonNull View child, int width, int height) {
121 | if (canAddViewToContainer()) {
122 | mFabExpandLayout.addView(child, width, height);
123 | } else {
124 | super.addView(child, width, height);
125 | }
126 | }
127 |
128 | @Override
129 | public void addView(@NonNull View child, ViewGroup.LayoutParams params) {
130 | if (canAddViewToContainer()) {
131 | mFabExpandLayout.addView(child, params);
132 | } else {
133 | super.addView(child, params);
134 | }
135 | }
136 |
137 | @Override
138 | public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
139 | if (canAddViewToContainer()) {
140 | mFabExpandLayout.addView(child, index, params);
141 | } else {
142 | super.addView(child, index, params);
143 | }
144 | }
145 |
146 | /**
147 | * hide() and show() methods are useful for remembering the toolbar state on screen rotation.
148 | */
149 | public void hide() {
150 | mFabExpandLayout.setVisibility(View.INVISIBLE);
151 | mFabType = FAB_CIRCLE;
152 | }
153 |
154 | public void show() {
155 | mFabExpandLayout.setVisibility(View.VISIBLE);
156 | mFabType = FAB_EXPAND;
157 | }
158 |
159 | private boolean canAddViewToContainer() {
160 | return mFabExpandLayout != null;
161 | }
162 |
163 | public void expandFab() {
164 | mFabType = FAB_EXPAND;
165 | mAnimatingFab = true;
166 |
167 | // Center point on the screen of the FAB.
168 | int x = (int) (centerX(mFab));
169 | int y = (int) (centerY(mFab));
170 |
171 | // Start and end radius of the sheet expand animation.
172 | float startRadius = getFabSizePx() / 2;
173 | float endRadius = calculateStartRadius(x, y);
174 |
175 | mFabExpandLayout.setAlpha(0f);
176 | mFabExpandLayout.setVisibility(View.VISIBLE);
177 |
178 | mFab.setVisibility(View.INVISIBLE);
179 | mFab.setTranslationX(0f);
180 | mFab.setTranslationY(0f);
181 |
182 | mFab.setAlpha(1f);
183 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
184 | expandPreLollipop(x, y, startRadius, endRadius);
185 | } else {
186 | expandLollipop(x, y, startRadius, endRadius);
187 | }
188 | }
189 |
190 | public void contractFab() {
191 | if (!isFabExpanded()) {
192 | return;
193 | }
194 |
195 | mFabType = FAB_CIRCLE;
196 | mAnimatingFab = true;
197 |
198 | mFab.setAlpha(0f);
199 | mFab.setVisibility(View.VISIBLE);
200 |
201 | // Center point on the screen of the FAB.
202 | int x = (int) (centerX(mFab));
203 | int y = (int) (centerY(mFab));
204 |
205 | // Start and end radius of the toolbar contract animation.
206 | float endRadius = getFabSizePx() / 2;
207 | float startRadius = calculateStartRadius(x, y);
208 |
209 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
210 | contractPreLollipop(x, y, startRadius, endRadius);
211 | } else {
212 | contractLollipop(x, y, startRadius, endRadius);
213 | }
214 | }
215 |
216 | public boolean isFabExpanded() {
217 | return mFabType == FAB_EXPAND;
218 | }
219 |
220 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
221 | private void expandLollipop(int x, int y, float startRadius, float endRadius) {
222 |
223 | Animator toolbarExpandAnim = ViewAnimationUtils.createCircularReveal(
224 | mFabExpandLayout, x, y, startRadius, endRadius);
225 | toolbarExpandAnim.setDuration(animationDuration);
226 | toolbarExpandAnim.addListener(new AnimatorListenerAdapter() {
227 | @Override
228 | public void onAnimationStart(Animator animation) {
229 | super.onAnimationStart(animation);
230 | mFabExpandLayout.setAlpha(1f);
231 | }
232 |
233 | @Override
234 | public void onAnimationEnd(Animator animation) {
235 | super.onAnimationEnd(animation);
236 | expandAnimationEnd();
237 |
238 | }
239 | });
240 |
241 | toolbarExpandAnim.start();
242 | }
243 |
244 | private void expandPreLollipop(int x, int y, float startRadius, float endRadius) {
245 |
246 | SupportAnimator toolbarExpandAnim = io.codetail.animation.ViewAnimationUtils
247 | .createCircularReveal(
248 | mFabExpandLayout, x, y, startRadius, endRadius);
249 | toolbarExpandAnim.setDuration(animationDuration);
250 | toolbarExpandAnim.addListener(new SupportAnimator.AnimatorListener() {
251 | @Override
252 | public void onAnimationStart() {
253 | mFabExpandLayout.setAlpha(1f);
254 | }
255 |
256 | @Override
257 | public void onAnimationEnd() {
258 | //mFab.setAlpha(1f);
259 | expandAnimationEnd();
260 |
261 | }
262 |
263 | @Override
264 | public void onAnimationCancel() {
265 |
266 | }
267 |
268 | @Override
269 | public void onAnimationRepeat() {
270 |
271 | }
272 | });
273 |
274 | toolbarExpandAnim.start();
275 | }
276 |
277 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
278 | private void contractLollipop(int x, int y, float startRadius, float endRadius) {
279 |
280 | Animator toolbarContractAnim = ViewAnimationUtils.createCircularReveal(
281 | mFabExpandLayout, x, y, startRadius, endRadius);
282 | toolbarContractAnim.setDuration(animationDuration);
283 |
284 | toolbarContractAnim.addListener(new AnimatorListenerAdapter() {
285 | @Override
286 | public void onAnimationEnd(Animator animation) {
287 | super.onAnimationEnd(animation);
288 | contractAnimationEnd();
289 | }
290 | });
291 |
292 | toolbarContractAnim.start();
293 | }
294 |
295 | private void contractPreLollipop(int x, int y, float startRadius, float endRadius) {
296 |
297 | final SupportAnimator toolbarContractAnim = io.codetail.animation.ViewAnimationUtils
298 | .createCircularReveal(mFabExpandLayout, x, y, startRadius, endRadius);
299 | toolbarContractAnim.setDuration(animationDuration);
300 |
301 | toolbarContractAnim.addListener(new SupportAnimator.AnimatorListener() {
302 | @Override
303 | public void onAnimationStart() {
304 |
305 | }
306 |
307 | @Override
308 | public void onAnimationEnd() {
309 | contractAnimationEnd();
310 | }
311 |
312 | @Override
313 | public void onAnimationCancel() {
314 |
315 | }
316 |
317 | @Override
318 | public void onAnimationRepeat() {
319 |
320 | }
321 | });
322 |
323 | toolbarContractAnim.start();
324 | }
325 |
326 | private void expandAnimationEnd(){
327 | mAnimatingFab = false;
328 | if (mListener != null)
329 | mListener.onFabAnimationEnd();
330 | }
331 |
332 | private void contractAnimationEnd(){
333 | mFab.setAlpha(1f);
334 | mFabExpandLayout.setAlpha(0f);
335 |
336 | mAnimatingFab = false;
337 | mFabExpandLayout.setVisibility(View.INVISIBLE);
338 | mFabExpandLayout.setAlpha(1f);
339 | }
340 |
341 | private float calculateStartRadius(int x, int y){
342 | return (float) Math.hypot(
343 | Math.max(x, mFabExpandLayout.getWidth() - x),
344 | Math.max(y, mFabExpandLayout.getHeight() - y));
345 | }
346 |
347 | private int getFabSizePx() {
348 | DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
349 | return Math.round(mFabSize * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
350 | }
351 |
352 | private float centerX(View view) {
353 | if (view != null) {
354 | return ViewCompat.getX(view) + view.getWidth() / 2f;
355 | } else {
356 | return 0f;
357 | }
358 | }
359 |
360 | private float centerY(View view) {
361 | if (view != null) {
362 | return ViewCompat.getY(view) + view.getHeight() / 2f;
363 | } else {
364 | return 0f;
365 | }
366 | }
367 |
368 | public interface OnFabAnimationEndListener {
369 | void onFabAnimationEnd();
370 | }
371 |
372 | public void setFabAnimationEndListener(OnFabAnimationEndListener eventListener) {
373 | mListener = eventListener;
374 | }
375 | }
376 |
--------------------------------------------------------------------------------
/viewclickanimation/src/main/java/com/appnirman/viewclickanimation/FooterLayout.java:
--------------------------------------------------------------------------------
1 | package com.appnirman.viewclickanimation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.AnimatorSet;
6 | import android.animation.ObjectAnimator;
7 | import android.animation.PropertyValuesHolder;
8 | import android.animation.ValueAnimator;
9 | import android.annotation.TargetApi;
10 | import android.content.Context;
11 | import android.content.res.Resources;
12 | import android.content.res.TypedArray;
13 | import android.graphics.Color;
14 | import android.os.Build;
15 | import android.support.annotation.IntDef;
16 | import android.support.annotation.NonNull;
17 | import android.support.design.widget.CoordinatorLayout;
18 | import android.support.v4.view.animation.FastOutLinearInInterpolator;
19 | import android.util.AttributeSet;
20 | import android.util.DisplayMetrics;
21 | import android.util.TypedValue;
22 | import android.view.Gravity;
23 | import android.view.MotionEvent;
24 | import android.view.View;
25 | import android.view.ViewAnimationUtils;
26 | import android.view.ViewGroup;
27 | import android.view.animation.AccelerateInterpolator;
28 | import android.view.animation.DecelerateInterpolator;
29 | import android.widget.FrameLayout;
30 | import android.widget.ImageView;
31 | import android.widget.LinearLayout;
32 | import io.codetail.animation.SupportAnimator;
33 |
34 |
35 | @CoordinatorLayout.DefaultBehavior(FooterBehavior.class)
36 | public class FooterLayout extends FrameLayout {
37 |
38 | private static final int DEFAULT_ANIMATION_DURATION = 400;
39 | private static final int DEFAULT_FAB_SIZE = 56;
40 | private int mBackgroundColor;
41 | private ValueAnimator mShowBackgroundAnimator;
42 | private ValueAnimator mHideBackgroundAnimator;
43 | private boolean mIsSetClosedOnTouchOutside;
44 |
45 | @IntDef({ FAB_CIRCLE, FAB_EXPAND }) private @interface Fab {
46 |
47 | }
48 |
49 | private static final int FAB_CIRCLE = 0;
50 | private static final int FAB_EXPAND = 1;
51 |
52 | int mFabType = FAB_CIRCLE;
53 | boolean mAnimatingFab = false;
54 |
55 | private LinearLayout mFabExpandLayout;
56 | private View mFab;
57 |
58 | private int animationDuration;
59 | private int mFabSize;
60 |
61 | public FooterLayout(Context context) {
62 | super(context);
63 | init();
64 | }
65 |
66 | public FooterLayout(Context context, AttributeSet attrs) {
67 | super(context, attrs);
68 | init();
69 | loadAttributes(context, attrs);
70 | }
71 |
72 | public FooterLayout(Context context, AttributeSet attrs, int defStyle) {
73 | super(context, attrs, defStyle);
74 | init();
75 | loadAttributes(context, attrs);
76 | }
77 |
78 | private void init() {
79 | inflate(getContext(), R.layout.footer_layout, this);
80 | mFabExpandLayout = ((LinearLayout) findViewById(R.id.container));
81 | }
82 |
83 | private void loadAttributes(Context context, AttributeSet attrs) {
84 | TypedValue outValue = new TypedValue();
85 | Resources.Theme theme = context.getTheme();
86 |
87 | // use ?attr/colorPrimary as background color
88 | theme.resolveAttribute(R.attr.colorPrimary, outValue, true);
89 |
90 | TypedArray a =
91 | getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.FooterLayout, 0, 0);
92 |
93 | int containerGravity;
94 | try {
95 | setColor(a.getColor(R.styleable.FooterLayout_ft_color, outValue.data));
96 | animationDuration =
97 | a.getInteger(R.styleable.FooterLayout_ft_anim_duration, DEFAULT_ANIMATION_DURATION);
98 | containerGravity = a.getInteger(R.styleable.FooterLayout_ft_container_gravity, 1);
99 | mFabSize = a.getInteger(R.styleable.FooterLayout_ft_fab_type, DEFAULT_FAB_SIZE);
100 | mBackgroundColor = a.getColor(R.styleable.FooterLayout_ft_menu_backgroundColor, Color.TRANSPARENT);
101 |
102 | initBackgroundDimAnimation();
103 | } finally {
104 | a.recycle();
105 | }
106 |
107 | mFabExpandLayout.setGravity(getGravity(containerGravity));
108 | }
109 |
110 | private void initBackgroundDimAnimation() {
111 | final int maxAlpha = Color.alpha(mBackgroundColor);
112 | final int red = Color.red(mBackgroundColor);
113 | final int green = Color.green(mBackgroundColor);
114 | final int blue = Color.blue(mBackgroundColor);
115 |
116 | mShowBackgroundAnimator = ValueAnimator.ofInt(0, maxAlpha);
117 | mShowBackgroundAnimator.setDuration(DEFAULT_ANIMATION_DURATION);
118 | mShowBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
119 | @Override
120 | public void onAnimationUpdate(ValueAnimator animation) {
121 | Integer alpha = (Integer) animation.getAnimatedValue();
122 | setBackgroundColor(Color.argb(alpha, red, green, blue));
123 | }
124 | });
125 |
126 | mHideBackgroundAnimator = ValueAnimator.ofInt(maxAlpha, 0);
127 | mHideBackgroundAnimator.setDuration(DEFAULT_ANIMATION_DURATION);
128 | mHideBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
129 | @Override
130 | public void onAnimationUpdate(ValueAnimator animation) {
131 | Integer alpha = (Integer) animation.getAnimatedValue();
132 | setBackgroundColor(Color.argb(alpha, red, green, blue));
133 | }
134 | });
135 | }
136 |
137 | public void setFab(ImageView imageView) {
138 | mFab = imageView;
139 | }
140 |
141 | private int getGravity(int gravityEnum) {
142 | return (gravityEnum == 0 ? Gravity.START
143 | : gravityEnum == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.END) | Gravity.CENTER_VERTICAL;
144 | }
145 |
146 | public void setColor(int color) {
147 | mFabExpandLayout.setBackgroundColor(color);
148 | }
149 |
150 | @Override public void addView(@NonNull View child) {
151 | if (canAddViewToContainer()) {
152 | mFabExpandLayout.addView(child);
153 | } else {
154 | super.addView(child);
155 | }
156 | }
157 |
158 | @Override public void addView(@NonNull View child, int width, int height) {
159 | if (canAddViewToContainer()) {
160 | mFabExpandLayout.addView(child, width, height);
161 | } else {
162 | super.addView(child, width, height);
163 | }
164 | }
165 |
166 | @Override public void addView(@NonNull View child, ViewGroup.LayoutParams params) {
167 | if (canAddViewToContainer()) {
168 | mFabExpandLayout.addView(child, params);
169 | } else {
170 | super.addView(child, params);
171 | }
172 | }
173 |
174 | @Override public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
175 | if (canAddViewToContainer()) {
176 | mFabExpandLayout.addView(child, index, params);
177 | } else {
178 | super.addView(child, index, params);
179 | }
180 | }
181 |
182 | /**
183 | * hide() and show() methods are useful for remembering the toolbar state on screen rotation.
184 | */
185 |
186 | private boolean isBackgroundEnabled() {
187 | return mBackgroundColor != Color.TRANSPARENT;
188 | }
189 |
190 | public void hide() {
191 | mFabExpandLayout.setVisibility(View.INVISIBLE);
192 | mFabType = FAB_CIRCLE;
193 | }
194 |
195 | public void show() {
196 | mFabExpandLayout.setVisibility(View.VISIBLE);
197 | mFabType = FAB_EXPAND;
198 | }
199 |
200 | private boolean canAddViewToContainer() {
201 | return mFabExpandLayout != null;
202 | }
203 |
204 | public void slideInFab() {
205 | if (mAnimatingFab) {
206 | return;
207 | }
208 |
209 | if (isFabExpanded()) {
210 | contractFab();
211 | return;
212 | }
213 |
214 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
215 | float dy = mFab.getHeight() + lp.bottomMargin;
216 | if (mFab.getTranslationY() != dy) {
217 | return;
218 | }
219 |
220 | mAnimatingFab = true;
221 | mFab.setVisibility(View.VISIBLE);
222 | mFab.animate()
223 | .setStartDelay(0)
224 | .setDuration(200)
225 | .setInterpolator(new FastOutLinearInInterpolator())
226 | .translationY(0f)
227 | .setListener(new AnimatorListenerAdapter() {
228 | @Override public void onAnimationEnd(final Animator animation) {
229 | super.onAnimationEnd(animation);
230 | mAnimatingFab = false;
231 | }
232 | })
233 | .start();
234 | }
235 |
236 | public void slideOutFab() {
237 | if (mAnimatingFab) {
238 | return;
239 | }
240 |
241 | if (isFabExpanded()) {
242 | contractFab();
243 | return;
244 | }
245 |
246 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
247 | if (mFab.getTranslationY() != 0f) {
248 | return;
249 | }
250 |
251 | mAnimatingFab = true;
252 | mFab.animate()
253 | .setStartDelay(0)
254 | .setDuration(200)
255 | .setInterpolator(new FastOutLinearInInterpolator())
256 | .translationY(mFab.getHeight() + lp.bottomMargin)
257 | .setListener(new AnimatorListenerAdapter() {
258 | @Override public void onAnimationEnd(final Animator animation) {
259 | super.onAnimationEnd(animation);
260 | mAnimatingFab = false;
261 | mFab.setVisibility(View.INVISIBLE);
262 | }
263 | })
264 | .start();
265 | }
266 |
267 | public void expandFab() {
268 | mFabType = FAB_EXPAND;
269 | if (isBackgroundEnabled()) {
270 | mShowBackgroundAnimator.start();
271 | }
272 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
273 | expandPreLollipop();
274 | } else {
275 | expandLollipop();
276 | }
277 | }
278 |
279 | public void setClosedOnTouchOutside(boolean close) {
280 | mIsSetClosedOnTouchOutside = close;
281 | }
282 |
283 | @Override
284 | public boolean onTouchEvent(MotionEvent event) {
285 | if (mIsSetClosedOnTouchOutside) {
286 | boolean handled = false;
287 | switch (event.getAction()) {
288 | case MotionEvent.ACTION_DOWN:
289 | handled = isFabExpanded();
290 | break;
291 | case MotionEvent.ACTION_UP:
292 | contractFab();
293 | handled = true;
294 | }
295 |
296 | return handled;
297 | }
298 |
299 | return super.onTouchEvent(event);
300 | }
301 |
302 | public void contractFab() {
303 | if (!isFabExpanded()) {
304 | return;
305 | }
306 | if (isBackgroundEnabled()) {
307 | mHideBackgroundAnimator.start();
308 | }
309 |
310 | mFabType = FAB_CIRCLE;
311 |
312 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
313 | contractPreLollipop();
314 | } else {
315 | contractLollipop();
316 | }
317 | }
318 |
319 | public boolean isFabExpanded() {
320 | return mFabType == FAB_EXPAND;
321 | }
322 |
323 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void expandLollipop() {
324 | mAnimatingFab = true;
325 |
326 | // Translation vector for the FAB. Basically move it just below the toolbar.
327 | float dx = ViewUtils.centerX(mFabExpandLayout) + getFabSizePx() - ViewUtils.centerX(mFab);
328 | float dy = ViewUtils.getRelativeTop(mFabExpandLayout)
329 | - ViewUtils.getRelativeTop(mFab)
330 | - (mFab.getHeight() - getFabSizePx()) / 2;
331 |
332 | // Center point on the screen of the FAB after translation. Used as the start point
333 | // for the expansion animation of the toolbar.
334 | int x = (int) (ViewUtils.centerX(mFab) + dx);
335 | int y = (mFabExpandLayout.getBottom() - mFabExpandLayout.getTop()) / 2;
336 |
337 | // Start and end radii of the toolbar expand animation.
338 | float startRadius = getFabSizePx() / 2;
339 | float endRadius = (float) Math.hypot(Math.max(x, mFabExpandLayout.getWidth() - x),
340 | Math.max(y, mFabExpandLayout.getHeight() - y));
341 |
342 | mFabExpandLayout.setAlpha(0f);
343 | mFabExpandLayout.setVisibility(View.VISIBLE);
344 |
345 | Animator fabSlideXAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
346 | PropertyValuesHolder.ofFloat(View.TRANSLATION_X, 0f, dx));
347 | fabSlideXAnim.setDuration(animationDuration / 2);
348 |
349 | Animator fabSlideYAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
350 | PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f, dy));
351 | fabSlideYAnim.setDuration(animationDuration / 2);
352 |
353 | Animator toolbarExpandAnim =
354 | ViewAnimationUtils.createCircularReveal(mFabExpandLayout, x, y, startRadius, endRadius);
355 | toolbarExpandAnim.setStartDelay(animationDuration / 2);
356 | toolbarExpandAnim.setDuration(animationDuration / 2);
357 |
358 | // Play All animations together. Interpolators must be added after playTogether()
359 | // or the won't be used.
360 | AnimatorSet animSet = new AnimatorSet();
361 | animSet.playTogether(fabSlideXAnim, fabSlideYAnim, toolbarExpandAnim);
362 | fabSlideXAnim.setInterpolator(new AccelerateInterpolator(1.0f));
363 | fabSlideYAnim.setInterpolator(new DecelerateInterpolator(0.8f));
364 |
365 | fabSlideYAnim.addListener(new AnimatorListenerAdapter() {
366 | @Override public void onAnimationEnd(Animator animation) {
367 | super.onAnimationEnd(animation);
368 | mFab.setVisibility(View.INVISIBLE);
369 | mFab.setTranslationX(0f);
370 | mFab.setTranslationY(0f);
371 | mFab.setAlpha(1f);
372 | }
373 | });
374 |
375 | toolbarExpandAnim.addListener(new AnimatorListenerAdapter() {
376 | @Override public void onAnimationStart(Animator animation) {
377 | super.onAnimationStart(animation);
378 | mFabExpandLayout.setAlpha(1f);
379 | }
380 |
381 | @Override public void onAnimationEnd(Animator animation) {
382 | super.onAnimationEnd(animation);
383 | mAnimatingFab = false;
384 | }
385 | });
386 |
387 | animSet.start();
388 | }
389 |
390 | private void expandPreLollipop() {
391 | mAnimatingFab = true;
392 |
393 | // Translation vector for the FAB. Basically move it just below the toolbar.
394 | float dx = ViewUtils.centerX(mFabExpandLayout) + getFabSizePx() - ViewUtils.centerX(mFab);
395 | float dy = ViewUtils.getRelativeTop(mFabExpandLayout)
396 | - ViewUtils.getRelativeTop(mFab)
397 | - (mFab.getHeight() - getFabSizePx()) / 2;
398 |
399 | // Center point on the screen of the FAB after translation. Used as the start point
400 | // for the expansion animation of the toolbar.
401 | int x = (int) (ViewUtils.centerX(mFab) + dx);
402 | int y = (mFabExpandLayout.getBottom() - mFabExpandLayout.getTop()) / 2;
403 |
404 | // Start and end radii of the toolbar expand animation.
405 | float startRadius = getFabSizePx() / 2;
406 | float endRadius = (float) Math.hypot(Math.max(x, mFabExpandLayout.getWidth() - x),
407 | Math.max(y, mFabExpandLayout.getHeight() - y));
408 |
409 | mFabExpandLayout.setAlpha(0f);
410 | mFabExpandLayout.setVisibility(View.VISIBLE);
411 |
412 | Animator fabSlideXAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
413 | PropertyValuesHolder.ofFloat(View.TRANSLATION_X, 0f, dx));
414 | fabSlideXAnim.setDuration(animationDuration / 2);
415 |
416 | Animator fabSlideYAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
417 | PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f, dy));
418 | fabSlideYAnim.setDuration(animationDuration / 2);
419 |
420 | final SupportAnimator toolbarExpandAnim =
421 | io.codetail.animation.ViewAnimationUtils.createCircularReveal(mFabExpandLayout, x, y,
422 | startRadius, endRadius);
423 | toolbarExpandAnim.setDuration(animationDuration / 2);
424 |
425 | // Play slide animations together. Interpolators must be added after playTogether()
426 | // or the won't be used.
427 | AnimatorSet animSet = new AnimatorSet();
428 | animSet.playTogether(fabSlideXAnim, fabSlideYAnim);
429 | fabSlideXAnim.setInterpolator(new AccelerateInterpolator(1.0f));
430 | fabSlideYAnim.setInterpolator(new DecelerateInterpolator(0.8f));
431 |
432 | fabSlideYAnim.addListener(new AnimatorListenerAdapter() {
433 | @Override public void onAnimationEnd(Animator animation) {
434 | super.onAnimationEnd(animation);
435 | mFab.setAlpha(0f);
436 | mFab.setVisibility(View.INVISIBLE);
437 | mFab.setTranslationX(0f);
438 | mFab.setTranslationY(0f);
439 |
440 | // Play toolbar expand animation after slide animations finish.
441 | toolbarExpandAnim.start();
442 | }
443 | });
444 |
445 | toolbarExpandAnim.addListener(new SupportAnimator.AnimatorListener() {
446 | @Override public void onAnimationStart() {
447 | mFabExpandLayout.setAlpha(1f);
448 | }
449 |
450 | @Override public void onAnimationEnd() {
451 | mFab.setAlpha(1f);
452 | mAnimatingFab = false;
453 | }
454 |
455 | @Override public void onAnimationCancel() {
456 |
457 | }
458 |
459 | @Override public void onAnimationRepeat() {
460 |
461 | }
462 | });
463 |
464 | animSet.start();
465 | }
466 |
467 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void contractLollipop() {
468 | mAnimatingFab = true;
469 |
470 | // Translation vector for the FAB. Basically move it just below the toolbar.
471 | float dx = ViewUtils.centerX(mFabExpandLayout) + getFabSizePx() - ViewUtils.centerX(mFab);
472 | float dy = ViewUtils.getRelativeTop(mFabExpandLayout)
473 | - ViewUtils.getRelativeTop(mFab)
474 | - (mFab.getHeight() - getFabSizePx()) / 2;
475 |
476 | mFab.setAlpha(0f);
477 | mFab.setTranslationX(dx);
478 | mFab.setTranslationY(dy);
479 | mFab.setVisibility(View.VISIBLE);
480 |
481 | // Center point on the screen of the FAB before translation. Used as the start point
482 | // for the expansion animation of the toolbar.
483 | int x = (int) (ViewUtils.centerX(mFab));
484 | int y = (mFabExpandLayout.getBottom() - mFabExpandLayout.getTop()) / 2;
485 |
486 | // Start and end radii of the toolbar contract animation.
487 | float endRadius = getFabSizePx() / 2;
488 | float startRadius = (float) Math.hypot(Math.max(x, mFabExpandLayout.getWidth() - x),
489 | Math.max(y, mFabExpandLayout.getHeight() - y));
490 |
491 | Animator fabSlideXAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
492 | PropertyValuesHolder.ofFloat(View.TRANSLATION_X, dx, 0f));
493 | fabSlideXAnim.setStartDelay(animationDuration / 2);
494 | fabSlideXAnim.setDuration(animationDuration / 2);
495 |
496 | Animator fabSlideYAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
497 | PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, dy, 0f));
498 | fabSlideYAnim.setStartDelay(animationDuration / 2);
499 | fabSlideYAnim.setDuration(animationDuration / 2);
500 |
501 | Animator toolbarContractAnim =
502 | ViewAnimationUtils.createCircularReveal(mFabExpandLayout, x, y, startRadius, endRadius);
503 | toolbarContractAnim.setDuration(animationDuration / 2);
504 |
505 | // Play All animations together. Interpolators must be added after playTogether()
506 | // or the won't be used.
507 | AnimatorSet animSet = new AnimatorSet();
508 | animSet.playTogether(toolbarContractAnim, fabSlideXAnim, fabSlideYAnim);
509 | fabSlideXAnim.setInterpolator(new DecelerateInterpolator(0.8f));
510 | fabSlideYAnim.setInterpolator(new AccelerateInterpolator(1.0f));
511 |
512 | toolbarContractAnim.addListener(new AnimatorListenerAdapter() {
513 | @Override public void onAnimationEnd(Animator animation) {
514 | super.onAnimationEnd(animation);
515 | mFab.setAlpha(1f);
516 | mFabExpandLayout.setAlpha(0f);
517 | }
518 | });
519 |
520 | fabSlideYAnim.addListener(new AnimatorListenerAdapter() {
521 | @Override public void onAnimationEnd(Animator animation) {
522 | super.onAnimationEnd(animation);
523 | mFabExpandLayout.setVisibility(View.INVISIBLE);
524 | mFabExpandLayout.setAlpha(1f);
525 | mAnimatingFab = false;
526 | }
527 | });
528 |
529 | animSet.start();
530 | }
531 |
532 | private void contractPreLollipop() {
533 | mAnimatingFab = true;
534 |
535 | // Translation vector for the FAB. Basically move it just below the toolbar.
536 | float dx = ViewUtils.centerX(mFabExpandLayout) + getFabSizePx() - ViewUtils.centerX(mFab);
537 | float dy = ViewUtils.getRelativeTop(mFabExpandLayout)
538 | - ViewUtils.getRelativeTop(mFab)
539 | - (mFab.getHeight() - getFabSizePx()) / 2;
540 |
541 | mFab.setAlpha(0f);
542 | mFab.setTranslationX(dx);
543 | mFab.setTranslationY(dy);
544 | mFab.setVisibility(View.VISIBLE);
545 |
546 | // Center point on the screen of the FAB before translation. Used as the start point
547 | // for the expansion animation of the toolbar.
548 | int x = (int) (ViewUtils.centerX(mFab));
549 | int y = (mFabExpandLayout.getBottom() - mFabExpandLayout.getTop()) / 2;
550 |
551 | // Start and end radii of the toolbar contract animation.
552 | float endRadius = getFabSizePx() / 2;
553 | float startRadius = (float) Math.hypot(Math.max(x, mFabExpandLayout.getWidth() - x),
554 | Math.max(y, mFabExpandLayout.getHeight() - y));
555 |
556 | Animator fabSlideXAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
557 | PropertyValuesHolder.ofFloat(View.TRANSLATION_X, dx, 0f));
558 | fabSlideXAnim.setDuration(animationDuration / 2);
559 |
560 | Animator fabSlideYAnim = ObjectAnimator.ofPropertyValuesHolder(mFab,
561 | PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, dy, 0f));
562 | fabSlideYAnim.setDuration(animationDuration / 2);
563 |
564 | final SupportAnimator toolbarContractAnim =
565 | io.codetail.animation.ViewAnimationUtils.createCircularReveal(mFabExpandLayout, x, y,
566 | startRadius, endRadius);
567 | toolbarContractAnim.setDuration(animationDuration / 2);
568 |
569 | // Play slide animations together. Interpolators must be added after playTogether()
570 | // or the won't be used.
571 | final AnimatorSet animSet = new AnimatorSet();
572 | animSet.playTogether(fabSlideXAnim, fabSlideYAnim);
573 | fabSlideXAnim.setInterpolator(new DecelerateInterpolator(0.8f));
574 | fabSlideYAnim.setInterpolator(new AccelerateInterpolator(1.0f));
575 |
576 | toolbarContractAnim.addListener(new SupportAnimator.AnimatorListener() {
577 | @Override public void onAnimationStart() {
578 |
579 | }
580 |
581 | @Override public void onAnimationEnd() {
582 | mFab.setAlpha(1f);
583 | mFabExpandLayout.setAlpha(0f);
584 |
585 | // Play fab animation after contract animation finishes.
586 | animSet.start();
587 | }
588 |
589 | @Override public void onAnimationCancel() {
590 |
591 | }
592 |
593 | @Override public void onAnimationRepeat() {
594 |
595 | }
596 | });
597 |
598 | fabSlideYAnim.addListener(new AnimatorListenerAdapter() {
599 | @Override public void onAnimationEnd(Animator animation) {
600 | super.onAnimationEnd(animation);
601 | mFabExpandLayout.setVisibility(View.INVISIBLE);
602 | mFabExpandLayout.setAlpha(1f);
603 | mAnimatingFab = false;
604 | }
605 | });
606 |
607 | toolbarContractAnim.start();
608 | }
609 |
610 | private int getFabSizePx() {
611 | DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
612 | return Math.round(mFabSize * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
613 | }
614 | }
615 |
--------------------------------------------------------------------------------