├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── LICENSE.txt
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── fonts
│ │ └── RobotoCondensed-Regular.ttf
│ ├── java
│ └── com
│ │ └── commit451
│ │ └── quickactionview
│ │ └── sample
│ │ ├── Cheese.kt
│ │ ├── CheeseAdapter.kt
│ │ ├── CheeseViewHolder.kt
│ │ ├── Cheeses.kt
│ │ ├── CustomActionsInAnimator.kt
│ │ ├── CustomActionsTitleAnimator.kt
│ │ ├── MainActivity.kt
│ │ └── RecyclerViewActivity.kt
│ └── res
│ ├── drawable-nodpi
│ ├── cheese_1.jpg
│ ├── cheese_2.jpg
│ ├── cheese_3.jpg
│ ├── cheese_4.jpg
│ └── cheese_5.jpg
│ ├── drawable
│ ├── ic_favorite_24dp.xml
│ ├── ic_shopping_basket_24dp.xml
│ ├── ic_shopping_basket_dark_24dp.xml
│ ├── ic_thumb_up_black_24dp.xml
│ ├── indicator.xml
│ ├── sample_background_color.xml
│ ├── sample_changing_icon.xml
│ └── text_background.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── activity_recyclerview.xml
│ └── item_cheese.xml
│ ├── menu
│ ├── actions.xml
│ └── actions_2.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
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── quickactionview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── commit451
│ │ └── quickactionview
│ │ ├── Action.kt
│ │ ├── ActionTitleView.kt
│ │ ├── ActionView.kt
│ │ ├── ActionsInAnimator.kt
│ │ ├── ActionsOutAnimator.kt
│ │ ├── ActionsTitleInAnimator.kt
│ │ ├── ActionsTitleOutAnimator.kt
│ │ ├── ColorUtils.kt
│ │ ├── ConfigHelper.kt
│ │ ├── QuickActionView.kt
│ │ └── animator
│ │ ├── FadeAnimator.kt
│ │ ├── FadeInFadeOutActionsTitleAnimator.kt
│ │ ├── PopAnimator.kt
│ │ └── SlideFromCenterAnimator.kt
│ └── res
│ ├── drawable
│ ├── qav_indicator.xml
│ └── qav_text_background.xml
│ └── values
│ └── dimens.xml
├── screenshots
└── qav.gif
└── settings.gradle
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 | on: [pull_request, push]
3 | jobs:
4 | build:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - name: Checkout the code
8 | uses: actions/checkout@v2
9 | - name: Build the app
10 | run: ./gradlew build
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io
2 |
3 | ### Android ###
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 |
29 | ### Intellij ###
30 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
31 |
32 | *.iml
33 |
34 | ## Directory-based project format:
35 | .idea/
36 | # if you remove the above rule, at least ignore the following:
37 |
38 | # User-specific stuff:
39 | # .idea/workspace.xml
40 | # .idea/tasks.xml
41 | # .idea/dictionaries
42 |
43 | # Sensitive or high-churn files:
44 | # .idea/dataSources.ids
45 | # .idea/dataSources.xml
46 | # .idea/sqlDataSources.xml
47 | # .idea/dynamic.xml
48 | # .idea/uiDesigner.xml
49 |
50 | # Gradle:
51 | # .idea/gradle.xml
52 | # .idea/libraries
53 |
54 | # Mongo Explorer plugin:
55 | # .idea/mongoSettings.xml
56 |
57 | ## File-based project format:
58 | *.ipr
59 | *.iws
60 |
61 | ## Plugin-specific files:
62 |
63 | # IntelliJ
64 | out/
65 |
66 | # mpeltonen/sbt-idea plugin
67 | .idea_modules/
68 |
69 | # JIRA plugin
70 | atlassian-ide-plugin.xml
71 |
72 | # Crashlytics plugin (for Android Studio and IntelliJ)
73 | com_crashlytics_export_strings.xml
74 |
75 | # Ignore Gradle GUI config
76 | gradle-app.setting
77 |
78 | # Mobile Tools for Java (J2ME)
79 | .mtj.tmp/
80 |
81 | # Package Files #
82 | *.war
83 | *.ear
84 |
85 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
86 | hs_err_pid*
87 |
88 | *.DS_Store
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QuickActionView
2 | View that shows quick actions when long pressed, inspired by Pinterest
3 |
4 | [](https://travis-ci.org/Commit451/QuickActionView) [](https://jitpack.io/#Commit451/QuickActionView)
5 |
6 | 
7 |
8 | # Gradle Dependency
9 |
10 | Add this in your root `build.gradle` file (**not** your module `build.gradle` file):
11 |
12 | ```gradle
13 | allprojects {
14 | repositories {
15 | ...
16 | maven { url "https://jitpack.io" }
17 | }
18 | }
19 | ```
20 |
21 | Then, add the library to your project `build.gradle`
22 | ```gradle
23 | dependencies {
24 | compile 'com.github.Commit451:QuickActionView:latest.release.here'
25 | }
26 | ```
27 |
28 | # Basic Usage
29 |
30 | See the sample app for usage within a normal layout, as well as within a list using RecyclerView. In the most basic usage:
31 |
32 | ```java
33 | View view = findViewById(R.id.your_view);
34 | QuickActionView.make(this)
35 | .addActions(R.menu.actions)
36 | .register(view);
37 | ```
38 | You can also create Actions at runtime:
39 | ```java
40 | Drawable icon = ContextCompat.getDrawable(this, R.drawable.ic_favorite_24dp);
41 | String title = getString(R.string.action_favorite);
42 | Action action = new Action(1337, icon, title);
43 | QuickActionView.make(this)
44 | .addAction(action)
45 | //more configuring
46 | .register(view);
47 | ```
48 |
49 | # Configuring the QuickActionView
50 |
51 | QuickActionView can be customized globally, or on a per Action basis.
52 | ```java
53 | QuickActionView.make(this)
54 | .addActions(R.menu.actions)
55 | .setOnActionSelectedListener(mQuickActionListener)
56 | .setBackgroundColor(Color.RED)
57 | .setTextColor(Color.BLUE)
58 | .setTextSize(30)
59 | .setScrimColor(Color.parseColor("#99FFFFFF"))
60 | //etc
61 | .register(view);
62 | ```
63 |
64 | # Configuring Action Items
65 |
66 | Use the `QuickActionConfig` builder to create custom configurations for each action item you create.
67 | ```java
68 | //Give one of the quick actions custom colors
69 | Action.Config actionConfig = new Action.Config()
70 | .setBackgroundColor(Color.BLUE)
71 | .setTextColor(Color.MAGENTA);
72 |
73 | QuickActionView.make(this)
74 | .addActions(R.menu.actions)
75 | //the custom Action.Cofig will only apply to the addToCart action
76 | .setActionConfig(actionConfig, R.id.action_add_to_cart)
77 | .register(findViewById(R.id.custom_parent));
78 | ```
79 |
80 | # Customizing Animations
81 |
82 | You can even customize the animation performed when the actions come into view and go out of view. `FadeAnimator` `PopAnimator` and `SlideFromCenterAnimator` are three pre-built animators, and all you need to do to create your own is implement `ActionsInAnimator`, `ActionsOutAnimator`
83 | and call `setActionsInAnimator` and `setActionsOutAnimator` respectively.
84 |
85 | # Listening for Events
86 |
87 | You can hook into the interesting events a QuickActionView has:
88 | ```java
89 | QuickActionView.make(this)
90 | .addActions(R.menu.actions)
91 | .setOnActionSelectedListener(mQuickActionListener)
92 | .setOnShowListener(mQuickActionShowListener)
93 | .setOnDismissListener(mQuickActionDismissListener)
94 | .setOnActionHoverChangedListener(mOnActionHoverChangedListener)
95 | .register(view);
96 | ```
97 |
98 | See the sample for more detail.
99 |
100 | License
101 | --------
102 |
103 | Copyright 2020 Commit 451
104 |
105 | Licensed under the Apache License, Version 2.0 (the "License");
106 | you may not use this file except in compliance with the License.
107 | You may obtain a copy of the License at
108 |
109 | http://www.apache.org/licenses/LICENSE-2.0
110 |
111 | Unless required by applicable law or agreed to in writing, software
112 | distributed under the License is distributed on an "AS IS" BASIS,
113 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114 | See the License for the specific language governing permissions and
115 | limitations under the License.
116 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 33
7 |
8 | defaultConfig {
9 | applicationId "com.commit451.quickactionview.sample"
10 | minSdkVersion 21
11 | targetSdkVersion 33
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 | lintOptions {
22 | abortOnError false
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation 'androidx.appcompat:appcompat:1.5.1'
28 | implementation 'com.google.android.material:material:1.7.0'
29 | implementation 'androidx.recyclerview:recyclerview:1.2.1'
30 |
31 | implementation project(':quickactionview')
32 | }
33 |
--------------------------------------------------------------------------------
/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 /Users/John/Library/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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/RobotoCondensed-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/assets/fonts/RobotoCondensed-Regular.ttf
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/Cheese.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | /**
4 | * A fake model to show usage
5 | */
6 | data class Cheese(
7 | val drawable: Int,
8 | val name: String
9 | )
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/CheeseAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import android.content.Context
4 | import com.google.android.material.snackbar.Snackbar
5 | import androidx.recyclerview.widget.RecyclerView
6 | import android.view.ViewGroup
7 |
8 | import com.commit451.quickactionview.Action
9 | import com.commit451.quickactionview.OnActionSelectedListener
10 | import com.commit451.quickactionview.QuickActionView
11 |
12 | /**
13 | * Adapter for the RecyclerView, which holds cheeses
14 | */
15 | class CheeseAdapter(context: Context, private val listener: Listener) : RecyclerView.Adapter(), OnActionSelectedListener {
16 |
17 | private val values = mutableListOf()
18 |
19 | private val quickActionView: QuickActionView = QuickActionView.make(context)
20 | .addActions(R.menu.actions)
21 | .setOnActionSelectedListener(this)
22 |
23 | override fun invoke(action: Action, quickActionView: QuickActionView) {
24 | val view = quickActionView.longPressedView
25 | if (view != null) {
26 | val position = view.getTag(R.id.list_position) as Int
27 | val cheese = values[position]
28 | Snackbar.make(view, "Clicked on ${cheese.name} with action ${action.title}", Snackbar.LENGTH_SHORT)
29 | .show()
30 | }
31 | }
32 |
33 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheeseViewHolder {
34 | val holder = CheeseViewHolder.newInstance(parent)
35 | holder.itemView.setOnClickListener { v ->
36 | val position = v.getTag(R.id.list_position) as Int
37 | val cheese = values[position]
38 | // Communicate to the activity that the item was clicked
39 | listener.onItemClicked(cheese)
40 | }
41 | quickActionView.register(holder.itemView)
42 | return holder
43 | }
44 |
45 | override fun onBindViewHolder(holder: CheeseViewHolder, position: Int) {
46 | val cheese = values[position]
47 | holder.bind(cheese)
48 | holder.itemView.setTag(R.id.list_position, position)
49 | holder.itemView.setTag(R.id.list_holder, holder)
50 | }
51 |
52 | override fun getItemCount(): Int {
53 | return values.size
54 | }
55 |
56 | fun setData(cheeses: Collection) {
57 | values.addAll(cheeses)
58 | notifyDataSetChanged()
59 | }
60 |
61 | interface Listener {
62 | fun onItemClicked(cheese: Cheese)
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/CheeseViewHolder.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import android.widget.ImageView
7 | import android.widget.TextView
8 | import androidx.recyclerview.widget.RecyclerView
9 |
10 | /**
11 | * The view holder related to each Cheese item
12 | */
13 | class CheeseViewHolder(view: View) : RecyclerView.ViewHolder(view) {
14 |
15 | companion object {
16 |
17 | fun newInstance(parent: ViewGroup): CheeseViewHolder {
18 | val view = LayoutInflater.from(parent.context)
19 | .inflate(R.layout.item_cheese, parent, false)
20 | return CheeseViewHolder(view)
21 | }
22 | }
23 |
24 | private val image: ImageView = view.findViewById(R.id.image)
25 | private val title: TextView = view.findViewById(R.id.name)
26 |
27 | fun bind(cheese: Cheese) {
28 | image.setImageResource(cheese.drawable)
29 | title.text = cheese.name
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/Cheeses.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import java.util.Random
4 |
5 | object Cheeses {
6 |
7 | private val RANDOM = Random()
8 |
9 | private fun randomCheeseDrawable(): Int {
10 | return when (RANDOM.nextInt(5)) {
11 | 0 -> R.drawable.cheese_1
12 | 1 -> R.drawable.cheese_2
13 | 2 -> R.drawable.cheese_3
14 | 3 -> R.drawable.cheese_4
15 | 4 -> R.drawable.cheese_5
16 | else -> R.drawable.cheese_1
17 | }
18 | }
19 |
20 | private val cheeseStrings = arrayOf("Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese", "Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell", "Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc", "Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss", "Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon", "Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase", "Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese", "Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy", "Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille", "Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore", "Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)", "Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves", "Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur", "Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon", "Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin", "Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)", "Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine", "Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza", "Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)", "Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta", "Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie", "Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux", "Capricorn Goat", "Capriole Banon", "Carre de l'Est", "Casciotta di Urbino", "Cashel Blue", "Castellano", "Castelleno", "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain", "Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou", "Chabichou du Poitou", "Chabis de Gatine", "Chaource", "Charolais", "Chaumes", "Cheddar", "Cheddar Clothbound", "Cheshire", "Chevres", "Chevrotin des Aravis", "Chontaleno", "Civray", "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby", "Cold Pack", "Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper", "Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)", "Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese", "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza", "Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley", "Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino", "Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo", "Danish Fontina", "Daralagjazsky", "Dauphin", "Delice des Fiouves", "Denhany Dorset Drum", "Derby", "Dessertnyj Belyj", "Devon Blue", "Devon Garland", "Dolcelatte", "Doolin", "Doppelrhamstufel", "Dorset Blue Vinney", "Double Gloucester", "Double Worcester", "Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra", "Dunlop", "Dunsyre Blue", "Duroblando", "Durrus", "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz", "Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne", "Esbareich", "Esrom", "Etorki", "Evansdale Farmhouse Brie", "Evora De L'Alentejo", "Exmoor Blue", "Explorateur", "Feta", "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle", "Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis", "Flor de Guia", "Flower Marie", "Folded", "Folded cheese with mint", "Fondant de Brebis", "Fontainebleau", "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus", "Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison", "Fresh Jack", "Fresh Mozzarella", "Fresh Ricotta", "Fresh Truffles", "Fribourgeois", "Friesekaas", "Friesian", "Friesla", "Frinault", "Fromage a Raclette", "Fromage Corse", "Fromage de Montagne de Savoie", "Fromage Frais", "Fruit Cream Cheese", "Frying Cheese", "Fynbo", "Gabriel", "Galette du Paludier", "Galette Lyonnaise", "Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail", "Garrotxa", "Gastanberra", "Geitost", "Gippsland Blue", "Gjetost", "Gloucester", "Golden Cross", "Gorgonzola", "Gornyaltajski", "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost", "Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel", "Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh", "Greve", "Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny", "Halloumi", "Halloumy (Australian)", "Haloumi-Style Cheese", "Harbourne Blue", "Havarti", "Heidi Gruyere", "Hereford Hop", "Herrgardsost", "Herriot Farmhouse", "Herve", "Hipi Iti", "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster", "Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu", "Isle of Mull", "Jarlsberg", "Jermi Tortes", "Jibneh Arabieh", "Jindi Brie", "Jubilee Blue", "Juustoleipa", "Kadchgall", "Kaseri", "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine", "Kikorangi", "King Island Cape Wickham Brie", "King River Gold", "Klosterkaese", "Knockalara", "Kugelkase", "L'Aveyronnais", "L'Ecir de l'Aubrac", "La Taupiniere", "La Vache Qui Rit", "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire", "Langres", "Lappi", "Laruns", "Lavistown", "Le Brin", "Le Fium Orbo", "Le Lacandou", "Le Roule", "Leafield", "Lebbene", "Leerdammer", "Leicester", "Leyden", "Limburger", "Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer", "Little Rydings", "Livarot", "Llanboidy", "Llanglofan Farmhouse", "Loch Arthur Farmhouse", "Loddiswell Avondale", "Longhorn", "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam", "Macconais", "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego", "Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses", "Maredsous", "Margotin", "Maribo", "Maroilles", "Mascares", "Mascarpone", "Mascarpone (Australian)", "Mascarpone Torta", "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse", "Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)", "Meyer Vintage Gouda", "Mihalic Peynir", "Milleens", "Mimolette", "Mine-Gabhar", "Mini Baby Bells", "Mixte", "Molbo", "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio", "Monterey Jack", "Monterey Jack Dry", "Morbier", "Morbier Cru de Montagne", "Mothais a la Feuille", "Mozzarella", "Mozzarella (Australian)", "Mozzarella di Bufala", "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster", "Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais", "Neufchatel", "Neufchatel (Australian)", "Niolo", "Nokkelost", "Northumberland", "Oaxaca", "Olde York", "Olivet au Foin", "Olivet Bleu", "Olivet Cendre", "Orkney Extra Mature Cheddar", "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty", "Oszczypek", "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer", "Panela", "Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)", "Parmigiano Reggiano", "Pas de l'Escalette", "Passendale", "Pasteurized Processed", "Pate de Fromage", "Patefine Fort", "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac", "Pave du Berry", "Pecorino", "Pecorino in Walnut Leaves", "Pecorino Romano", "Peekskill Pyramid", "Pelardon des Cevennes", "Pelardon des Corbieres", "Penamellera", "Penbryn", "Pencarreg", "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse", "Picodon de Chevre", "Picos de Europa", "Piora", "Pithtviers au Foin", "Plateau de Herve", "Plymouth Cheese", "Podhalanski", "Poivre d'Ane", "Polkolbin", "Pont l'Eveque", "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre", "Pourly", "Prastost", "Pressato", "Prince-Jean", "Processed Cheddar", "Provolone", "Provolone (Australian)", "Pyengana Cheddar", "Pyramide", "Quark", "Quark (Australian)", "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit", "Queso Blanco", "Queso Blanco con Frutas --Pina y Mango", "Queso de Murcia", "Queso del Montsec", "Queso del Tietar", "Queso Fresco", "Queso Fresco (Adobera)", "Queso Iberico", "Queso Jalapeno", "Queso Majorero", "Queso Media Luna", "Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette", "Ragusano", "Raschera", "Reblochon", "Red Leicester", "Regal de la Dombes", "Reggianito", "Remedou", "Requeson", "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata", "Ridder", "Rigotte", "Rocamadour", "Rollot", "Romano", "Romans Part Dieu", "Roncal", "Roquefort", "Roule", "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu", "Saaland Pfarr", "Saanenkaese", "Saga", "Sage Derby", "Sainte Maure", "Saint-Marcellin", "Saint-Nectaire", "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre", "Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza", "Schabzieger", "Schloss", "Selles sur Cher", "Selva", "Serat", "Seriously Strong Cheddar", "Serra da Estrela", "Sharpam", "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene", "Smoked Gouda", "Somerset Brie", "Sonoma Jack", "Sottocenare al Tartufo", "Soumaintrain", "Sourire Lozerien", "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese", "Stilton", "Stinking Bishop", "String", "Sussex Slipcote", "Sveciaost", "Swaledale", "Sweet Style Swiss", "Swiss", "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie", "Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea", "Testouri", "Tete de Moine", "Tetilla", "Texas Goat Cheese", "Tibet", "Tillamook Cheddar", "Tilsit", "Timboon Brie", "Toma", "Tomme Brulee", "Tomme d'Abondance", "Tomme de Chevre", "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans", "Tommes", "Torta del Casar", "Toscanello", "Touree de L'Aubier", "Tourmalet", "Trappe (Veritable)", "Trois Cornes De Vendee", "Tronchon", "Trou du Cru", "Truffe", "Tupi", "Turunmaa", "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa", "Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois", "Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue", "Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington", "Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou", "Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano")
21 |
22 | private fun randomCheeseName(): String = cheeseStrings[RANDOM.nextInt(cheeseStrings.size - 1)]
23 |
24 | fun randomCheese() = Cheese(randomCheeseDrawable(), randomCheeseName())
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/CustomActionsInAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import android.graphics.Point
4 | import android.os.Build
5 | import android.view.View
6 | import android.view.ViewAnimationUtils
7 | import android.view.animation.LinearInterpolator
8 |
9 | import com.commit451.quickactionview.Action
10 | import com.commit451.quickactionview.ActionView
11 | import com.commit451.quickactionview.ActionsInAnimator
12 | import com.commit451.quickactionview.QuickActionView
13 |
14 | /**
15 | * Example of how to create a custom animations in animator
16 | */
17 | class CustomActionsInAnimator(private val quickActionView: QuickActionView) : ActionsInAnimator {
18 |
19 | private val interpolator = LinearInterpolator()
20 |
21 | override fun animateActionIn(action: Action, index: Int, view: ActionView, center: Point) {
22 | view.animate()
23 | .alpha(1.0f)
24 | .setInterpolator(interpolator)
25 | .setDuration(200)
26 | }
27 |
28 | override fun animateIndicatorIn(indicator: View) {
29 | indicator.alpha = 0f
30 | indicator.animate()
31 | .alpha(1f)
32 | .setDuration(200)
33 | }
34 |
35 | override fun animateScrimIn(scrim: View) {
36 | val center = quickActionView.centerPoint
37 | if (Build.VERSION.SDK_INT >= 21 && center != null) {
38 | ViewAnimationUtils.createCircularReveal(scrim, center.x, center.y, 0f, Math.max(scrim.height, scrim.width).toFloat())
39 | .start()
40 | } else {
41 | scrim.alpha = 0f
42 | scrim.animate()
43 | .alpha(1f)
44 | .setDuration(200)
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/CustomActionsTitleAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import android.view.View
4 | import android.view.animation.OvershootInterpolator
5 |
6 | import com.commit451.quickactionview.Action
7 | import com.commit451.quickactionview.ActionsTitleInAnimator
8 | import com.commit451.quickactionview.ActionsTitleOutAnimator
9 |
10 | /**
11 | * Default animator which animates the action title in and out
12 | */
13 | class CustomActionsTitleAnimator : ActionsTitleInAnimator, ActionsTitleOutAnimator {
14 |
15 | companion object {
16 | private const val DURATION = 200L //ms
17 | }
18 |
19 | override fun animateActionTitleIn(action: Action, index: Int, view: View) {
20 | view.alpha = 0.0f
21 | view.scaleX = 0.0f
22 | view.scaleY = 0.0f
23 | view.animate()
24 | .alpha(1.0f)
25 | .scaleX(1.0f)
26 | .scaleY(1.0f)
27 | .setInterpolator(OvershootInterpolator())
28 | .setDuration(DURATION)
29 | }
30 |
31 | override fun animateActionTitleOut(action: Action, index: Int, view: View): Long {
32 | view.animate()
33 | .alpha(0.0f)
34 | .scaleX(0.0f)
35 | .scaleY(0.0f)
36 | .setDuration(DURATION)
37 | return DURATION
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import android.annotation.SuppressLint
4 | import android.graphics.Color
5 | import android.os.Bundle
6 | import android.util.Log
7 | import android.view.View
8 | import androidx.appcompat.app.AppCompatActivity
9 | import androidx.appcompat.widget.Toolbar
10 | import androidx.core.content.ContextCompat
11 | import com.commit451.quickactionview.Action
12 | import com.commit451.quickactionview.QuickActionView
13 | import com.commit451.quickactionview.animator.PopAnimator
14 | import com.google.android.material.snackbar.Snackbar
15 |
16 | /**
17 | * Shows general use of the QuickActionView
18 | */
19 | class MainActivity : AppCompatActivity() {
20 |
21 | companion object {
22 | private const val TAG = "QuickActionView"
23 | }
24 |
25 | private lateinit var root: View
26 |
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | setContentView(R.layout.activity_main)
30 | findViewById(R.id.buttonRecyclerview).setOnClickListener {
31 | startActivity(
32 | RecyclerViewActivity.newIntent(this@MainActivity)
33 | )
34 | }
35 | val toolbar = findViewById(R.id.toolbar)
36 | val normalParent = findViewById(R.id.normalParent)
37 | val customParent = findViewById(R.id.customParent)
38 | root = findViewById(R.id.root)
39 | setSupportActionBar(toolbar)
40 | QuickActionView.make(this)
41 | .addActions(R.menu.actions)
42 | .setOnActionSelectedListener { action, _ -> onAction(action) }
43 | .setOnShowListener { Log.d(TAG, "onShow") }
44 | .setOnDismissListener { Log.d(TAG, "onDismiss") }
45 | .setOnActionHoverChangedListener { _, _, hovering -> Log.d(TAG, "onHover $hovering") }
46 | .register(normalParent)
47 | normalParent.setOnClickListener {
48 | Snackbar.make(root, "View was clicked", Snackbar.LENGTH_SHORT)
49 | .show()
50 | }
51 |
52 | @SuppressLint("ResourceType")
53 | val actionConfig = Action.Config(this)
54 | .setBackgroundColorStateList(
55 | ContextCompat.getColorStateList(
56 | this,
57 | R.drawable.sample_background_color
58 | )!!
59 | )
60 | .setTextColor(Color.MAGENTA)
61 |
62 | val popAnimator = PopAnimator(true)
63 | val actionTitleAnimator = CustomActionsTitleAnimator()
64 | val qav = QuickActionView.make(this)
65 | .addActions(R.menu.actions_2)
66 | .setOnActionSelectedListener { action, _ -> onAction(action) }
67 | .setBackgroundColor(Color.RED)
68 | .setTextColor(Color.BLUE)
69 | .setTextSize(30)
70 | .setScrimColor(Color.parseColor("#99FFFFFF"))
71 | .setTextBackgroundDrawable(R.drawable.text_background)
72 | .setIndicatorDrawable(
73 | ContextCompat.getDrawable(
74 | this@MainActivity,
75 | R.drawable.indicator
76 | )!!
77 | )
78 | .setActionConfig(actionConfig, R.id.action_add_to_cart)
79 | .setActionsOutAnimator(popAnimator)
80 | .setActionsTitleInAnimator(actionTitleAnimator)
81 | .setActionsTitleOutAnimator(actionTitleAnimator)
82 | .register(customParent)
83 | val customActionsInAnimator = CustomActionsInAnimator(qav)
84 | qav.setActionsInAnimator(customActionsInAnimator)
85 | }
86 |
87 | private fun onAction(action: Action) {
88 | Snackbar.make(root, action.title.toString() + " was chosen", Snackbar.LENGTH_SHORT)
89 | .show()
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/com/commit451/quickactionview/sample/RecyclerViewActivity.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.sample
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.appcompat.widget.Toolbar
8 | import androidx.recyclerview.widget.RecyclerView
9 | import com.google.android.material.snackbar.Snackbar
10 |
11 | /**
12 | * Shows usage of the QuickActionView from within a RecyclerView
13 | */
14 | class RecyclerViewActivity : AppCompatActivity() {
15 |
16 | companion object {
17 | fun newIntent(context: Context): Intent {
18 | return Intent(context, RecyclerViewActivity::class.java)
19 | }
20 | }
21 |
22 | private lateinit var adapter: CheeseAdapter
23 |
24 | override fun onCreate(savedInstanceState: Bundle?) {
25 | super.onCreate(savedInstanceState)
26 | setContentView(R.layout.activity_recyclerview)
27 | val toolbar = findViewById(R.id.toolbar)
28 | val recyclerView = findViewById(R.id.recyclerView)
29 | setSupportActionBar(toolbar)
30 | recyclerView.layoutManager = androidx.recyclerview.widget.GridLayoutManager(this, 2)
31 | adapter = CheeseAdapter(this, object : CheeseAdapter.Listener {
32 | override fun onItemClicked(cheese: Cheese) {
33 | Snackbar.make(recyclerView, cheese.name + " was clicked", Snackbar.LENGTH_SHORT)
34 | .show()
35 | }
36 | })
37 | recyclerView.adapter = adapter
38 |
39 | loadCheeses()
40 | }
41 |
42 | private fun loadCheeses() {
43 | val cheeses = mutableListOf()
44 | for (i in 0..29) {
45 | cheeses.add(Cheeses.randomCheese())
46 | }
47 | adapter.setData(cheeses)
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/cheese_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/drawable-nodpi/cheese_1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/cheese_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/drawable-nodpi/cheese_2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/cheese_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/drawable-nodpi/cheese_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/cheese_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/drawable-nodpi/cheese_4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/cheese_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/drawable-nodpi/cheese_5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_favorite_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_shopping_basket_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_shopping_basket_dark_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_thumb_up_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sample_background_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sample_changing_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/text_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
15 |
21 |
22 |
23 |
24 |
29 |
30 |
38 |
39 |
48 |
49 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_cheese.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/actions.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/actions_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 18sp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | QuickActionViewSample
3 | Favorite
4 | Add to cart
5 | Like
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.7.20'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:7.1.3'
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/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 | android.enableJetifier=true
20 | android.useAndroidX=true
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin or MSYS, switch paths to Windows format before running java
129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=`expr $i + 1`
158 | done
159 | case $i in
160 | 0) set -- ;;
161 | 1) set -- "$args0" ;;
162 | 2) set -- "$args0" "$args1" ;;
163 | 3) set -- "$args0" "$args1" "$args2" ;;
164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=`save "$@"`
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | exec "$JAVACMD" "$@"
184 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/quickactionview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/quickactionview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 33
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 33
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 | lintOptions {
21 | abortOnError false
22 | }
23 | }
24 |
25 | dependencies {
26 | api 'androidx.appcompat:appcompat:1.5.1'
27 | }
28 |
--------------------------------------------------------------------------------
/quickactionview/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 /Users/John/Library/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 |
--------------------------------------------------------------------------------
/quickactionview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/Action.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.content.Context
4 | import android.content.res.ColorStateList
5 | import android.graphics.Color
6 | import android.graphics.drawable.Drawable
7 | import androidx.annotation.ColorInt
8 | import androidx.annotation.DrawableRes
9 | import androidx.core.content.ContextCompat
10 |
11 | /**
12 | * Action that can be added to the [QuickActionView]
13 | */
14 | class Action
15 | /**
16 | * Create a new Action, which you add to the QuickActionView with [QuickActionView.addAction]
17 | *
18 | * @param id the action's unique id
19 | * @param icon the drawable icon to display
20 | * @param title the title that appears above the Action button
21 | */
22 | (val id: Int, val icon: Drawable, val title: CharSequence) {
23 |
24 | var config: Config? = null
25 |
26 | init {
27 | if (id == 0) {
28 | throw IllegalArgumentException("Actions must have a non-zero id")
29 | }
30 | }
31 |
32 | /**
33 | * Configuration for the [Action] which controls the visuals.
34 | */
35 | class Config constructor(context: Context) {
36 | internal var backgroundColorStateList: ColorStateList = ColorStateList.valueOf(ColorUtils.getThemeAttrColor(context, R.attr.colorAccent))
37 | internal var textColor: Int = Color.WHITE
38 | @DrawableRes
39 | internal var textBackgroundDrawable: Int = R.drawable.qav_text_background
40 |
41 | fun getBackgroundColorStateList(): ColorStateList {
42 | return backgroundColorStateList
43 | }
44 |
45 | fun setBackgroundColorStateList(backgroundColorStateList: ColorStateList): Config {
46 | this.backgroundColorStateList = backgroundColorStateList
47 | return this
48 | }
49 |
50 | fun setBackgroundColor(@ColorInt backgroundColor: Int): Config {
51 | backgroundColorStateList = ColorStateList.valueOf(backgroundColor)
52 | return this
53 | }
54 |
55 | fun getTextBackgroundDrawable(context: Context): Drawable? {
56 | return if (textBackgroundDrawable != 0) {
57 | ContextCompat.getDrawable(context, textBackgroundDrawable)
58 | } else null
59 | }
60 |
61 | fun setTextBackgroundDrawable(@DrawableRes textBackgroundDrawable: Int): Config {
62 | this.textBackgroundDrawable = textBackgroundDrawable
63 | return this
64 | }
65 |
66 | fun getTextColor(): Int {
67 | return textColor
68 | }
69 |
70 | fun setTextColor(textColor: Int): Config {
71 | this.textColor = textColor
72 | return this
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ActionTitleView.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.annotation.SuppressLint
4 | import android.annotation.TargetApi
5 | import android.content.Context
6 | import android.os.Build
7 | import androidx.appcompat.widget.AppCompatTextView
8 |
9 | /**
10 | * Shows the title of the Action
11 | */
12 | @SuppressLint("ViewConstructor")
13 | internal class ActionTitleView(
14 | context: Context,
15 | private val action: Action,
16 | private val configHelper: ConfigHelper
17 | ) : AppCompatTextView(context) {
18 |
19 | init {
20 | init()
21 | }
22 |
23 | @SuppressLint("NewApi")
24 | private fun init() {
25 | setPadding(configHelper.textPaddingLeft, configHelper.textPaddingTop, configHelper.textPaddingRight, configHelper.textPaddingBottom)
26 | setTextColor(configHelper.textColor)
27 | textSize = configHelper.textSize.toFloat()
28 | if (Build.VERSION.SDK_INT >= 16) {
29 | setBackgroundDrawable(configHelper.getTextBackgroundDrawable(context))
30 | } else {
31 | background = configHelper.getTextBackgroundDrawable(context)
32 | }
33 | text = action.title
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ActionView.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.animation.ValueAnimator
4 | import android.annotation.SuppressLint
5 | import android.content.Context
6 | import android.graphics.Canvas
7 | import android.graphics.Color
8 | import android.graphics.Paint
9 | import android.graphics.Point
10 | import android.graphics.Rect
11 | import android.view.View
12 |
13 | /**
14 | * View that shows the action
15 | */
16 | @SuppressLint("ViewConstructor")
17 | class ActionView(
18 | context: Context,
19 | val action: Action,
20 | private val configHelper: ConfigHelper
21 | ) : View(context), ValueAnimator.AnimatorUpdateListener {
22 |
23 | private var mBackgroundPaint: Paint? = null
24 |
25 | private var mActionCircleRadius: Int = 0
26 | internal var actionCircleRadiusExpanded: Float = 0.toFloat()
27 | private set
28 | private var shadowOffsetY: Float = 0.toFloat()
29 | private var mIconPadding: Int = 0
30 | var interpolation: Float = 0.toFloat()
31 | private var mCurrentAnimator: ValueAnimator? = null
32 | private var mSelected = false
33 | private val mCenter = Point()
34 | private val mTempPoint = Point()
35 |
36 | private val actionState: IntArray
37 | get() = if (mSelected) {
38 | intArrayOf(android.R.attr.state_selected)
39 | } else {
40 | intArrayOf()
41 | }
42 |
43 | private val maxShadowRadius: Float
44 | get() = actionCircleRadiusExpanded / 5.0f
45 |
46 | private val interpolatedRadius: Float
47 | get() = mActionCircleRadius + (actionCircleRadiusExpanded - mActionCircleRadius) * interpolation
48 |
49 | private val currentShadowRadius: Float
50 | get() = interpolatedRadius / 5
51 |
52 | val circleCenterX: Float
53 | get() = actionCircleRadiusExpanded + maxShadowRadius
54 |
55 | val circleCenterY: Float
56 | get() = actionCircleRadiusExpanded + maxShadowRadius - shadowOffsetY
57 |
58 | val circleCenterPoint: Point
59 | get() {
60 | mCenter.set(circleCenterX.toInt(), circleCenterY.toInt())
61 | return mCenter
62 | }
63 |
64 |
65 | init {
66 | init()
67 | }
68 |
69 | private fun init() {
70 | setLayerType(View.LAYER_TYPE_SOFTWARE, null)
71 | mBackgroundPaint = Paint()
72 | mBackgroundPaint!!.isAntiAlias = true
73 | mActionCircleRadius = resources.getDimensionPixelSize(R.dimen.qav_action_view_radius)
74 | actionCircleRadiusExpanded = resources.getDimensionPixelSize(R.dimen.qav_action_view_radius_expanded).toFloat()
75 | shadowOffsetY = resources.getDimensionPixelSize(R.dimen.qav_action_shadow_offset_y).toFloat()
76 | mIconPadding = resources.getDimensionPixelSize(R.dimen.qav_action_view_icon_padding)
77 | }
78 |
79 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
80 | setMeasuredDimension((actionCircleRadiusExpanded * 2 + maxShadowRadius * 2).toInt(), (actionCircleRadiusExpanded * 2 + maxShadowRadius * 2).toInt())
81 | }
82 |
83 | override fun onDraw(canvas: Canvas) {
84 | super.onDraw(canvas)
85 |
86 | action.icon.state = actionState
87 |
88 | val x = circleCenterX
89 | val y = circleCenterY
90 | mBackgroundPaint!!.setShadowLayer(currentShadowRadius, 0f, shadowOffsetY, Color.parseColor("#50000000"))
91 | mBackgroundPaint!!.color = configHelper.backgroundColorStateList.getColorForState(actionState, Color.GRAY)
92 |
93 | canvas.drawCircle(x, y, interpolatedRadius, mBackgroundPaint!!)
94 |
95 | val icon = action.icon
96 |
97 | mTempPoint.x = x.toInt()
98 | mTempPoint.y = y.toInt()
99 | val bounds = getRectInsideCircle(mTempPoint, interpolatedRadius)
100 | bounds.inset(mIconPadding, mIconPadding)
101 |
102 | val aspect = icon.intrinsicWidth / icon.intrinsicHeight.toFloat()
103 | val desiredWidth = Math.min(bounds.width().toFloat(), bounds.height() * aspect).toInt()
104 | val desiredHeight = Math.min(bounds.height().toFloat(), bounds.width() / aspect).toInt()
105 |
106 | bounds.inset((bounds.width() - desiredWidth) / 2, (bounds.height() - desiredHeight) / 2)
107 | icon.bounds = bounds
108 | action.icon.draw(canvas)
109 |
110 | }
111 |
112 |
113 | private fun getRectInsideCircle(center: Point, radius: Float): Rect {
114 | val rect = Rect(0, 0, (radius * 2 / Math.sqrt(2.0)).toInt(), (radius * 2 / Math.sqrt(2.0)).toInt())
115 | rect.offsetTo(center.x - rect.width() / 2, center.y - rect.width() / 2)
116 | return rect
117 | }
118 |
119 | internal fun animateInterpolation(to: Float) {
120 | if (mCurrentAnimator != null && mCurrentAnimator!!.isRunning) {
121 | mCurrentAnimator!!.cancel()
122 | }
123 | mCurrentAnimator = ValueAnimator.ofFloat(interpolation, to)
124 | mCurrentAnimator!!.setDuration(150).addUpdateListener(this)
125 | mCurrentAnimator!!.start()
126 | }
127 |
128 | override fun isSelected(): Boolean {
129 | return mSelected
130 | }
131 |
132 | override fun setSelected(selected: Boolean) {
133 | mSelected = selected
134 | }
135 |
136 | override fun onAnimationUpdate(animation: ValueAnimator) {
137 | interpolation = animation.animatedValue as Float
138 | invalidate()
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ActionsInAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.graphics.Point
4 | import android.view.View
5 |
6 | /**
7 | * Custom animations for QuickActionView animating in
8 | */
9 | interface ActionsInAnimator {
10 |
11 | /**
12 | * Animate in the action view within the QuickActionView
13 | *
14 | * @param action the action
15 | * @param index the index of the action in the list of actions
16 | * @param view the action view to animate
17 | * @param center the final resting center point of the Action
18 | */
19 | fun animateActionIn(action: Action, index: Int, view: ActionView, center: Point)
20 |
21 | /**
22 | * Animate in the indicator as the QuickActionView shows
23 | *
24 | * @param indicator the indicator view
25 | */
26 | fun animateIndicatorIn(indicator: View)
27 |
28 | /**
29 | * Animate in the scrim as the QuickActionView shows
30 | *
31 | * @param scrim the scrim view
32 | */
33 | fun animateScrimIn(scrim: View)
34 | }
35 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ActionsOutAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.graphics.Point
4 | import android.view.View
5 |
6 | /**
7 | * Custom animations for QuickActionView animating out
8 | */
9 | interface ActionsOutAnimator {
10 |
11 | /**
12 | * Animate the action view as the QuickActionView dismisses
13 | *
14 | * @param action The action being animated
15 | * @param index The position of the actionview in its parent
16 | * @param view The action view
17 | * @param center The center of the indicator
18 | * @return The duration of this animation, in milliseconds
19 | */
20 | fun animateActionOut(action: Action, index: Int, view: ActionView, center: Point): Long
21 |
22 | /**
23 | * Animate the indicator view as the QuickActionView dismisses
24 | *
25 | * @param indicator The indicator view
26 | * @return The duration of this animation, in milliseconds
27 | */
28 | fun animateIndicatorOut(indicator: View): Long
29 |
30 | /**
31 | * Animate the scrim as the QuickActionView dismisses
32 | *
33 | * @param scrim The scrimView to animate
34 | * @return The duration of this animation, in milliseconds
35 | */
36 | fun animateScrimOut(scrim: View): Long
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ActionsTitleInAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.view.View
4 |
5 | /**
6 | * Custom animations for an [Action] label animating in
7 | */
8 | interface ActionsTitleInAnimator {
9 |
10 | /**
11 | * Animate the action title view as the QuickActionView action title appears
12 | *
13 | * @param action The action being animated
14 | * @param index The position of the action in its parent
15 | * @param view The action title view
16 | */
17 | fun animateActionTitleIn(action: Action, index: Int, view: View)
18 | }
19 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ActionsTitleOutAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.view.View
4 |
5 | /**
6 | * Custom animations for an [Action] label animating in
7 | */
8 | interface ActionsTitleOutAnimator {
9 |
10 | /**
11 | * Animate the action title view as the QuickActionView action title disappears
12 | *
13 | * @param action The action being animated
14 | * @param index The position of the action in its parent
15 | * @param view The action title view
16 | * @return The duration of this animation, in milliseconds, so that the view can be properly
17 | * hidden when the animation completes
18 | */
19 | fun animateActionTitleOut(action: Action, index: Int, view: View): Long
20 | }
21 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ColorUtils.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.content.Context
4 | import android.util.TypedValue
5 |
6 | /**
7 | * Gets the colors
8 | */
9 | internal object ColorUtils {
10 |
11 | private val typedValue = TypedValue()
12 |
13 | fun getThemeAttrColor(context: Context, attributeColor: Int): Int {
14 | context.theme.resolveAttribute(attributeColor, typedValue, true)
15 | return typedValue.data
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/ConfigHelper.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.content.Context
4 | import android.content.res.ColorStateList
5 | import android.graphics.Typeface
6 | import android.graphics.drawable.Drawable
7 | import androidx.annotation.ColorInt
8 |
9 | /**
10 | * Determines which config to get values from, based on the state of each config.
11 | */
12 | class ConfigHelper(
13 | private val actionConfig: Action.Config?,
14 | private val quickActionViewConfig: QuickActionView.Config
15 | ) {
16 |
17 | val textColor: Int
18 | @ColorInt
19 | get() = if (actionConfig != null && actionConfig.textColor != 0) {
20 | actionConfig.textColor
21 | } else quickActionViewConfig.textColor
22 |
23 |
24 | val backgroundColorStateList: ColorStateList
25 | get() = if (actionConfig?.backgroundColorStateList != null) {
26 | actionConfig.backgroundColorStateList
27 | } else quickActionViewConfig.backgroundColorStateList
28 |
29 | val typeface: Typeface?
30 | get() = quickActionViewConfig.typeface
31 |
32 | val textSize: Int
33 | get() = quickActionViewConfig.textSize
34 |
35 | val textPaddingTop: Int
36 | get() = quickActionViewConfig.textPaddingTop
37 |
38 | val textPaddingBottom: Int
39 | get() = quickActionViewConfig.textPaddingBottom
40 |
41 | val textPaddingLeft: Int
42 | get() = quickActionViewConfig.textPaddingLeft
43 |
44 | val textPaddingRight: Int
45 | get() = quickActionViewConfig.textPaddingRight
46 |
47 | fun getTextBackgroundDrawable(context: Context): Drawable? {
48 | return if (actionConfig?.getTextBackgroundDrawable(context) != null) {
49 | actionConfig.getTextBackgroundDrawable(context)
50 | } else quickActionViewConfig.getTextBackgroundDrawable(context)
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/QuickActionView.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.content.res.ColorStateList
6 | import android.graphics.*
7 | import android.graphics.drawable.Drawable
8 | import android.os.Build
9 | import android.os.Bundle
10 | import android.text.TextUtils
11 | import android.view.*
12 | import android.widget.FrameLayout
13 | import androidx.annotation.ColorInt
14 | import androidx.annotation.DrawableRes
15 | import androidx.annotation.IdRes
16 | import androidx.annotation.MenuRes
17 | import androidx.appcompat.view.menu.MenuBuilder
18 | import androidx.core.content.ContextCompat
19 | import com.commit451.quickactionview.animator.FadeInFadeOutActionsTitleAnimator
20 | import com.commit451.quickactionview.animator.SlideFromCenterAnimator
21 | import java.util.*
22 |
23 | /**
24 | * A QuickActionView, which shows actions when a view is long pressed.
25 | *
26 | * @see [https://github.com/Commit451/QuickActionView](https://github.com/Commit451/QuickActionView)
27 | */
28 | @Suppress("unused")
29 | class QuickActionView private constructor(private val context: Context) {
30 |
31 | companion object {
32 |
33 | /**
34 | * Create a QuickActionView which you can configure as desired, then
35 | * call [.register] to show it.
36 | *
37 | * @param context activity context
38 | * @return the QuickActionView for you to
39 | */
40 | fun make(context: Context): QuickActionView {
41 | return QuickActionView(context)
42 | }
43 | }
44 |
45 | private var shown = false
46 | private var onActionSelectedListener: OnActionSelectedListener? = null
47 | private var onDismissListener: OnDismissListener? = null
48 | private var onShowListener: OnShowListener? = null
49 | private var onActionHoverChangedListener: OnActionHoverChangedListener? = null
50 | private val actionDistance: Float
51 | private val actionPadding: Int
52 | private val actions = mutableListOf()
53 | private var extras: Bundle? = null
54 | private var quickActionViewLayout: QuickActionViewLayout? = null
55 | private val config: Config
56 | private var actionsInAnimator: ActionsInAnimator? = null
57 | private var actionsOutAnimator: ActionsOutAnimator? = null
58 | private var actionsTitleInAnimator: ActionsTitleInAnimator? = null
59 | private var actionsTitleOutAnimator: ActionsTitleOutAnimator? = null
60 |
61 | @ColorInt
62 | private var scrimColor = Color.parseColor("#99000000")
63 | private var indicatorDrawable: Drawable? = null
64 | private val registeredListeners = HashMap()
65 |
66 | /**
67 | * Retrieve the view that has been long pressed
68 | *
69 | * @return the registered view that was long pressed to show the QuickActionView
70 | */
71 | var longPressedView: View? = null
72 | private set
73 |
74 | /**
75 | * Get the center point of the [QuickActionView] aka the point at which the actions will eminate from
76 | *
77 | * @return the center point, or null if the view has not yet been created
78 | */
79 | val centerPoint: Point?
80 | get() = if (quickActionViewLayout != null) {
81 | quickActionViewLayout!!.centerPoint
82 | } else null
83 |
84 | init {
85 | config = Config(context)
86 | indicatorDrawable = ContextCompat.getDrawable(context, R.drawable.qav_indicator)
87 | actionDistance = context.resources.getDimensionPixelSize(R.dimen.qav_action_distance).toFloat()
88 | actionPadding = context.resources.getDimensionPixelSize(R.dimen.qav_action_padding)
89 | val defaultAnimator = SlideFromCenterAnimator(true)
90 | val defaultTitleAnimator = FadeInFadeOutActionsTitleAnimator()
91 | actionsInAnimator = defaultAnimator
92 | actionsOutAnimator = defaultAnimator
93 | actionsTitleInAnimator = defaultTitleAnimator
94 | actionsTitleOutAnimator = defaultTitleAnimator
95 | }
96 |
97 | private fun show(anchor: View, offset: Point) {
98 | if (shown) {
99 | throw RuntimeException("Show cannot be called when the QuickActionView is already visible")
100 | }
101 | shown = true
102 |
103 | val parent = anchor.parent
104 | if (parent is View) {
105 | parent.requestDisallowInterceptTouchEvent(true)
106 | }
107 |
108 | longPressedView = anchor
109 |
110 | val loc = IntArray(2)
111 | anchor.getLocationInWindow(loc)
112 | val point = Point(offset)
113 | point.offset(loc[0], loc[1])
114 | display(point)
115 | }
116 |
117 |
118 | /**
119 | * Register the QuickActionView to appear when the passed view is long pressed
120 | *
121 | * @param view the view to have long press responses
122 | * @return the QuickActionView
123 | */
124 | fun register(view: View): QuickActionView {
125 | val listener = RegisteredListener()
126 | registeredListeners[view] = listener
127 | view.setOnTouchListener(listener)
128 | view.setOnLongClickListener(listener)
129 | return this
130 | }
131 |
132 | /**
133 | * Unregister the view so that it can no longer be long pressed to show the QuickActionView
134 | *
135 | * @param view the view to unregister
136 | */
137 | fun unregister(view: View) {
138 | registeredListeners.remove(view)
139 | view.setOnTouchListener(null)
140 | view.setOnLongClickListener(null)
141 | }
142 |
143 | /**
144 | * Adds an action to the QuickActionView
145 | *
146 | * @param action the action to add
147 | * @return the QuickActionView
148 | */
149 | fun addAction(action: Action): QuickActionView {
150 | checkShown()
151 | actions.add(action)
152 | return this
153 | }
154 |
155 | /**
156 | * Adds a collection of actions to the QuickActionView
157 | *
158 | * @param actions the actions to add
159 | * @return the QuickActionView
160 | */
161 | fun addActions(actions: Collection): QuickActionView {
162 | checkShown()
163 | this.actions.addAll(actions)
164 | return this
165 | }
166 |
167 | /**
168 | * Add actions to the QuickActionView from the given menu resource id.
169 | *
170 | * @param menuId menu resource id
171 | * @return the QuickActionView
172 | */
173 | @SuppressLint("RestrictedApi")
174 | fun addActions(@MenuRes menuId: Int): QuickActionView {
175 | val menu = MenuBuilder(context)
176 | MenuInflater(context).inflate(menuId, menu)
177 | for (i in 0 until menu.size()) {
178 | val item = menu.getItem(i)
179 | val action = Action(item.itemId, item.icon!!, item.title!!)
180 | addAction(action)
181 | }
182 | return this
183 | }
184 |
185 | /**
186 | * Removes all actions from the QuickActionView
187 | *
188 | * @return the QuickActionView
189 | */
190 | fun removeActions(): QuickActionView {
191 | actions.clear()
192 | return this
193 | }
194 |
195 | /**
196 | * Remove an individual action from the QuickActionView
197 | *
198 | * @param actionId the action id
199 | * @return the QuickActionView
200 | */
201 | fun removeAction(actionId: Int): QuickActionView {
202 | for (i in actions.indices) {
203 | if (actions[i].id == actionId) {
204 | actions.removeAt(i)
205 | return this
206 | }
207 | }
208 | throw IllegalArgumentException("No action exists for actionId$actionId")
209 | }
210 |
211 | /**
212 | * @param onActionSelectedListener the listener
213 | * @return the QuickActionView
214 | * @see OnActionSelectedListener
215 | */
216 | fun setOnActionSelectedListener(onActionSelectedListener: OnActionSelectedListener): QuickActionView {
217 | this.onActionSelectedListener = onActionSelectedListener
218 | return this
219 | }
220 |
221 | /**
222 | * @param onDismissListener the listener
223 | * @return the QuickActionView
224 | * @see OnDismissListener
225 | */
226 | fun setOnDismissListener(onDismissListener: OnDismissListener): QuickActionView {
227 | this.onDismissListener = onDismissListener
228 | return this
229 | }
230 |
231 | /**
232 | * @param onShowListener the listener
233 | * @return the QuickActionView
234 | * @see OnShowListener
235 | */
236 | fun setOnShowListener(onShowListener: OnShowListener): QuickActionView {
237 | this.onShowListener = onShowListener
238 | return this
239 | }
240 |
241 | /**
242 | * @param listener the listener
243 | * @return the QuickActionView
244 | * @see OnActionHoverChangedListener
245 | */
246 | fun setOnActionHoverChangedListener(listener: OnActionHoverChangedListener): QuickActionView {
247 | onActionHoverChangedListener = listener
248 | return this
249 | }
250 |
251 | /**
252 | * Set the indicator drawable (the drawable that appears at the point the user has long pressed
253 | *
254 | * @param indicatorDrawable the indicator drawable
255 | * @return the QuickActionView
256 | */
257 | fun setIndicatorDrawable(indicatorDrawable: Drawable): QuickActionView {
258 | this.indicatorDrawable = indicatorDrawable
259 | return this
260 | }
261 |
262 | /**
263 | * Set the scrim color (the background behind the QuickActionView)
264 | *
265 | * @param scrimColor the desired scrim color
266 | * @return the QuickActionView
267 | */
268 | fun setScrimColor(@ColorInt scrimColor: Int): QuickActionView {
269 | this.scrimColor = scrimColor
270 | return this
271 | }
272 |
273 | /**
274 | * Set the drawable that appears behind the Action text labels
275 | *
276 | * @param textBackgroundDrawable the desired drawable
277 | * @return the QuickActionView
278 | */
279 | fun setTextBackgroundDrawable(@DrawableRes textBackgroundDrawable: Int): QuickActionView {
280 | config.setTextBackgroundDrawable(textBackgroundDrawable)
281 | return this
282 | }
283 |
284 |
285 | /**
286 | * Set the background color state list for all action items
287 | *
288 | * @param backgroundColorStateList the desired colorstatelist
289 | * @return the QuickActionView
290 | */
291 | fun setBackgroundColorStateList(backgroundColorStateList: ColorStateList): QuickActionView {
292 | config.backgroundColorStateList = backgroundColorStateList
293 | return this
294 | }
295 |
296 | /**
297 | * Set the text color for the Action labels
298 | *
299 | * @param textColor the desired text color
300 | * @return the QuickActionView
301 | */
302 | fun setTextColor(@ColorInt textColor: Int): QuickActionView {
303 | config.textColor = textColor
304 | return this
305 | }
306 |
307 | /**
308 | * Set the action's background color. If you want to have a pressed state,
309 | * see [.setBackgroundColorStateList]
310 | *
311 | * @param backgroundColor the desired background color
312 | * @return the QuickActionView
313 | */
314 | fun setBackgroundColor(@ColorInt backgroundColor: Int): QuickActionView {
315 | config.setBackgroundColor(backgroundColor)
316 | return this
317 | }
318 |
319 | /**
320 | * Set the typeface for the Action labels
321 | *
322 | * @param typeface the desired typeface
323 | * @return the QuickActionView
324 | */
325 | fun setTypeface(typeface: Typeface): QuickActionView {
326 | config.typeface = typeface
327 | return this
328 | }
329 |
330 | /**
331 | * Set the text size for the Action labels
332 | *
333 | * @param textSize the desired textSize (in pixels)
334 | * @return the QuickActionView
335 | */
336 | fun setTextSize(textSize: Int): QuickActionView {
337 | config.textSize = textSize
338 | return this
339 | }
340 |
341 | /**
342 | * Set the text top padding for the Action labels
343 | *
344 | * @param textPaddingTop the top padding in pixels
345 | * @return the QuickActionView
346 | */
347 | fun setTextPaddingTop(textPaddingTop: Int): QuickActionView {
348 | config.textPaddingTop = textPaddingTop
349 | return this
350 | }
351 |
352 | /**
353 | * Set the text bottom padding for the Action labels
354 | *
355 | * @param textPaddingBottom the top padding in pixels
356 | * @return the QuickActionView
357 | */
358 | fun setTextPaddingBottom(textPaddingBottom: Int): QuickActionView {
359 | config.textPaddingBottom = textPaddingBottom
360 | return this
361 | }
362 |
363 | /**
364 | * Set the text left padding for the Action labels
365 | *
366 | * @param textPaddingLeft the top padding in pixels
367 | * @return the QuickActionView
368 | */
369 | fun setTextPaddingLeft(textPaddingLeft: Int): QuickActionView {
370 | config.textPaddingLeft = textPaddingLeft
371 | return this
372 | }
373 |
374 | /**
375 | * Set the text right padding for the Action labels
376 | *
377 | * @param textPaddingRight the top padding in pixels
378 | * @return the QuickActionView
379 | */
380 | fun setTextPaddingRight(textPaddingRight: Int): QuickActionView {
381 | config.textPaddingRight = textPaddingRight
382 | return this
383 | }
384 |
385 | /**
386 | * Override the animations for when the QuickActionView shows
387 | *
388 | * @param actionsInAnimator the animation overrides
389 | * @return this QuickActionView
390 | */
391 | fun setActionsInAnimator(actionsInAnimator: ActionsInAnimator): QuickActionView {
392 | this.actionsInAnimator = actionsInAnimator
393 | return this
394 | }
395 |
396 | /**
397 | * Override the animations for when the QuickActionView dismisses
398 | *
399 | * @param actionsOutAnimator the animation overrides
400 | * @return this QuickActionView
401 | */
402 | fun setActionsOutAnimator(actionsOutAnimator: ActionsOutAnimator): QuickActionView {
403 | this.actionsOutAnimator = actionsOutAnimator
404 | return this
405 | }
406 |
407 | /**
408 | * Override the animations for when the QuickActionView action title shows
409 | *
410 | * @param actionsTitleInAnimator the custom animator
411 | * @return this QuickActionView
412 | */
413 | fun setActionsTitleInAnimator(actionsTitleInAnimator: ActionsTitleInAnimator): QuickActionView {
414 | this.actionsTitleInAnimator = actionsTitleInAnimator
415 | return this
416 | }
417 |
418 | /**
419 | * Override the animations for when the QuickActionView dismisses
420 | *
421 | * @param actionsTitleOutAnimator the custom animator
422 | * @return this QuickActionView
423 | */
424 | fun setActionsTitleOutAnimator(actionsTitleOutAnimator: ActionsTitleOutAnimator): QuickActionView {
425 | this.actionsTitleOutAnimator = actionsTitleOutAnimator
426 | return this
427 | }
428 |
429 | /**
430 | * Set a custom configuration for the action with the given id
431 | *
432 | * @param config the configuration to attach
433 | * @param actionId the action id
434 | * @return this QuickActionView
435 | */
436 | fun setActionConfig(config: Action.Config, @IdRes actionId: Int): QuickActionView {
437 | for (action in actions) {
438 | if (action.id == actionId) {
439 | action.config = config
440 | return this
441 | }
442 | }
443 |
444 | throw IllegalArgumentException("No Action exists with id $actionId")
445 | }
446 |
447 | private fun display(point: Point) {
448 | if (actions.isEmpty()) {
449 | throw IllegalStateException("You need to give the QuickActionView actions before calling show!")
450 | }
451 |
452 | val manager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
453 | val params = WindowManager.LayoutParams()
454 | params.format = PixelFormat.TRANSLUCENT
455 | params.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
456 | quickActionViewLayout = QuickActionViewLayout(context, actions, point)
457 | manager.addView(quickActionViewLayout, params)
458 | onShowListener?.invoke(this)
459 | }
460 |
461 | private fun animateHide() {
462 | val duration = quickActionViewLayout?.animateOut() ?: 0L
463 | quickActionViewLayout?.postDelayed({ removeView() }, duration)
464 | }
465 |
466 | private fun removeView() {
467 | val quickActionViewLayout = quickActionViewLayout
468 | if (quickActionViewLayout != null) {
469 | val manager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
470 | if (checkAttachedToWindow(quickActionViewLayout)) {
471 | manager.removeView(quickActionViewLayout)
472 | }
473 | this.quickActionViewLayout = null
474 | shown = false
475 | }
476 |
477 |
478 | val parent = longPressedView?.parent
479 | if (parent is View) {
480 | parent.requestDisallowInterceptTouchEvent(false)
481 | }
482 | }
483 |
484 | private fun checkAttachedToWindow(view: View): Boolean {
485 | return if (Build.VERSION.SDK_INT >= 19) {
486 | view.isAttachedToWindow
487 | } else true
488 | //Unfortunately, we have no way of truly knowing on versions less than 19
489 | }
490 |
491 | private fun dismiss() {
492 | if (!shown) {
493 | throw RuntimeException("The QuickActionView must be visible to call dismiss()")
494 | }
495 | onDismissListener?.invoke(this@QuickActionView)
496 | animateHide()
497 | }
498 |
499 | private fun checkShown() {
500 | if (shown) {
501 | throw RuntimeException("QuickActionView cannot be configured if show has already been called.")
502 | }
503 | }
504 |
505 | /**
506 | * Get the extras associated with the QuickActionView. Allows for
507 | * saving state to the QuickActionView
508 | *
509 | * @return the bundle for the QuickActionView
510 | */
511 | fun getExtras(): Bundle? {
512 | return extras
513 | }
514 |
515 | /**
516 | * Set extras to associate with the QuickActionView to allow saving state
517 | *
518 | * @param extras the bundle
519 | * @return the QuickActionView
520 | */
521 | fun setExtras(extras: Bundle): QuickActionView {
522 | this.extras = extras
523 | return this
524 | }
525 |
526 | class Config private constructor(context: Context, var typeface: Typeface?, var textSize: Int, var textPaddingTop: Int) {
527 | private val defaultConfig: Action.Config
528 | var textPaddingBottom: Int = 0
529 | var textPaddingLeft: Int = 0
530 | var textPaddingRight: Int = 0
531 |
532 | var textColor: Int
533 | get() = defaultConfig.textColor
534 | set(@ColorInt textColor) {
535 | defaultConfig.textColor = textColor
536 | }
537 |
538 |
539 | var backgroundColorStateList: ColorStateList
540 | get() = defaultConfig.backgroundColorStateList
541 | set(backgroundColorStateList) {
542 | defaultConfig.backgroundColorStateList = backgroundColorStateList
543 | }
544 |
545 | constructor(context: Context) : this(context, null, context.resources.getInteger(R.integer.qav_action_title_view_text_size), context.resources.getDimensionPixelSize(R.dimen.qav_action_title_view_text_padding))
546 |
547 | init {
548 | textPaddingBottom = textPaddingTop
549 | textPaddingLeft = textPaddingTop
550 | textPaddingRight = textPaddingTop
551 | defaultConfig = Action.Config(context)
552 | }
553 |
554 |
555 | fun getTextBackgroundDrawable(context: Context): Drawable? {
556 | return defaultConfig.getTextBackgroundDrawable(context)
557 | }
558 |
559 | fun setTextBackgroundDrawable(@DrawableRes textBackgroundDrawable: Int) {
560 | defaultConfig.setTextBackgroundDrawable(textBackgroundDrawable)
561 | }
562 |
563 | fun setBackgroundColor(@ColorInt backgroundColor: Int) {
564 | defaultConfig.setBackgroundColor(backgroundColor)
565 | }
566 | }
567 |
568 | /**
569 | * Parent layout that actually houses all of the quick action views
570 | */
571 | private inner class QuickActionViewLayout(context: Context, actions: List, internal val centerPoint: Point) : FrameLayout(context) {
572 | private val indicatorView: View
573 | private val scrimView: View = View(context)
574 | private val actionViews = LinkedHashMap()
575 | private val actionTitleViews = LinkedHashMap()
576 | private val lastTouch = PointF()
577 | private var animated = false
578 |
579 | private val maxActionAngle: Float
580 | get() {
581 | var max = 0f
582 | for ((index, actionView) in actionViews.values.withIndex()) {
583 | max = getActionOffsetAngle(index, actionView)
584 | }
585 | return max
586 | }
587 |
588 | private val middleAngleOffset: Float
589 | get() = maxActionAngle / 2f
590 |
591 | init {
592 | scrimView.setBackgroundColor(scrimColor)
593 | val scrimParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
594 | addView(scrimView, scrimParams)
595 | indicatorView = View(context)
596 | if (Build.VERSION.SDK_INT >= 16) {
597 | indicatorView.background = indicatorDrawable
598 | } else {
599 | indicatorView.setBackgroundDrawable(indicatorDrawable)
600 | }
601 | val indicatorParams = FrameLayout.LayoutParams(indicatorDrawable!!.intrinsicWidth, indicatorDrawable!!.intrinsicHeight)
602 | addView(indicatorView, indicatorParams)
603 | for (action in actions) {
604 | val helper = ConfigHelper(action.config, config)
605 | val actionView = ActionView(context, action, helper)
606 | actionViews[action] = actionView
607 | val params = FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
608 | addView(actionView, params)
609 | if (!TextUtils.isEmpty(action.title)) {
610 | val actionTitleView = ActionTitleView(context, action, helper)
611 | actionTitleView.visibility = View.GONE
612 | actionTitleViews[action] = actionTitleView
613 | val titleParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
614 | addView(actionTitleView, titleParams)
615 | }
616 | }
617 | }
618 |
619 | override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
620 | scrimView.layout(0, 0, measuredWidth, measuredHeight)
621 |
622 | indicatorView.layout(centerPoint.x - (indicatorView.measuredWidth / 2.0).toInt(),
623 | centerPoint.y - (indicatorView.measuredHeight / 2.0).toInt(),
624 | centerPoint.x + (indicatorView.measuredWidth / 2.0).toInt(),
625 | centerPoint.y + (indicatorView.measuredHeight / 2.0).toInt())
626 | var index = 0
627 | for ((action, actionView) in actionViews) {
628 |
629 | val startAngle = getOptimalStartAngle(actionView.actionCircleRadiusExpanded)
630 | val point = getActionPoint(index, startAngle, actionView)
631 | point.offset(-actionView.circleCenterX, -actionView.circleCenterY)
632 | actionView.layout(point.x.toInt(), point.y.toInt(), (point.x + actionView.measuredWidth).toInt(), (point.y + actionView.measuredHeight).toInt())
633 | val titleView = actionTitleViews[action]
634 | if (titleView != null) {
635 | val titleLeft = point.x + actionView.measuredWidth / 2 - titleView.measuredWidth / 2
636 | val titleTop = point.y - 10f - titleView.measuredHeight.toFloat()
637 | titleView.layout(titleLeft.toInt(), titleTop.toInt(), (titleLeft + titleView.measuredWidth).toInt(), (titleTop + titleView.measuredHeight).toInt())
638 | }
639 | index++
640 | }
641 |
642 | if (!animated) {
643 | animateActionsIn()
644 | animateIndicatorIn()
645 | animateScrimIn()
646 | animated = true
647 | }
648 | }
649 |
650 | private fun animateActionsIn() {
651 | for ((index, view) in actionViews.values.withIndex()) {
652 | actionsInAnimator?.animateActionIn(view.action, index, view, centerPoint)
653 | }
654 | }
655 |
656 | private fun animateIndicatorIn() {
657 | actionsInAnimator?.animateIndicatorIn(indicatorView)
658 | }
659 |
660 | private fun animateScrimIn() {
661 | actionsInAnimator?.animateScrimIn(scrimView)
662 | }
663 |
664 | internal fun animateOut(): Long {
665 | var maxDuration = 0L
666 | maxDuration = Math.max(maxDuration, animateActionsOut())
667 | maxDuration = Math.max(maxDuration, animateScrimOut())
668 | maxDuration = Math.max(maxDuration, animateIndicatorOut())
669 | maxDuration = Math.max(maxDuration, animateLabelsOut().toLong())
670 | return maxDuration
671 | }
672 |
673 | private fun animateActionsOut(): Long {
674 | var maxDuration = 0L
675 | for ((index, view) in actionViews.values.withIndex()) {
676 | view.clearAnimation()
677 | maxDuration = Math.max(actionsOutAnimator?.animateActionOut(view.action, index, view, centerPoint) ?: 0L, maxDuration)
678 | }
679 | return maxDuration
680 | }
681 |
682 | private fun animateLabelsOut(): Int {
683 | for (view in actionTitleViews.values) {
684 | view.animate().alpha(0f).duration = 100
685 | }
686 | return 200
687 | }
688 |
689 | private fun animateIndicatorOut(): Long {
690 | indicatorView.clearAnimation()
691 | return actionsOutAnimator!!.animateIndicatorOut(indicatorView)
692 | }
693 |
694 | private fun animateScrimOut(): Long {
695 | scrimView.clearAnimation()
696 | return actionsOutAnimator!!.animateScrimOut(scrimView)
697 | }
698 |
699 | override fun onTouchEvent(event: MotionEvent): Boolean {
700 | if (shown) {
701 | when (event.action) {
702 | MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> {
703 | lastTouch.set(event.rawX, event.rawY)
704 | for ((index, actionView) in actionViews.values.withIndex()) {
705 | if (insideCircle(getActionPoint(index, getOptimalStartAngle(actionView.actionCircleRadiusExpanded), actionView), actionView.actionCircleRadiusExpanded, event.rawX, event.rawY)) {
706 | if (!actionView.isSelected) {
707 | actionView.isSelected = true
708 | actionView.animateInterpolation(1.0f)
709 | val actionTitleView = actionTitleViews[actionView.action]
710 | if (actionTitleView != null) {
711 | actionTitleView.visibility = View.VISIBLE
712 | actionTitleView.bringToFront()
713 | actionsTitleInAnimator!!.animateActionTitleIn(actionView.action, index, actionTitleView)
714 | }
715 | onActionHoverChangedListener?.invoke(actionView.action, this@QuickActionView, true)
716 | }
717 | } else {
718 | if (actionView.isSelected) {
719 | actionView.isSelected = false
720 | actionView.animateInterpolation(0.0f)
721 | val actionTitleView = actionTitleViews[actionView.action]
722 | if (actionTitleView != null) {
723 | val timeTaken = actionsTitleOutAnimator!!.animateActionTitleOut(actionView.action, index, actionTitleView)
724 | actionTitleView.postDelayed({ actionTitleView.visibility = View.GONE }, timeTaken)
725 | }
726 | onActionHoverChangedListener?.invoke(actionView.action, this@QuickActionView, false)
727 | }
728 | }
729 | }
730 | invalidate()
731 | }
732 | MotionEvent.ACTION_UP -> {
733 | for ((key, value) in actionViews) {
734 | if (value.isSelected) {
735 | onActionSelectedListener?.invoke(key, this@QuickActionView)
736 | break
737 | }
738 | }
739 |
740 | dismiss()
741 | }
742 | MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_OUTSIDE -> dismiss()
743 | }
744 | }
745 | return true
746 | }
747 |
748 |
749 | private fun getActionPoint(index: Int, startAngle: Float, view: ActionView): PointF {
750 | val point = PointF(centerPoint)
751 | val angle = (Math.toRadians(startAngle.toDouble()) + getActionOffsetAngle(index, view)).toFloat()
752 | point.offset((Math.cos(angle.toDouble()) * getTotalRadius(view.actionCircleRadiusExpanded)).toInt().toFloat(), (Math.sin(angle.toDouble()) * getTotalRadius(view.actionCircleRadiusExpanded)).toInt().toFloat())
753 | return point
754 | }
755 |
756 | private fun getActionOffsetAngle(index: Int, view: ActionView): Float {
757 | return (index * (2 * Math.atan2((view.actionCircleRadiusExpanded + actionPadding).toDouble(), getTotalRadius(view.actionCircleRadiusExpanded).toDouble()))).toFloat()
758 | }
759 |
760 | private fun getTotalRadius(actionViewRadiusExpanded: Float): Float {
761 | return actionDistance + Math.max(indicatorView.width, indicatorView.height).toFloat() + actionViewRadiusExpanded
762 | }
763 |
764 | private fun getOptimalStartAngle(actionViewRadiusExpanded: Float): Float {
765 | if (measuredWidth > 0) {
766 | val radius = getTotalRadius(actionViewRadiusExpanded)
767 |
768 | val top = -centerPoint.y
769 | val topIntersect = !java.lang.Double.isNaN(Math.acos((top / radius).toDouble()))
770 |
771 | val horizontalOffset = (centerPoint.x - measuredWidth / 2.0f) / (measuredWidth / 2.0f)
772 |
773 | val angle: Float
774 | val offset = Math.pow(Math.abs(horizontalOffset).toDouble(), 1.2).toFloat() * Math.signum(horizontalOffset)
775 | angle = if (topIntersect) {
776 | 90 + 90 * offset
777 | } else {
778 | 270 - 90 * offset
779 | }
780 | normalizeAngle(angle.toDouble())
781 |
782 | return (angle - Math.toDegrees(middleAngleOffset.toDouble())).toFloat()
783 | }
784 | return (270 - Math.toDegrees(middleAngleOffset.toDouble())).toFloat()
785 | }
786 |
787 |
788 | fun normalizeAngle(angleDegrees: Double): Float {
789 | var finalAngleDegrees = angleDegrees
790 | finalAngleDegrees = finalAngleDegrees % 360
791 | finalAngleDegrees = (finalAngleDegrees + 360) % 360
792 | return finalAngleDegrees.toFloat()
793 | }
794 |
795 | private fun insideCircle(center: PointF, radius: Float, x: Float, y: Float): Boolean {
796 | return distance(center, x, y) < radius
797 | }
798 |
799 | private fun distance(point: PointF, x: Float, y: Float): Float {
800 | return Math.sqrt(Math.pow((x - point.x).toDouble(), 2.0) + Math.pow((y - point.y).toDouble(), 2.0)).toFloat()
801 | }
802 | }
803 |
804 | /**
805 | * A class to combine a long click listener and a touch listener, to register views with
806 | */
807 | private inner class RegisteredListener : View.OnLongClickListener, View.OnTouchListener {
808 |
809 | private var touchX: Float = 0.toFloat()
810 | private var touchY: Float = 0.toFloat()
811 |
812 | override fun onLongClick(v: View): Boolean {
813 | show(v, Point(touchX.toInt(), touchY.toInt()))
814 | return false
815 | }
816 |
817 | override fun onTouch(v: View, event: MotionEvent): Boolean {
818 | touchX = event.x
819 | touchY = event.y
820 | if (shown) {
821 | quickActionViewLayout?.onTouchEvent(event)
822 | }
823 | return shown
824 | }
825 | }
826 | }
827 |
828 | /**
829 | * Listener for when an action is selected (hovered, then released)
830 | */
831 | typealias OnActionSelectedListener = (action: Action, quickActionView: QuickActionView) -> Unit
832 |
833 | /**
834 | * Listener for when an action has its hover state changed (hovering or stopped hovering)
835 | */
836 | typealias OnActionHoverChangedListener = (action: Action, quickActionView: QuickActionView, hovering: Boolean) -> Unit
837 |
838 | /**
839 | * Listen for when the QuickActionView is dismissed
840 | */
841 | typealias OnDismissListener = (quickActionView: QuickActionView) -> Unit
842 |
843 | /**
844 | * Listener for when the QuickActionView is shown
845 | */
846 | typealias OnShowListener = (quickActionView: QuickActionView) -> Unit
847 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/animator/FadeAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.animator
2 |
3 | import android.graphics.Point
4 | import android.view.View
5 | import android.view.animation.LinearInterpolator
6 |
7 | import com.commit451.quickactionview.Action
8 | import com.commit451.quickactionview.ActionView
9 | import com.commit451.quickactionview.ActionsInAnimator
10 | import com.commit451.quickactionview.ActionsOutAnimator
11 |
12 | /**
13 | * Fades in the quick actions
14 | */
15 | @Suppress("unused")
16 | class FadeAnimator : ActionsInAnimator, ActionsOutAnimator {
17 |
18 | private val interpolator = LinearInterpolator()
19 |
20 | override fun animateActionIn(action: Action, index: Int, view: ActionView, center: Point) {
21 | view.animate()
22 | .alpha(1.0f)
23 | .setDuration(200).interpolator = interpolator
24 | }
25 |
26 | override fun animateIndicatorIn(indicator: View) {
27 | indicator.alpha = 0f
28 | indicator.animate().alpha(1f).duration = 200
29 | }
30 |
31 | override fun animateScrimIn(scrim: View) {
32 | scrim.alpha = 0f
33 | scrim.animate().alpha(1f).duration = 200
34 | }
35 |
36 | override fun animateActionOut(action: Action, index: Int, view: ActionView, center: Point): Long {
37 | view.animate().scaleX(0.1f)
38 | .scaleY(0.1f)
39 | .alpha(0.0f)
40 | .setStartDelay(0).duration = 200
41 | return 200
42 | }
43 |
44 | override fun animateIndicatorOut(indicator: View): Long {
45 | indicator.animate().alpha(0f).duration = 200
46 | return 200
47 | }
48 |
49 | override fun animateScrimOut(scrim: View): Long {
50 | scrim.animate().alpha(0f).duration = 200
51 | return 200
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/animator/FadeInFadeOutActionsTitleAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.animator
2 |
3 | import android.view.View
4 |
5 | import com.commit451.quickactionview.Action
6 | import com.commit451.quickactionview.ActionsTitleInAnimator
7 | import com.commit451.quickactionview.ActionsTitleOutAnimator
8 |
9 | /**
10 | * Default animator which animates the action title in and out
11 | */
12 | class FadeInFadeOutActionsTitleAnimator @JvmOverloads constructor(
13 | private val duration: Long = 100L
14 | ) : ActionsTitleInAnimator, ActionsTitleOutAnimator {
15 |
16 | override fun animateActionTitleIn(action: Action, index: Int, view: View) {
17 | view.alpha = 0.0f
18 | view.animate()
19 | .alpha(1.0f)
20 | .setDuration(duration)
21 | }
22 |
23 | override fun animateActionTitleOut(action: Action, index: Int, view: View): Long {
24 | view.animate()
25 | .alpha(0.0f)
26 | .setDuration(duration)
27 | return duration
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/animator/PopAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.animator
2 |
3 | import android.graphics.Point
4 | import android.view.View
5 | import android.view.animation.OvershootInterpolator
6 |
7 | import com.commit451.quickactionview.Action
8 | import com.commit451.quickactionview.ActionView
9 | import com.commit451.quickactionview.ActionsInAnimator
10 | import com.commit451.quickactionview.ActionsOutAnimator
11 |
12 | /**
13 | * Animator where actions pop in
14 | */
15 | class PopAnimator @JvmOverloads constructor(
16 | private val staggered: Boolean = false
17 | ) : ActionsInAnimator, ActionsOutAnimator {
18 |
19 | private val interpolator = OvershootInterpolator()
20 |
21 | override fun animateActionIn(action: Action, index: Int, view: ActionView, center: Point) {
22 | view.scaleX = 0.01f
23 | view.scaleY = 0.01f
24 | val viewPropertyAnimator = view.animate().scaleY(1.0f)
25 | .scaleX(1.0f)
26 | .setDuration(200)
27 | .setInterpolator(interpolator)
28 | if (staggered) {
29 | viewPropertyAnimator.startDelay = (index * 100).toLong()
30 | }
31 | }
32 |
33 | override fun animateIndicatorIn(indicator: View) {
34 | indicator.alpha = 0f
35 | indicator.animate().alpha(1f).duration = 200
36 | }
37 |
38 | override fun animateScrimIn(scrim: View) {
39 | scrim.alpha = 0f
40 | scrim.animate().alpha(1f).duration = 200
41 | }
42 |
43 | override fun animateActionOut(action: Action, index: Int, view: ActionView, center: Point): Long {
44 | view.animate().scaleX(0.01f)
45 | .scaleY(0.01f)
46 | .alpha(0.0f)
47 | .setStartDelay(0).duration = 200
48 | return 200
49 | }
50 |
51 | override fun animateIndicatorOut(indicator: View): Long {
52 | indicator.animate().alpha(0f).duration = 200
53 | return 200
54 | }
55 |
56 | override fun animateScrimOut(scrim: View): Long {
57 | scrim.animate().alpha(0f).duration = 200
58 | return 200
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/quickactionview/src/main/java/com/commit451/quickactionview/animator/SlideFromCenterAnimator.kt:
--------------------------------------------------------------------------------
1 | package com.commit451.quickactionview.animator
2 |
3 | import android.graphics.Point
4 | import android.view.View
5 | import android.view.animation.OvershootInterpolator
6 |
7 | import com.commit451.quickactionview.Action
8 | import com.commit451.quickactionview.ActionView
9 | import com.commit451.quickactionview.ActionsInAnimator
10 | import com.commit451.quickactionview.ActionsOutAnimator
11 |
12 | /**
13 | * Animator that slides actions out from the center point. This is the default animation
14 | * a QuickActionView uses
15 | */
16 | class SlideFromCenterAnimator @JvmOverloads constructor(
17 | private val staggered: Boolean = false
18 | ) : ActionsInAnimator, ActionsOutAnimator {
19 |
20 | private val interpolator = OvershootInterpolator()
21 |
22 | override fun animateActionIn(action: Action, index: Int, view: ActionView, center: Point) {
23 | val actionCenter = view.circleCenterPoint
24 | actionCenter.offset(view.left, view.top)
25 | view.translationY = (center.y - actionCenter.y).toFloat()
26 | view.translationX = (center.x - actionCenter.x).toFloat()
27 | val viewPropertyAnimator = view.animate()
28 | .translationX(0f)
29 | .translationY(0f)
30 | .setInterpolator(interpolator)
31 | .setDuration(150)
32 | if (staggered) {
33 | viewPropertyAnimator.startDelay = (index * 100).toLong()
34 | }
35 | }
36 |
37 | override fun animateIndicatorIn(indicator: View) {
38 | indicator.alpha = 0f
39 | indicator.animate()
40 | .alpha(1f)
41 | .setDuration(200)
42 | }
43 |
44 | override fun animateScrimIn(scrim: View) {
45 | scrim.alpha = 0f
46 | scrim.animate()
47 | .alpha(1f)
48 | .setDuration(200)
49 | }
50 |
51 | override fun animateActionOut(action: Action, index: Int, view: ActionView, center: Point): Long {
52 | val actionCenter = view.circleCenterPoint
53 | actionCenter.offset(view.left, view.top)
54 | val translateViewPropertyAnimator = view.animate()
55 | .translationY((center.y - actionCenter.y).toFloat())
56 | .translationX((center.x - actionCenter.x).toFloat())
57 | .setInterpolator(interpolator)
58 | .setStartDelay(0)
59 | .setDuration(150)
60 |
61 | val alphaViewPropertyAnimator = view.animate()
62 | .alpha(0f)
63 | .setStartDelay(0)
64 | .setDuration(150)
65 | if (staggered) {
66 | translateViewPropertyAnimator.startDelay = (index * 100).toLong()
67 | alphaViewPropertyAnimator.startDelay = (index * 100).toLong()
68 | }
69 |
70 | return index * 100L + 150L
71 | }
72 |
73 | override fun animateIndicatorOut(indicator: View): Long {
74 | indicator.animate()
75 | .alpha(0f)
76 | .setDuration(200L)
77 | return 200L
78 | }
79 |
80 | override fun animateScrimOut(scrim: View): Long {
81 | scrim.animate()
82 | .alpha(0f)
83 | .setDuration(200)
84 | return 200L
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/quickactionview/src/main/res/drawable/qav_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/quickactionview/src/main/res/drawable/qav_text_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/quickactionview/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 14
4 | 4dp
5 | 28dp
6 | 32dp
7 | 8dp
8 | 20dp
9 | 4dp
10 | 3dp
11 |
--------------------------------------------------------------------------------
/screenshots/qav.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Commit451/QuickActionView/72db4a0037f88bea7bb8f77d37d32f59c0c50365/screenshots/qav.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':quickactionview'
2 |
--------------------------------------------------------------------------------