├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── qwert2603
│ │ └── floating_action_mode_example
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable
│ ├── action_mode_background.xml
│ ├── ic_check_box_white_24dp.xml
│ ├── ic_delete_white_24dp.xml
│ ├── ic_select_all_white_24dp.xml
│ └── klimt_1918.png
│ ├── layout
│ ├── activity_main.xml
│ ├── item.xml
│ ├── user_list_action_mode.xml
│ └── user_list_action_mode_2.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── integers.xml
│ ├── strings.xml
│ └── styles.xml
├── art
├── device-2017-01-11-133834.png
├── device-2017-01-11-133856.png
├── device-2017-01-11-133905.png
├── device-2017-01-11-133940.png
├── device-2017-01-11-134000.png
├── device-2017-01-12-115335.png
├── device-2017-01-12-115349.png
├── device-2017-01-12-115403.png
├── device-2017-01-12-115420.png
├── qq.png
└── qq2.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── qwert2603
│ │ └── floating_action_mode
│ │ ├── FloatingActionMode.kt
│ │ └── Utils.kt
│ └── res
│ ├── drawable-v21
│ └── fam_image_button_background.xml
│ ├── drawable
│ ├── fam_ic_close_white_24dp.xml
│ ├── fam_ic_drag_white_24dp.xml
│ └── fam_image_button_background.xml
│ ├── layout
│ └── floating_action_mode.xml
│ └── values
│ ├── attrs.xml
│ └── colors.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.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 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FloatingActionMode
2 |
3 | [](https://www.jitpack.io/#qwert2603/FloatingActionMode)
4 |
5 | Floating Action Mode (FAM) is the custom view for context actions on Android. (*minSdkVersion* ***15***)
6 |
7 | FAM can be dragged over screen or it can be fixed at the top or bottom (with disabled dragging).
8 |
9 | ## [Demo Video (Fixed)](https://www.youtube.com/watch?v=1tn0MQV0ZrQ)
10 | ## [Demo Video (Dragging)](https://www.youtube.com/watch?v=PbQ8N7pWGt4)
11 |
12 | ## Fixed
13 | 
14 |
15 |
16 | ## Dragging
17 | 
18 |
19 | ## XML-Attributes
20 |
21 | FAM has following XML-attributes (they also may be changed programmatically):
22 |
23 | * ***fam_opened*** defines whether FAM opened when created. (false by default)
24 |
25 | * ***fam_content_res*** is LayoutRes that represents content of FAM (e.g. some buttons). (no content by default)
26 | * ***fam_can_close*** defines whether FAM has button for closing itself. (true by default)
27 |
28 | * ***fam_close_icon*** is DrawableRes for closing button. (has default value)
29 |
30 | * ***fam_can_drag*** defines whether FAM has button for gragging itself. (true by default)
31 |
32 | * ***fam_drag_icon*** is DrawableRes for dragging button. (has default value)
33 |
34 | * ***fam_can_dismiss*** defines whether FAM may be dismissed (and closed) if transtationX while dragging is big enough. (true by default)
35 |
36 | * ***fam_dismiss_threshold*** is fraction that used to solve threshold translationX for dismissing. (0.4f by default)
37 |
38 | * ***fam_minimize_direction*** defines minimize direction of FAM. This attribute may have following values (nearest by default):
39 | * *top* - FAM will be translated to the top border of parent (excluding offsets) while minimizing.
40 | * *bottom* - FAM will be translated to the bottom border of parent (excluding offsets) while minimizing.
41 | * *nearest* - FAM will be translated to the nearest (top or bottom) border of parent (excluding offsets) while minimizing.
42 |
43 | * ***fam_animation_duration*** defines duration of minimize/maximize animations. (400 by default)
44 |
45 | FAM has ***OnCloseListener*** that allows to get callback when FAM was dismissed or closed by user.
46 |
47 | ## Using in CoordinatorLayout
48 |
49 | FAM has its special CoordinatorLayout.Behavior and can be used in CoordinatorLayout.
50 | FloatingActionModeBehavior allows to offset FAM of AppBarLayout and Snackbar.SnackbarLayout.
51 | Also it allows to minimize/maximize FAM on scroll.
52 |
53 | FAM has no background by default, so you can use any one you want.
54 |
55 | *android:translationZ="8dp"* can be used for shadow.
56 |
57 | *android:animateLayoutChanges="true"* can be used to animate contentChanges (*fam_content_res* attribute).
58 | FAM animates *fam_close_button* and *fam_drag_button* changes by default.
59 |
60 | ```
61 |
62 |
63 |
64 | ...
65 |
66 |
67 |
69 |
70 |
85 |
86 |
87 | ```
88 |
89 | ## Download
90 |
91 | ```
92 | allprojects {
93 | repositories {
94 | ...
95 | maven { url "https://www.jitpack.io" }
96 | }
97 | }
98 | ```
99 |
100 | ```
101 | dependencies {
102 | compile 'com.github.qwert2603:FloatingActionMode:x.y.z'
103 | }
104 | ```
105 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.2"
8 | defaultConfig {
9 | applicationId "com.qwert2603.floating_action_mode_example"
10 | minSdkVersion 15
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | sourceSets {
22 | main.java.srcDirs += 'src/main/kotlin'
23 | }
24 | }
25 | kapt {
26 | generateStubs = true
27 | }
28 |
29 | dependencies {
30 | ext.support_version = '25.1.0'
31 |
32 | compile fileTree(dir: 'libs', include: ['*.jar'])
33 | compile project(':library')
34 |
35 | compile "com.android.support:appcompat-v7:$support_version"
36 | compile "com.android.support:design:$support_version"
37 |
38 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
39 | }
40 | repositories {
41 | mavenCentral()
42 | maven {
43 | url "http://repository.jetbrains.com/all"
44 | }
45 | }
--------------------------------------------------------------------------------
/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 C:\Users\alex\AppData\Local\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/qwert2603/floating_action_mode_example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.qwert2603.floating_action_mode_example
2 |
3 | import android.annotation.SuppressLint
4 | import android.graphics.Color
5 | import android.os.Bundle
6 | import android.support.design.widget.Snackbar
7 | import android.support.v7.app.AppCompatActivity
8 | import android.support.v7.widget.DividerItemDecoration
9 | import android.support.v7.widget.LinearLayoutManager
10 | import android.support.v7.widget.RecyclerView
11 | import android.view.LayoutInflater
12 | import android.view.View
13 | import android.view.ViewGroup
14 | import com.qwert2603.floating_action_mode.FloatingActionMode
15 | import kotlinx.android.synthetic.main.activity_main.*
16 | import kotlinx.android.synthetic.main.item.view.*
17 |
18 | class MainActivity : AppCompatActivity() {
19 |
20 | var b: Boolean = true
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | setContentView(R.layout.activity_main)
25 |
26 | setSupportActionBar(toolbar)
27 |
28 | recycler_view.layoutManager = LinearLayoutManager(this)
29 | recycler_view.adapter = ItemsAdapter()
30 | recycler_view.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
31 |
32 | floating_action_mode.onOpenListener = object : FloatingActionMode.OnOpenListener {
33 | override fun onOpen() {
34 | fab.animate().translationY(activity_main.height - fab.top.toFloat())
35 | }
36 | }
37 |
38 | floating_action_mode.onCloseListener = object : FloatingActionMode.OnCloseListener {
39 | override fun onClose() {
40 | fab.animate().translationY(0f)
41 | if (b) {
42 | Snackbar.make(activity_main, "closed", Snackbar.LENGTH_SHORT).show()
43 | }
44 | b = !b
45 | }
46 | }
47 | }
48 |
49 | private inner class ItemsAdapter : RecyclerView.Adapter() {
50 |
51 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = VH(LayoutInflater.from(this@MainActivity).inflate(R.layout.item, parent, false))
52 |
53 | override fun onBindViewHolder(holder: VH, position: Int) = holder.bind(position)
54 |
55 | override fun getItemCount() = 100
56 |
57 | internal inner class VH(itemView: View) : RecyclerView.ViewHolder(itemView) {
58 |
59 | init {
60 | itemView.setOnClickListener {
61 | Snackbar.make(this@MainActivity.activity_main, itemView.text.text, Snackbar.LENGTH_SHORT).show()
62 | if (adapterPosition == 14) {
63 | floating_action_mode.canDrag = !floating_action_mode.canDrag
64 | }
65 | if (adapterPosition == 17) {
66 | floating_action_mode.canClose = !floating_action_mode.canClose
67 | }
68 | if (adapterPosition == 19) {
69 | val minimizeDirection = FloatingActionMode.MinimizeDirection
70 | .values()[(floating_action_mode.minimizeDirection.ordinal + 1) % FloatingActionMode.MinimizeDirection.values().size]
71 | floating_action_mode.minimizeDirection = minimizeDirection
72 | Snackbar.make(this@MainActivity.activity_main, minimizeDirection.name, Snackbar.LENGTH_SHORT).show()
73 | }
74 | if (adapterPosition == 26) {
75 | if (floating_action_mode.contentRes == 0) floating_action_mode.contentRes = R.layout.user_list_action_mode else
76 | if (floating_action_mode.contentRes == R.layout.user_list_action_mode) floating_action_mode.contentRes = R.layout.user_list_action_mode_2 else
77 | if (floating_action_mode.contentRes == R.layout.user_list_action_mode_2) floating_action_mode.contentRes = 0
78 | }
79 | }
80 | itemView.setOnLongClickListener {
81 | floating_action_mode.open()
82 | return@setOnLongClickListener true
83 | }
84 | }
85 |
86 | @SuppressLint("SetTextI18n")
87 | fun bind(i: Int) = with(itemView) {
88 | color.setBackgroundColor(Color.argb(i * 256 / 100, 0, 0, 0xff))
89 | text.text = "Text #" + i
90 | }
91 | }
92 |
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/action_mode_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_check_box_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_delete_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_select_all_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/klimt_1918.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/drawable/klimt_1918.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
41 |
47 |
48 |
55 |
56 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/user_list_action_mode.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/user_list_action_mode_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
28 |
29 |
35 |
36 |
37 |
38 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #D90000
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 | 8dp
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/integers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 400
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Floating Action Mode Example
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/art/device-2017-01-11-133834.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-11-133834.png
--------------------------------------------------------------------------------
/art/device-2017-01-11-133856.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-11-133856.png
--------------------------------------------------------------------------------
/art/device-2017-01-11-133905.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-11-133905.png
--------------------------------------------------------------------------------
/art/device-2017-01-11-133940.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-11-133940.png
--------------------------------------------------------------------------------
/art/device-2017-01-11-134000.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-11-134000.png
--------------------------------------------------------------------------------
/art/device-2017-01-12-115335.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-12-115335.png
--------------------------------------------------------------------------------
/art/device-2017-01-12-115349.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-12-115349.png
--------------------------------------------------------------------------------
/art/device-2017-01-12-115403.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-12-115403.png
--------------------------------------------------------------------------------
/art/device-2017-01-12-115420.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/device-2017-01-12-115420.png
--------------------------------------------------------------------------------
/art/qq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/qq.png
--------------------------------------------------------------------------------
/art/qq2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/art/qq2.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.0.6'
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.2.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qwert2603/FloatingActionMode/a30a754a77b7ae7eb8a15225575355fde37a3986/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 04 16:13:10 KRAT 2017
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-3.2-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # 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 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 25
12 | versionCode 5
13 | versionName "1.4"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | sourceSets {
22 | main.java.srcDirs += 'src/main/kotlin'
23 | }
24 | }
25 | kapt {
26 | generateStubs = true
27 | }
28 |
29 | dependencies {
30 | ext.support_version = '25.1.0'
31 |
32 | compile fileTree(dir: 'libs', include: ['*.jar'])
33 |
34 | compile "com.android.support:appcompat-v7:$support_version"
35 | compile "com.android.support:design:$support_version"
36 |
37 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
38 | }
39 | repositories {
40 | mavenCentral()
41 | maven {
42 | url "http://repository.jetbrains.com/all"
43 | }
44 | }
--------------------------------------------------------------------------------
/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 C:\Users\alex\AppData\Local\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/com/qwert2603/floating_action_mode/FloatingActionMode.kt:
--------------------------------------------------------------------------------
1 | package com.qwert2603.floating_action_mode
2 |
3 | import android.animation.ValueAnimator
4 | import android.content.Context
5 | import android.os.Bundle
6 | import android.os.Parcelable
7 | import android.support.annotation.DrawableRes
8 | import android.support.annotation.FloatRange
9 | import android.support.annotation.LayoutRes
10 | import android.support.design.widget.AppBarLayout
11 | import android.support.design.widget.CoordinatorLayout
12 | import android.support.design.widget.Snackbar
13 | import android.support.v4.view.ViewCompat
14 | import android.util.AttributeSet
15 | import android.view.LayoutInflater
16 | import android.view.MotionEvent
17 | import android.view.View
18 | import android.widget.LinearLayout
19 | import com.qwert2603.floating_action_mode.Utils.between
20 | import com.qwert2603.floating_action_mode.Utils.centerX
21 | import com.qwert2603.floating_action_mode.Utils.parentHeight
22 | import kotlinx.android.synthetic.main.floating_action_mode.view.*
23 |
24 | /**
25 | * [FloatingActionMode] (FAM) that shows layout given to it.
26 | * Can be closed, dragged over screen and swiped-to-dismiss.
27 | */
28 | @CoordinatorLayout.DefaultBehavior(FloatingActionMode.FloatingActionModeBehavior::class)
29 | open class FloatingActionMode @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearLayout(context, attrs, defStyleAttr) {
30 |
31 | var opened: Boolean = false
32 |
33 | /**
34 | * Top offset of actionMode calculated by [FloatingActionModeBehavior] as [AppBarLayout.getHeight].
35 | */
36 | var topOffset: Int = 0
37 | set(value) {
38 | if (value != field) {
39 | field = value
40 | if (isInEditMode) {
41 | offsetTopAndBottom(calculateMaximizedTranslationY().toInt())
42 | return
43 | }
44 | arrangeY()
45 | }
46 | }
47 |
48 | /**
49 | * Bottom offset of actionMode calculated by [FloatingActionModeBehavior] as [Snackbar.SnackbarLayout.getHeight] - [Snackbar.SnackbarLayout.getTranslationY].
50 | */
51 | var bottomOffset: Int = 0
52 | set(value) {
53 | if (value != field) {
54 | field = value
55 | if (isInEditMode) {
56 | offsetTopAndBottom(calculateMaximizedTranslationY().toInt())
57 | return
58 | }
59 | arrangeY()
60 | }
61 | }
62 |
63 | @LayoutRes
64 | open var contentRes: Int = 0
65 | set(value) {
66 | field = value
67 |
68 | // first is LinearLayout with close_button & drag_button.
69 | if (childCount > 1) {
70 | removeViewAt(1)
71 | }
72 |
73 | if (field != 0) {
74 | LayoutInflater.from(context).inflate(field, this, true)
75 | }
76 | }
77 |
78 | open var canClose: Boolean = true
79 | set(value) {
80 | field = value
81 | fam_close_button.visibility = if (field) View.VISIBLE else View.GONE
82 | }
83 |
84 | @DrawableRes
85 | open var closeIconRes: Int = R.drawable.fam_ic_close_white_24dp
86 | set(value) {
87 | field = value
88 | if (field != 0) {
89 | fam_close_button.setImageResource(field)
90 | } else {
91 | fam_close_button.setImageDrawable(null)
92 | }
93 | }
94 |
95 | var maximized: Boolean = true
96 |
97 | var maximizeTranslationY: Float = 0f
98 | set(value) {
99 | if (value != field) {
100 | field = value
101 | arrangeY()
102 | }
103 | }
104 |
105 | open var canDrag: Boolean = true
106 | set(value) {
107 | field = value
108 | fam_drag_button.visibility = if (field) View.VISIBLE else View.GONE
109 | }
110 |
111 | @DrawableRes
112 | open var dragIconRes: Int = R.drawable.fam_ic_drag_white_24dp
113 | set(value) {
114 | field = value
115 | if (field != 0) {
116 | fam_drag_button.setImageResource(field)
117 | } else {
118 | fam_drag_button.setImageDrawable(null)
119 | }
120 | }
121 |
122 | var canDismiss: Boolean = true
123 |
124 | /**
125 | * Set threshold for actionMode dismissal.
126 | * If ([getTranslationX]/[getWidth]) > [dismissThreshold] actionMode will be dismissed after user stops touching [drag_button].
127 | */
128 | @FloatRange(from = 0.0, to = 1.0)
129 | var dismissThreshold: Float = 0.4f
130 |
131 | interface OnCloseListener {
132 | fun onClose()
133 | }
134 |
135 | var onCloseListener: OnCloseListener? = null
136 |
137 | interface OnOpenListener {
138 | fun onOpen()
139 | }
140 |
141 | var onOpenListener: OnOpenListener? = null
142 |
143 | enum class MinimizeDirection {
144 | TOP,
145 | BOTTOM,
146 | NEAREST
147 | }
148 |
149 | var minimizeDirection = MinimizeDirection.NEAREST
150 |
151 | var animationDuration: Long = 400L
152 |
153 | private var translationYAnimator: ValueAnimator = ValueAnimator.ofFloat(0f)
154 |
155 | private var startAnimationY: Float = 0f
156 |
157 | private val translationYAnimatorUpdateListener = ValueAnimator.AnimatorUpdateListener {
158 | val animatedValue = translationYAnimator.animatedValue as Float
159 | if (animatedValue.between(calculateMinimizeTranslationYTop(), calculateMinimizeTranslationYBottom())) {
160 | translationY = animatedValue
161 | } else {
162 | translationYAnimator.cancel()
163 | arrangeY()
164 | }
165 | }
166 |
167 | init {
168 | if (!isInEditMode) {
169 | visibility = View.INVISIBLE
170 | }
171 |
172 | LayoutInflater.from(context).inflate(R.layout.floating_action_mode, this, true)
173 | orientation = HORIZONTAL
174 |
175 | if (attrs != null) {
176 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMode)
177 | try {
178 | opened = typedArray.getBoolean(R.styleable.FloatingActionMode_fam_opened, false)
179 | contentRes = typedArray.getResourceId(R.styleable.FloatingActionMode_fam_content_res, 0)
180 | canClose = typedArray.getBoolean(R.styleable.FloatingActionMode_fam_can_close, true)
181 | closeIconRes = typedArray.getResourceId(R.styleable.FloatingActionMode_fam_close_icon, R.drawable.fam_ic_close_white_24dp)
182 | canDrag = typedArray.getBoolean(R.styleable.FloatingActionMode_fam_can_drag, true)
183 | dragIconRes = typedArray.getResourceId(R.styleable.FloatingActionMode_fam_drag_icon, R.drawable.fam_ic_drag_white_24dp)
184 | canDismiss = typedArray.getBoolean(R.styleable.FloatingActionMode_fam_can_dismiss, true)
185 | dismissThreshold = typedArray.getFloat(R.styleable.FloatingActionMode_fam_dismiss_threshold, 0.4f)
186 | val md = typedArray.getInteger(R.styleable.FloatingActionMode_fam_minimize_direction, -1)
187 | if (md >= 0) minimizeDirection = MinimizeDirection.values()[md]
188 | animationDuration = typedArray.getInteger(R.styleable.FloatingActionMode_fam_animation_duration, 400).toLong()
189 | } finally {
190 | typedArray.recycle()
191 | }
192 | }
193 |
194 | fam_close_button.setOnClickListener { close() }
195 |
196 | fam_drag_button.setOnTouchListener(object : OnTouchListener {
197 | var prevTransitionY = 0f
198 | var startRawX = 0f
199 | var startRawY = 0f
200 |
201 | override fun onTouch(v: View, event: MotionEvent): Boolean {
202 | if (!this@FloatingActionMode.canDrag || this@FloatingActionMode.translationYAnimator.isStarted) {
203 | return false
204 | }
205 |
206 | val fractionX = Math.abs(event.rawX - startRawX) / this@FloatingActionMode.width
207 |
208 | when (event.actionMasked) {
209 | MotionEvent.ACTION_DOWN -> {
210 | this@FloatingActionMode.fam_drag_button.isPressed = true
211 | startRawX = event.rawX
212 | startRawY = event.rawY
213 | prevTransitionY = this@FloatingActionMode.translationY
214 | }
215 | MotionEvent.ACTION_MOVE -> {
216 | this@FloatingActionMode.maximizeTranslationY = prevTransitionY + event.rawY - startRawY
217 | translationX = event.rawX - startRawX
218 | if (canDismiss) {
219 | val alpha = if (fractionX < dismissThreshold) 1.0f else Math.pow(1.0 - (fractionX - dismissThreshold) / (1 - dismissThreshold), 4.0).toFloat()
220 | this@FloatingActionMode.alpha = alpha
221 | }
222 | }
223 | MotionEvent.ACTION_UP -> {
224 | fam_drag_button.isPressed = false
225 | this@FloatingActionMode.animate().translationX(0f).duration = animationDuration
226 | if (canDismiss && fractionX > dismissThreshold) {
227 | this@FloatingActionMode.close()
228 | }
229 | }
230 | }
231 | return true
232 | }
233 | })
234 |
235 | if (opened) {
236 | openWithoutAnimation()
237 | }
238 | }
239 |
240 | private fun openWithoutAnimation() {
241 | visibility = View.VISIBLE
242 | maximize(false)
243 | }
244 |
245 | /**
246 | * Arrange FAM to correct Y position considering [topOffset], [bottomOffset], [maximized] and [maximizeTranslationY]
247 | */
248 | private fun arrangeY() {
249 | if (!translationYAnimator.isStarted) {
250 | translationY = calculateTranslationY()
251 | } else {
252 | translationYAnimator.values[0].setFloatValues(startAnimationY, calculateTranslationY())
253 | }
254 | }
255 |
256 | /**
257 | * Open FAM with animation.
258 | */
259 | open fun open() {
260 | if (opened) {
261 | return
262 | }
263 | opened = true
264 | onOpenListener?.onOpen()
265 | visibility = View.VISIBLE
266 | maximizeTranslationY = 0f
267 | translationY = 0f
268 | minimize(false)
269 | maximize(true)
270 | }
271 |
272 | /**
273 | * Close FAM with animation.
274 | */
275 | open fun close() {
276 | minimize(true)
277 | opened = false
278 | onCloseListener?.onClose()
279 | Utils.runOnUI((animationDuration * 1.5).toLong()) {
280 | if (!opened) {
281 | visibility = View.INVISIBLE
282 | }
283 | }
284 | }
285 |
286 | /**
287 | * Maximize FAM.
288 | * If [animate] == true, it will be animated to its maximized position.
289 | */
290 | open fun maximize(animate: Boolean) {
291 | if (!opened) {
292 | return
293 | }
294 | maximized = true
295 | val function = {
296 | scaleY = 1f
297 | scaleX = 1f
298 | translationY = calculateMaximizedTranslationY()
299 | alpha = 1f
300 | }
301 | if (animate) {
302 | animate().scaleY(1f).scaleX(1f).alpha(1f).duration = animationDuration
303 | animateTranslationY(calculateMaximizedTranslationY())
304 | } else {
305 | function()
306 | }
307 | }
308 |
309 | /**
310 | * Minimize FAM.
311 | * If [animate] == true, it will be animated to its minimize position considering [minimizeDirection].
312 | */
313 | open fun minimize(animate: Boolean) {
314 | if (!opened) {
315 | return
316 | }
317 | maximized = false
318 | val function = {
319 | scaleY = MINIMIZED_SCALE_Y
320 | scaleX = MINIMIZED_SCALE_X
321 | translationY = calculateMinimizeTranslationY()
322 | alpha = MINIMIZED_ALPHA
323 | }
324 | if (animate) {
325 | animate().scaleY(MINIMIZED_SCALE_Y).scaleX(MINIMIZED_SCALE_X).alpha(MINIMIZED_ALPHA).duration = animationDuration
326 | animateTranslationY(calculateMinimizeTranslationY())
327 | } else {
328 | function()
329 | }
330 | }
331 |
332 | private fun animateTranslationY(to: Float) {
333 | translationYAnimator.apply {
334 | removeAllListeners()
335 | removeAllUpdateListeners()
336 | cancel()
337 | }
338 | startAnimationY = translationY
339 | translationYAnimator = ValueAnimator.ofFloat(translationY, to)
340 | translationYAnimator.apply {
341 | duration = animationDuration
342 | addUpdateListener(translationYAnimatorUpdateListener)
343 | startDelay = animationDuration / 3
344 | start()
345 | }
346 | }
347 |
348 | private fun calculateTranslationY() = if (maximized) calculateMaximizedTranslationY() else calculateMinimizeTranslationY()
349 |
350 | private fun calculateMaximizedTranslationY(): Float {
351 | var tY = maximizeTranslationY
352 | var topMargin = 0
353 | var bottomMargin = 0
354 | val lp = layoutParams
355 | if (lp is MarginLayoutParams) {
356 | topMargin = lp.topMargin
357 | bottomMargin = lp.bottomMargin
358 | }
359 | val topOver = (topOffset + topMargin) - (top + tY)
360 | if (topOver > 0) {
361 | tY += topOver
362 | }
363 | val bottomOver = (bottom + tY) - (parentHeight() - bottomOffset - bottomMargin)
364 | if (bottomOver > 0) {
365 | tY -= bottomOver
366 | }
367 | return tY
368 | }
369 |
370 | private fun calculateMinimizeTranslationY() = when (minimizeDirection) {
371 | MinimizeDirection.TOP -> calculateMinimizeTranslationYTop()
372 | MinimizeDirection.BOTTOM -> calculateMinimizeTranslationYBottom()
373 | MinimizeDirection.NEAREST -> if (isInTopHalfOfParent()) calculateMinimizeTranslationYTop() else calculateMinimizeTranslationYBottom()
374 | }
375 |
376 | private fun calculateMinimizeTranslationYTop() = (-top + topOffset).toFloat() - height * (1 - MINIMIZED_SCALE_Y) / 2
377 |
378 | private fun calculateMinimizeTranslationYBottom() = parentHeight() - bottomOffset - bottom + height * (1 - MINIMIZED_SCALE_Y) / 2
379 |
380 | private fun isInTopHalfOfParent() = (centerX() + translationY < parentHeight() / 2)
381 |
382 | /**
383 | * Behavior for FAM, that updates FAM's
384 | * [topOffset] as [AppBarLayout.getHeight] and
385 | * [bottomOffset] as ([Snackbar.SnackbarLayout.getHeight]-[Snackbar.SnackbarLayout.getTranslationY]).
386 | *
387 | * Also this Behavior minimizes/maximizes FAM on scroll.
388 | */
389 | open class FloatingActionModeBehavior @JvmOverloads constructor(context: Context? = null, attrs: AttributeSet? = null) : CoordinatorLayout.Behavior(context, attrs) {
390 |
391 | override fun layoutDependsOn(parent: CoordinatorLayout?, child: FloatingActionMode?, dependency: View?): Boolean {
392 | return dependency is AppBarLayout || dependency is Snackbar.SnackbarLayout
393 | }
394 |
395 | override fun onDependentViewChanged(parent: CoordinatorLayout, child: FloatingActionMode, dependency: View): Boolean {
396 | when (dependency) {
397 | is AppBarLayout -> child.topOffset = dependency.bottom
398 | is Snackbar.SnackbarLayout -> child.bottomOffset = -1 * Math.min(0, dependency.getTranslationY().toInt() - dependency.getHeight())
399 | }
400 | return true
401 | }
402 |
403 | override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout?, child: FloatingActionMode?, directTargetChild: View?, target: View?, nestedScrollAxes: Int): Boolean {
404 | return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
405 | }
406 |
407 | override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionMode, target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) {
408 | super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
409 |
410 | if (!child.opened) return
411 |
412 | // FAM should not react to scroll its children.
413 | var parent = target.parent
414 | while (parent != coordinatorLayout) {
415 | if (parent == child) {
416 | return
417 | }
418 | parent = parent.parent
419 | }
420 |
421 | if (dyConsumed > 0) {
422 | child.minimize(true)
423 | } else if (dyConsumed < 0) {
424 | child.maximize(true)
425 | }
426 | }
427 | }
428 |
429 | override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
430 | return !maximized
431 | }
432 |
433 | override fun onTouchEvent(event: MotionEvent?): Boolean {
434 | return true
435 | }
436 |
437 | override fun onSaveInstanceState(): Parcelable {
438 | val bundle = Bundle()
439 | bundle.putParcelable(SUPER_STATE_KEY, super.onSaveInstanceState())
440 |
441 | bundle.putBoolean(OPENED_KEY, opened)
442 | bundle.putInt(CONTENT_RES_KEY, contentRes)
443 | bundle.putBoolean(CAN_CLOSE_KEY, canClose)
444 | bundle.putInt(CLOSE_ICON_RES_KEY, closeIconRes)
445 | bundle.putBoolean(CAN_DRAG_KEY, canDrag)
446 | bundle.putInt(DRAG_ICON_RES_KEY, dragIconRes)
447 | bundle.putBoolean(CAN_DISMISS_KEY, canDismiss)
448 | bundle.putFloat(DISMISS_THRESHOLD_KEY, dismissThreshold)
449 | bundle.putInt(MINIMIZE_DIRECTION_KEY, minimizeDirection.ordinal)
450 | bundle.putLong(ANIMATION_DURATION_KEY, animationDuration)
451 |
452 | return bundle
453 | }
454 |
455 | override fun onRestoreInstanceState(parcelable: Parcelable) {
456 | if (parcelable is Bundle) {
457 | opened = parcelable.getBoolean(OPENED_KEY)
458 | contentRes = parcelable.getInt(CONTENT_RES_KEY)
459 | canClose = parcelable.getBoolean(CAN_CLOSE_KEY)
460 | closeIconRes = parcelable.getInt(CLOSE_ICON_RES_KEY)
461 | canDrag = parcelable.getBoolean(CAN_DRAG_KEY)
462 | dragIconRes = parcelable.getInt(DRAG_ICON_RES_KEY)
463 | canDismiss = parcelable.getBoolean(CAN_DISMISS_KEY)
464 | dismissThreshold = parcelable.getFloat(DISMISS_THRESHOLD_KEY)
465 | minimizeDirection = MinimizeDirection.values()[parcelable.getInt(MINIMIZE_DIRECTION_KEY)]
466 | animationDuration = parcelable.getLong(ANIMATION_DURATION_KEY)
467 |
468 | val state = parcelable.getParcelable(SUPER_STATE_KEY)
469 | super.onRestoreInstanceState(state)
470 | } else {
471 | super.onRestoreInstanceState(parcelable)
472 | }
473 |
474 | if (opened) {
475 | openWithoutAnimation()
476 | arrangeY()
477 | }
478 | }
479 |
480 | companion object {
481 | private val SUPER_STATE_KEY = "com.qwert2603.floating_action_mode.SUPER_STATE_KEY"
482 |
483 | private val OPENED_KEY = "com.qwert2603.floating_action_mode.OPENED_KEY"
484 | private val CONTENT_RES_KEY = "com.qwert2603.floating_action_mode.CONTENT_RES_KEY"
485 | private val CAN_CLOSE_KEY = "com.qwert2603.floating_action_mode.CAN_CLOSE_KEY"
486 | private val CLOSE_ICON_RES_KEY = "com.qwert2603.floating_action_mode.CLOSE_ICON_RES_KEY"
487 | private val CAN_DRAG_KEY = "com.qwert2603.floating_action_mode.CAN_DRAG_KEY"
488 | private val DRAG_ICON_RES_KEY = "com.qwert2603.floating_action_mode.DRAG_ICON_RES_KEY"
489 | private val CAN_DISMISS_KEY = "com.qwert2603.floating_action_mode.CAN_DISMISS_KEY"
490 | private val DISMISS_THRESHOLD_KEY = "com.qwert2603.floating_action_mode.DISMISS_THRESHOLD_KEY"
491 | private val MINIMIZE_DIRECTION_KEY = "com.qwert2603.floating_action_mode.MINIMIZE_DIRECTION_KEY"
492 | private val ANIMATION_DURATION_KEY = "com.qwert2603.floating_action_mode.ANIMATION_DURATION_KEY"
493 |
494 | val MINIMIZED_SCALE_X = 0.5f
495 | val MINIMIZED_SCALE_Y = 0.5f
496 | val MINIMIZED_ALPHA = 0.5f
497 | }
498 | }
499 |
--------------------------------------------------------------------------------
/library/src/main/java/com/qwert2603/floating_action_mode/Utils.kt:
--------------------------------------------------------------------------------
1 | package com.qwert2603.floating_action_mode
2 |
3 | import android.os.Handler
4 | import android.os.Looper
5 | import android.view.View
6 | import android.view.ViewGroup
7 |
8 | internal object Utils {
9 |
10 | private val sMainLooperHandler: Handler = Handler(Looper.getMainLooper())
11 |
12 | /**
13 | * Post runnable to execute on main thread with given delay.
14 | */
15 | fun runOnUI(delay: Long = 0, func: () -> Unit) {
16 | sMainLooperHandler.postDelayed({ func() }, delay)
17 | }
18 |
19 | fun View.centerX() = top + height / 2
20 |
21 | fun View.parentHeight() = (parent as ViewGroup?)?.height ?: 0
22 |
23 | fun > T.between(l: T, r: T) = l < this && this < r
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-v21/fam_image_button_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fam_ic_close_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fam_ic_drag_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fam_image_button_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/floating_action_mode.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
18 |
19 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #54FFFFFF
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------