├── settings.gradle
├── .gitignore
├── example
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── 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
│ │ ├── drawable-hdpi
│ │ │ └── ic_add_white_24dp.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_add_white_24dp.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_add_white_24dp.png
│ │ │ ├── ic_home_white_24dp.png
│ │ │ ├── ic_file_download_white_24dp.png
│ │ │ └── ic_open_in_browser_white_24dp.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_add_white_24dp.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── fragment_line_menu.xml
│ │ │ └── fragment_circle_menu.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── terranovaproductions
│ │ └── newcomicreader
│ │ └── sample
│ │ ├── DemoLineMenuFragment.java
│ │ ├── FragmentAdapter.java
│ │ ├── MainActivity.java
│ │ └── DemoCircleMenuFragment.java
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── library
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── drawable
│ │ │ └── rounded_corners.xml
│ │ └── java
│ │ └── com
│ │ └── novaapps
│ │ └── floatingactionmenu
│ │ └── FloatingActionMenu.java
├── proguard-rules.pro
└── build.gradle
├── gradle.properties
├── LICENSE.md
├── README.md
├── gradlew.bat
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':library'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/*
5 | .DS_Store
6 | **/build/*
7 | /captures
8 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FloatingActionMenu
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-hdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-hdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-mdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-mdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-xhdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_home_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-xhdpi/ic_home_white_24dp.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_file_download_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-xhdpi/ic_file_download_white_24dp.png
--------------------------------------------------------------------------------
/example/src/main/res/drawable-xhdpi/ic_open_in_browser_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TristanWiley/FloatingActionMenu/HEAD/example/src/main/res/drawable-xhdpi/ic_open_in_browser_white_24dp.png
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Apr 19 19:32:29 EDT 2016
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 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FF9800
7 |
8 |
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/rounded_corners.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/example/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 /home/avinash/Public/Softwares/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 |
--------------------------------------------------------------------------------
/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 /home/avinash/Public/Softwares/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 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.novaapps.floatingactionmenu"
9 | minSdkVersion 14
10 | targetSdkVersion 23
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 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.0'
26 | compile project(':library')
27 | }
28 |
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/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
19 |
--------------------------------------------------------------------------------
/example/src/main/java/terranovaproductions/newcomicreader/sample/DemoLineMenuFragment.java:
--------------------------------------------------------------------------------
1 | package terranovaproductions.newcomicreader.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.novaapps.floatingactionmenu.FloatingActionMenu;
11 |
12 | /**
13 | * Created by renqinghe on 15-11-4.
14 | */
15 | public class DemoLineMenuFragment extends Fragment {
16 | @Nullable
17 | @Override
18 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
19 | View v = inflater.inflate(R.layout.fragment_line_menu, container, false);
20 | FloatingActionMenu menu = (FloatingActionMenu) v.findViewById(R.id.fab_menu_line);
21 | menu.setmItemGap(48);
22 | return v;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | ext {
3 | PUBLISH_GROUP_ID = 'com.novaapps'
4 | PUBLISH_ARTIFACT_ID = 'FloatingActionMenu'
5 | PUBLISH_VERSION = '1.0'
6 | }
7 | android {
8 | compileSdkVersion 23
9 | buildToolsVersion "23.0.1"
10 | lintOptions {
11 | abortOnError false
12 | }
13 | defaultConfig {
14 | minSdkVersion 14
15 | targetSdkVersion 23
16 | versionCode 1
17 | versionName "1.0"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(include: ['*.jar'], dir: 'libs')
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.android.support:appcompat-v7:23.1.0'
31 | compile 'com.android.support:design:23.1.0'
32 | }
33 | apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
34 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Tristan Wiley
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #FloatingActionMenu
2 |
3 | This is a fork from https://github.com/TristanWiley/FloatingActionMenu, I modified it to support both circle and line menu.
4 |
5 | Check the example for usage, the default is a line. A "circle" can be used by doing
6 |
7 | #Usage
8 |
9 | Put the following dependency in Gradle:
10 |
11 | compile 'com.novaapps:FloatingActionMenu:1.0'
12 |
13 | Check the sample for more information, to make the FloatingActionMenu a circle use the below code.
14 | ```java
15 | menu.setIsCircle(true)
16 | ```
17 |
18 | ## Example
19 | 
20 |
21 |
22 | The original code is from douo in this gist- gist.github.com/douo/dfde289778a9b3b6918f
23 |
24 | I modified the code so it looks better, there's spacing between the buttons.
25 |
26 | ##Contributors
27 | [Tristan Wiley](https://github.com/TristanWiley)
28 |
29 | [douo](https://gist.github.com/douo)
30 |
31 | [callmepeanut](https://github.com/callmepeanut)
32 |
33 | [Avinash-Bhat](https://github.com/Avinash-Bhat)
34 |
35 | Also thank you to my friend [tryadelion](https://github.com/tryadelion) for helping me get this on Bintray :).
36 |
--------------------------------------------------------------------------------
/example/src/main/java/terranovaproductions/newcomicreader/sample/FragmentAdapter.java:
--------------------------------------------------------------------------------
1 | package terranovaproductions.newcomicreader.sample;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by renqinghe on 15-11-4.
11 | */
12 | public class FragmentAdapter extends FragmentPagerAdapter {
13 | private List mFragments;
14 | private String tabTitles[];
15 |
16 | public FragmentAdapter(FragmentManager fm, List mFragments) {
17 | super(fm);
18 | this.mFragments = mFragments;
19 | }
20 |
21 | public FragmentAdapter(FragmentManager fm, List mFragments, String[] tabTitles) {
22 | super(fm);
23 | this.mFragments = mFragments;
24 | this.tabTitles = tabTitles;
25 | }
26 |
27 | @Override
28 | public Fragment getItem(int position) {
29 | return mFragments.get(position);
30 | }
31 |
32 | @Override
33 | public int getCount() {
34 | return mFragments.size();
35 | }
36 |
37 | @Override
38 | public CharSequence getPageTitle(int position) {
39 | return tabTitles[position];
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/example/src/main/java/terranovaproductions/newcomicreader/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package terranovaproductions.newcomicreader.sample;
2 |
3 | import android.support.design.widget.TabLayout;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.view.ViewPager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 | private ViewPager mViewPager;
16 | private TabLayout mTabLayout;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | mViewPager = (ViewPager) findViewById(R.id.viewpager);
24 | setupViewPager();
25 |
26 | mTabLayout = (TabLayout) findViewById(R.id.home_tabs);
27 | mTabLayout.setupWithViewPager(mViewPager);
28 | mTabLayout.setTabMode(TabLayout.MODE_FIXED);
29 | }
30 |
31 | private void setupViewPager() {
32 | List fragments = new ArrayList<>();
33 | fragments.add(new DemoCircleMenuFragment());
34 | fragments.add(new DemoLineMenuFragment());
35 | FragmentAdapter adapter =
36 | new FragmentAdapter(getSupportFragmentManager(), fragments, new String[]{"Circle", "Line"});
37 | mViewPager.setAdapter(adapter);
38 | mViewPager.setOnFocusChangeListener(new View.OnFocusChangeListener() {
39 | @Override
40 | public void onFocusChange(View v, boolean hasFocus) {
41 |
42 | }
43 | });
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/example/src/main/java/terranovaproductions/newcomicreader/sample/DemoCircleMenuFragment.java:
--------------------------------------------------------------------------------
1 | package terranovaproductions.newcomicreader.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Toast;
11 |
12 | import com.novaapps.floatingactionmenu.FloatingActionMenu;
13 |
14 | /**
15 | * Created by renqinghe on 15-11-4.
16 | */
17 | public class DemoCircleMenuFragment extends Fragment {
18 | @Nullable
19 | @Override
20 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
21 | View v = inflater.inflate(R.layout.fragment_circle_menu, container, false);
22 | initView(v);
23 | return v;
24 | }
25 |
26 | private void initView(View v) {
27 | FloatingActionMenu menu = (FloatingActionMenu) v.findViewById(R.id.fab_menu_circle);
28 | menu.setMultipleOfFB(3.2f);
29 | menu.setIsCircle(true);
30 |
31 | menu.setOnMenuItemClickListener(new FloatingActionMenu.OnMenuItemClickListener() {
32 | @Override
33 | public void onMenuItemClick(FloatingActionMenu fam, int index, FloatingActionButton item) {
34 | String str = "";
35 | switch (index) {
36 | case 0:
37 | str = "main fab is clicked!";
38 | break;
39 | case 1:
40 | str = "download fab is clicked!";
41 | break;
42 | case 2:
43 | str = "browser fab is clicked!";
44 | break;
45 | default:
46 | }
47 | Toast.makeText(getActivity().getApplicationContext(), str, Toast.LENGTH_SHORT).show();
48 | }
49 | });
50 |
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/fragment_line_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
25 |
26 |
27 |
34 |
35 |
36 |
43 |
44 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/fragment_circle_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
25 |
26 |
27 |
34 |
35 |
36 |
43 |
44 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/src/main/java/com/novaapps/floatingactionmenu/FloatingActionMenu.java:
--------------------------------------------------------------------------------
1 | package com.novaapps.floatingactionmenu;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.animation.TimeInterpolator;
7 | import android.animation.ValueAnimator;
8 | import android.content.Context;
9 | import android.graphics.Color;
10 | import android.graphics.drawable.ColorDrawable;
11 | import android.graphics.drawable.Drawable;
12 | import android.os.Bundle;
13 | import android.os.Parcelable;
14 | import android.support.annotation.NonNull;
15 | import android.support.design.widget.FloatingActionButton;
16 | import android.util.AttributeSet;
17 | import android.util.Log;
18 | import android.view.GestureDetector;
19 | import android.view.MotionEvent;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.view.animation.AnticipateInterpolator;
23 | import android.view.animation.OvershootInterpolator;
24 | import android.widget.ImageView;
25 | import android.widget.TextView;
26 |
27 | import java.util.ArrayList;
28 |
29 | /**
30 | * Component for a FloatingActionMenu.
31 | *
32 | * Created by charry on 2015/6/11. https://gist.github.com/douo/dfde289778a9b3b6918f and modified by Tristan Wiley
33 | */
34 | public class FloatingActionMenu extends ViewGroup {
35 |
36 | //-- Properties --//
37 |
38 | /**
39 | * Defines the rate of change for the open animation.
40 | */
41 | static final TimeInterpolator DEFAULT_OPEN_INTERPOLATOR = new OvershootInterpolator();
42 |
43 | /**
44 | * Defines the rate of change for the close animation.
45 | */
46 | static final TimeInterpolator DEFAULT_CLOSE_INTERPOLATOR = new AnticipateInterpolator();
47 |
48 | /**
49 | * The main menu button that is always visible. Clicking this will open/close the menu.
50 | */
51 | private FloatingActionButton mMenuButton;
52 |
53 | /**
54 | * The list of menu items to appear when the menu opens.
55 | */
56 | private ArrayList mMenuItems;
57 |
58 | /**
59 | * The list of labels to appear next to the menu items.
60 | */
61 | private ArrayList mMenuItemLabels;
62 |
63 | /**
64 | * Animators to animate the appearance/disappearance of the menu items.
65 | */
66 | private ArrayList mMenuItemAnimators;
67 |
68 | /**
69 | * The set of animations to occur when the menu opens.
70 | */
71 | private AnimatorSet mOpenAnimatorSet = new AnimatorSet();
72 |
73 | /**
74 | * The set of animations to occur when the menu closes.
75 | */
76 | private AnimatorSet mCloseAnimatorSet = new AnimatorSet();
77 |
78 | /**
79 | * The image that will appear inside the main menu item.
80 | */
81 | private ImageView mIcon;
82 |
83 | /**
84 | * A flag representing the open state of the menu.
85 | */
86 | private boolean mOpen;
87 |
88 | /**
89 | * A flag representing the current animation stte of the menu.
90 | */
91 | private boolean animating;
92 |
93 | /**
94 | * A flag representing whether or not the menu should close if the user touches outside of the menu items.
95 | */
96 | private boolean mIsSetClosedOnTouchOutside = true;
97 |
98 | /**
99 | * The duration of the open/close animations.
100 | */
101 | private long duration = 300;
102 |
103 | /**
104 | * A flag representing whether or not the menu appearance is a circle (true) or linear menu (false).
105 | */
106 | private boolean isCircle = false;
107 |
108 | /**
109 | * The radius of the circular menu (if application).
110 | */
111 | private int mRadius = 256;
112 |
113 | /**
114 | * If the radius of the circle is a multiple of the FB width, this is what that ratio is.
115 | */
116 | private float multipleOfFB = 0;
117 |
118 | /**
119 | * The gap between menu items.
120 | */
121 | private int mItemGap = 0;
122 |
123 | /**
124 | * A click listener for the main menu item.
125 | */
126 | private OnMenuItemClickListener onMenuItemClickListener;
127 |
128 | /**
129 | * A listener for when the menu toggles between open and closed.
130 | */
131 | private OnMenuToggleListener onMenuToggleListener;
132 |
133 | /**
134 | * A GestureDetector that looks for gestures outside the FAM and closes it if necessary.
135 | */
136 | GestureDetector mGestureDetector = new GestureDetector(getContext(),
137 | new GestureDetector.SimpleOnGestureListener() {
138 |
139 | @Override
140 | public boolean onDown(MotionEvent e) {
141 | return mIsSetClosedOnTouchOutside && isOpened();
142 | }
143 |
144 | @Override
145 | public boolean onSingleTapUp(MotionEvent e) {
146 | close();
147 | return true;
148 | }
149 | }
150 | );
151 |
152 | /**
153 | * An OnItemClickListener that handles clicks on a menu item or one of its labels.
154 | */
155 | private OnClickListener mOnItemClickListener = new OnClickListener() {
156 | @Override
157 | public void onClick(View v) {
158 | // If we click a menu item, call our MenuItemClickListener.
159 | // Else - we are clicking a label, call our MenuItemClickListener.
160 | // This is split into an if/else since we access different arrays for each.
161 | if (v instanceof FloatingActionButton) {
162 | int i = mMenuItems.indexOf(v);
163 | if (onMenuItemClickListener != null) {
164 | onMenuItemClickListener
165 | .onMenuItemClick(FloatingActionMenu.this, i, (FloatingActionButton) v);
166 | }
167 | } else if (v instanceof TextView) {
168 | int i = mMenuItemLabels.indexOf(v);
169 | if (onMenuItemClickListener != null) {
170 | onMenuItemClickListener.onMenuItemClick(FloatingActionMenu.this, i, mMenuItems.get(i));
171 | }
172 | }
173 | close();
174 | }
175 | };
176 |
177 | //-- Constructors --//
178 |
179 | public FloatingActionMenu(Context context) {
180 | this(context, null, 0);
181 | }
182 |
183 | public FloatingActionMenu(Context context, AttributeSet attrs) {
184 | this(context, attrs, 0);
185 | }
186 |
187 | public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr) {
188 | super(context, attrs, defStyleAttr);
189 |
190 | // Default all lists to 5 items.
191 | mMenuItems = new ArrayList<>(5);
192 | mMenuItemAnimators = new ArrayList<>(5);
193 | mMenuItemLabels = new ArrayList<>(5);
194 | mIcon = new ImageView(context);
195 | }
196 |
197 | //-- Overriden methods --//
198 |
199 | @Override
200 | protected void onFinishInflate() {
201 | bringChildToFront(mMenuButton);
202 | bringChildToFront(mIcon);
203 | super.onFinishInflate();
204 | }
205 |
206 | @Override
207 | public void addView(@NonNull View child, int index, LayoutParams params) {
208 | super.addView(child, index, params);
209 |
210 | // If the child count is greater than one, we are adding menu items.
211 | // If the child count is not greater than one, we are adding the initial menu item.
212 | if (getChildCount() > 1) {
213 | if (child instanceof FloatingActionButton) {
214 | addMenuItem((FloatingActionButton) child);
215 | }
216 | } else {
217 | mMenuButton = (FloatingActionButton) child;
218 | mIcon.setImageDrawable(mMenuButton.getDrawable());
219 | addView(mIcon);
220 | mMenuButton.setImageDrawable(mMenuButton.getDrawable());
221 | createDefaultIconAnimation();
222 | mMenuButton.setOnClickListener(new OnClickListener() {
223 | @Override
224 | public void onClick(View v) {
225 | toggle();
226 | }
227 | });
228 | }
229 | }
230 |
231 | /**
232 | * Handles the measuring of the FAM, and sets the size according to the number of children.
233 | */
234 | @Override
235 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
236 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
237 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
238 | int width;
239 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
240 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
241 | int height;
242 | final int count = getChildCount();
243 | int maxChildWidth = 0;
244 | for (int i = 0; i < count; i++) {
245 | View child = getChildAt(i);
246 | measureChild(child, widthMeasureSpec, heightMeasureSpec);
247 | }
248 | for (int i = 0; i < mMenuItems.size(); i++) {
249 | FloatingActionButton fab = mMenuItems.get(i);
250 | TextView label = mMenuItemLabels.get(i);
251 | maxChildWidth = Math.max(maxChildWidth,
252 | label.getMeasuredWidth() + fab.getMeasuredWidth());
253 |
254 | }
255 |
256 | maxChildWidth = Math.max(mMenuButton.getMeasuredWidth(), maxChildWidth);
257 |
258 | if (widthMode == MeasureSpec.EXACTLY) {
259 | width = widthSize;
260 | } else {
261 | width = maxChildWidth + 30;
262 | }
263 | if (heightMode == MeasureSpec.EXACTLY) {
264 | height = heightSize;
265 | } else {
266 | int heightSum = 0;
267 | for (int i = 0; i < count; i++) {
268 | View child = getChildAt(i);
269 | heightSum += child.getMeasuredHeight();
270 | }
271 | height = heightSum + 20;
272 | }
273 |
274 | setMeasuredDimension(resolveSize(width, widthMeasureSpec),
275 | resolveSize(height, heightMeasureSpec));
276 | }
277 |
278 | /**
279 | * Handles a touch event in the ViewGroup and closes the FAM if necessary.
280 | */
281 | @Override
282 | public boolean onTouchEvent(@NonNull MotionEvent event) {
283 | if (mIsSetClosedOnTouchOutside) {
284 | return mGestureDetector.onTouchEvent(event);
285 | } else {
286 | return super.onTouchEvent(event);
287 | }
288 | }
289 |
290 | /**
291 | * Sets the layout of the ViewGroup dependent on the number of menu items as well as menu direction.
292 | */
293 | @Override
294 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
295 | System.out.println("onLayout:" + changed);
296 | if (changed) {
297 | int right = r - getPaddingRight();
298 | int bottom = b - getPaddingBottom();
299 | int top = bottom - mMenuButton.getMeasuredHeight();
300 | mMenuButton.layout(right - mMenuButton.getMeasuredWidth(), top, right, bottom);
301 | int dw = (mMenuButton.getMeasuredWidth() - mIcon.getMeasuredWidth()) / 2;
302 | int dh = (mMenuButton.getMeasuredHeight() - mIcon.getMeasuredHeight()) / 2;
303 | mIcon.layout(right - mIcon.getMeasuredWidth() - dw,
304 | bottom - mIcon.getMeasuredHeight() - dh, right - dw, bottom - dh);
305 |
306 | if (isCircle) {
307 | if (mMenuItems.size() < 2) {
308 | Log.e("onLayout", "Floating Action Buttons must more then one!");
309 | return;
310 | }
311 | double angle = Math.PI/2d/(mMenuItems.size() - 1);
312 | for (int i = 0; i < mMenuItems.size(); i++) {
313 | FloatingActionButton itemFB = mMenuItems.get(i);
314 | int fbWidth = itemFB.getMeasuredWidth();
315 | int fbHeight = itemFB.getMeasuredHeight();
316 | if (0 != multipleOfFB) {
317 | mRadius = (int) (fbWidth * multipleOfFB);
318 | }
319 | int itemDw = (mMenuButton.getMeasuredWidth() - fbWidth) / 2;
320 | int itemDh = (mMenuButton.getMeasuredHeight() - fbHeight) / 2;
321 | int itemX = (int) (mRadius*Math.cos(i*angle));
322 | int itemY = (int) (mRadius*Math.sin(i*angle));
323 | itemFB.layout(right - itemX - fbWidth - itemDw, bottom - itemY - fbHeight - itemDh,
324 | right - itemX - itemDw, bottom - itemY - itemDh);
325 |
326 | if (!animating) {
327 | if (!mOpen) {
328 | itemFB.setTranslationY(mMenuButton.getTop() - itemFB.getTop());
329 | itemFB.setTranslationX(mMenuButton.getLeft() - itemFB.getLeft());
330 | itemFB.setVisibility(GONE);
331 | } else {
332 | itemFB.setTranslationY(0);
333 | itemFB.setTranslationX(0);
334 | itemFB.setVisibility(VISIBLE);
335 | }
336 | }
337 | }
338 | } else {
339 | for (int i = 0; i < mMenuItems.size(); i++) {
340 | FloatingActionButton item = mMenuItems.get(i);
341 | TextView label = mMenuItemLabels.get(i);
342 |
343 | label.setBackgroundResource(R.drawable.rounded_corners);
344 | bottom = top -= mItemGap;
345 |
346 | top -= item.getMeasuredHeight();
347 | int width = item.getMeasuredWidth();
348 | int d = (mMenuButton.getMeasuredWidth() - width) / 2;
349 | item.layout(right - width - d, top, right - d, bottom);
350 | d = (item.getMeasuredHeight() - label.getMeasuredHeight()) / 2;
351 |
352 | label.layout(item.getLeft() - label.getMeasuredWidth() - 50,
353 | item.getTop() + d, item.getLeft(),
354 | item.getTop() + d + label.getMeasuredHeight());
355 | if (!animating) {
356 | if (!mOpen) {
357 | item.setTranslationY(mMenuButton.getTop() - item.getTop());
358 | item.setVisibility(GONE);
359 | label.setVisibility(GONE);
360 | } else {
361 | item.setTranslationY(0);
362 | item.setVisibility(VISIBLE);
363 | label.setVisibility(VISIBLE);
364 | }
365 | }
366 | }
367 | }
368 | if (!animating && getBackground() != null) {
369 | if (!mOpen) {
370 | getBackground().setAlpha(0);
371 | } else {
372 | getBackground().setAlpha(0xff);
373 | }
374 | }
375 | }
376 | }
377 |
378 | /**
379 | * Saves the state of the menu item as open or close to be able to handle device rotations.
380 | */
381 | @Override
382 | public Parcelable onSaveInstanceState() {
383 | d("onSaveInstanceState");
384 | Bundle bundle = new Bundle();
385 | bundle.putParcelable("instanceState", super.onSaveInstanceState());
386 | bundle.putBoolean("mOpen", mOpen);
387 | // ... save everything
388 | return bundle;
389 | }
390 |
391 | /**
392 | * Restores the state of the FAM after a rotation.
393 | */
394 | @Override
395 | public void onRestoreInstanceState(Parcelable state) {
396 | d("onRestoreInstanceState");
397 | if (state instanceof Bundle) {
398 | Bundle bundle = (Bundle) state;
399 | mOpen = bundle.getBoolean("mOpen");
400 | // ... load everything
401 | state = bundle.getParcelable("instanceState");
402 | }
403 | super.onRestoreInstanceState(state);
404 | }
405 |
406 | @Override
407 | protected void onDetachedFromWindow() {
408 | d("onDetachedFromWindow");
409 | //getBackground().setAlpha(bgAlpha);//reset default alpha
410 | super.onDetachedFromWindow();
411 | }
412 |
413 | @Override
414 | public void setBackground(Drawable background) {
415 | if (background instanceof ColorDrawable) {
416 | // after activity finish and relaucher , background drawable state still remain?
417 | int bgAlpha = Color.alpha(((ColorDrawable) background).getColor());
418 | d("bg:" + Integer.toHexString(bgAlpha));
419 | super.setBackground(background);
420 | } else {
421 | throw new IllegalArgumentException("floating only support color background");
422 | }
423 | }
424 |
425 | //-- Open and close methods methods --//
426 |
427 | /**
428 | * Toggles the menu between open and closed, depending on its current state.
429 | */
430 | public void toggle() {
431 | if (!mOpen) {
432 | open();
433 | } else {
434 | close();
435 | }
436 | }
437 |
438 | /**
439 | * Opens the FloatingActionMenu.
440 | */
441 | public void open() {
442 | d("open");
443 | startOpenAnimator();
444 | mOpen = true;
445 | if (onMenuToggleListener != null) {
446 | onMenuToggleListener.onMenuToggle(true);
447 | }
448 | }
449 |
450 | /**
451 | * Closes the FloatingActionMenu.
452 | */
453 | public void close() {
454 | startCloseAnimator();
455 | mOpen = false;
456 | if (onMenuToggleListener != null) {
457 | onMenuToggleListener.onMenuToggle(true);
458 | }
459 | }
460 |
461 | //-- Animation methods. --//
462 |
463 | /**
464 | * Initiates all of the closing animations.
465 | */
466 | protected void startCloseAnimator() {
467 | mCloseAnimatorSet.start();
468 | for (ItemAnimator anim : mMenuItemAnimators) {
469 | anim.startCloseAnimator();
470 | }
471 | }
472 |
473 | /**
474 | * Initiating all of the opening animations.
475 | */
476 | protected void startOpenAnimator() {
477 | mOpenAnimatorSet.start();
478 | for (ItemAnimator anim : mMenuItemAnimators) {
479 | anim.startOpenAnimator();
480 | }
481 | }
482 |
483 | /**
484 | * Adds a new menu item to the FloatingActionMenu.
485 | * @param item The FloatingActionButton to add to the menu.
486 | */
487 | public void addMenuItem(FloatingActionButton item) {
488 | mMenuItems.add(item);
489 | mMenuItemAnimators.add(new ItemAnimator(item));
490 |
491 | TextView button = new TextView(getContext());
492 |
493 | LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
494 | button.setLayoutParams(params);
495 |
496 | button.setBackgroundResource(R.drawable.rounded_corners);
497 |
498 | button.setTextColor(Color.WHITE);
499 | button.setText(item.getContentDescription());
500 |
501 | Integer paddingSize = (int)button.getTextSize() / 3;
502 |
503 | button.setPadding(paddingSize, paddingSize, paddingSize, paddingSize);
504 |
505 | addView(button);
506 | mMenuItemLabels.add(button);
507 | item.setTag(button);
508 | item.setOnClickListener(mOnItemClickListener);
509 | button.setOnClickListener(mOnItemClickListener);
510 | }
511 |
512 | /**
513 | * Sets the default animation for the FAM icon, which is simply rotation.
514 | */
515 | private void createDefaultIconAnimation() {
516 | Animator.AnimatorListener listener = new Animator.AnimatorListener() {
517 | @Override
518 | public void onAnimationStart(Animator animation) {
519 | animating = true;
520 | }
521 |
522 | @Override
523 | public void onAnimationEnd(Animator animation) {
524 | animating = false;
525 | }
526 |
527 | @Override
528 | public void onAnimationCancel(Animator animation) {
529 | animating = false;
530 | }
531 |
532 | @Override
533 | public void onAnimationRepeat(Animator animation) {
534 |
535 | }
536 | };
537 | ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat(
538 | mIcon,
539 | "rotation",
540 | 135f,
541 | 0f
542 | );
543 |
544 | ObjectAnimator expandAnimator = ObjectAnimator.ofFloat(
545 | mIcon,
546 | "rotation",
547 | 0f,
548 | 135f
549 | );
550 |
551 | if (getBackground() != null) {
552 |
553 |
554 | ValueAnimator hideBackgroundAnimator = ObjectAnimator.ofInt(0xff, 0);
555 | hideBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
556 | @Override
557 | public void onAnimationUpdate(ValueAnimator animation) {
558 | Integer alpha = (Integer) animation.getAnimatedValue();
559 | //System.out.println(alpha);
560 | getBackground().setAlpha(alpha > 0xff ? 0xff : alpha);
561 | }
562 | });
563 | ValueAnimator showBackgroundAnimator = ObjectAnimator.ofInt(0, 0xff);
564 | showBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
565 | @Override
566 | public void onAnimationUpdate(ValueAnimator animation) {
567 |
568 | Integer alpha = (Integer) animation.getAnimatedValue();
569 | //System.out.println(alpha);
570 | getBackground().setAlpha(alpha > 0xff ? 0xff : alpha);
571 | }
572 | });
573 |
574 | mOpenAnimatorSet.playTogether(expandAnimator, showBackgroundAnimator);
575 | mCloseAnimatorSet.playTogether(collapseAnimator, hideBackgroundAnimator);
576 | } else {
577 | mOpenAnimatorSet.playTogether(expandAnimator);
578 | mCloseAnimatorSet.playTogether(collapseAnimator);
579 | }
580 |
581 | mOpenAnimatorSet.setInterpolator(DEFAULT_OPEN_INTERPOLATOR);
582 | mCloseAnimatorSet.setInterpolator(DEFAULT_CLOSE_INTERPOLATOR);
583 |
584 | mOpenAnimatorSet.setDuration(duration);
585 | mCloseAnimatorSet.setDuration(duration);
586 |
587 | mOpenAnimatorSet.addListener(listener);
588 | mCloseAnimatorSet.addListener(listener);
589 | }
590 |
591 | //-- Accessors --//
592 |
593 | /**
594 | * Determines whether or not the menu is open.
595 | * @return True if the menu is open, false otherwise.
596 | */
597 | public boolean isOpened() {
598 | return mOpen;
599 | }
600 |
601 | /**
602 | * Retrieves the OnMenuToggleListener that is applied to the FloatingActionMenu.
603 | */
604 | public OnMenuToggleListener getOnMenuToggleListener() {
605 | return onMenuToggleListener;
606 | }
607 |
608 | /**
609 | * Retrieves the OnMenuItemClickListener that is applied to the FloatingActionMenu.
610 | */
611 | public OnMenuItemClickListener getOnMenuItemClickListener() {
612 | return onMenuItemClickListener;
613 | }
614 |
615 | //-- Mutators --//
616 |
617 | /**
618 | * Assigns an OnMenuToggleListener to the FloatingActionMenu.
619 | */
620 | public void setOnMenuToggleListener(OnMenuToggleListener onMenuToggleListener) {
621 | this.onMenuToggleListener = onMenuToggleListener;
622 | }
623 |
624 | /**
625 | * Assigns an OnMenuItemClickListener to the FloatingActionMenu.
626 | */
627 | public void setOnMenuItemClickListener(OnMenuItemClickListener onMenuItemClickListener) {
628 | this.onMenuItemClickListener = onMenuItemClickListener;
629 | }
630 |
631 | /**
632 | * Set as circle(default) or line pattern
633 | */
634 | public void setIsCircle(boolean isCircle) {
635 | this.isCircle = isCircle;
636 | }
637 |
638 | /**
639 | * Set the radius of menu, default 256
640 | */
641 | public void setmRadius(int mRadius) {
642 | this.mRadius = mRadius;
643 | }
644 |
645 | /**
646 | * Set radius as multiple of width of floating action button
647 | */
648 | public void setMultipleOfFB(float multipleOfFB) {
649 | this.multipleOfFB = multipleOfFB;
650 | }
651 |
652 | /**
653 | * Duration of anim, default 300
654 | */
655 | public void setDuration(long duration) {
656 | this.duration = duration;
657 | }
658 |
659 | /**
660 | * Only usefully in Line pattern - sets the gap between menu items.
661 | */
662 | public void setmItemGap(int mItemGap) {
663 | this.mItemGap = mItemGap;
664 | }
665 |
666 | //-- Misc/Helper methods --//
667 |
668 | protected void d(String msg) {
669 | Log.d("FAM", msg == null ? null : msg);
670 | }
671 |
672 | //-- Interfaces --//
673 |
674 | /**
675 | * Interface that handles a change in the open/close state of the FloatingActionMenu.
676 | */
677 | public interface OnMenuToggleListener {
678 | void onMenuToggle(boolean opened);
679 | }
680 |
681 | /**
682 | * Interface that handles the click action of a MenuItem.
683 | */
684 | public interface OnMenuItemClickListener {
685 | void onMenuItemClick(FloatingActionMenu fam, int index, FloatingActionButton item);
686 | }
687 |
688 | /**
689 | * Animator that controls the open/close animation of menu items.
690 | */
691 | private class ItemAnimator implements Animator.AnimatorListener {
692 | private View mView;
693 | private boolean playingOpenAnimator;
694 |
695 | public ItemAnimator(View v) {
696 | v.animate().setListener(this);
697 | mView = v;
698 | }
699 |
700 | public void startOpenAnimator() {
701 | mView.animate().cancel();
702 | playingOpenAnimator = true;
703 | mView.animate()
704 | .translationY(0)
705 | .translationX(0)
706 | .setInterpolator(DEFAULT_OPEN_INTERPOLATOR)
707 | .start();
708 | mMenuButton.animate()
709 | .rotation(135f)
710 | .setInterpolator(DEFAULT_OPEN_INTERPOLATOR)
711 | .start();
712 | }
713 |
714 | public void startCloseAnimator() {
715 | mView.animate().cancel();
716 | playingOpenAnimator = false;
717 | mView.animate()
718 | .translationX(mMenuButton.getLeft() - mView.getLeft())
719 | .translationY((mMenuButton.getTop() - mView.getTop()))
720 | .setInterpolator(DEFAULT_CLOSE_INTERPOLATOR)
721 | .start();
722 | mMenuButton.animate()
723 | .rotation(0f)
724 | .setInterpolator(DEFAULT_CLOSE_INTERPOLATOR)
725 | .start();
726 | }
727 |
728 | @Override
729 | public void onAnimationStart(Animator animation) {
730 | if (playingOpenAnimator) {
731 | mView.setVisibility(VISIBLE);
732 | } else {
733 | ((TextView) mView.getTag()).setVisibility(GONE);
734 | }
735 | }
736 |
737 | @Override
738 | public void onAnimationEnd(Animator animation) {
739 | if (!playingOpenAnimator) {
740 | mView.setVisibility(GONE);
741 | } else {
742 | ((TextView) mView.getTag()).setVisibility(VISIBLE);
743 | }
744 | }
745 |
746 | @Override
747 | public void onAnimationCancel(Animator animation) {
748 |
749 | }
750 |
751 | @Override
752 | public void onAnimationRepeat(Animator animation) {
753 | }
754 | }
755 | }
756 |
--------------------------------------------------------------------------------