mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-06 00:32:32 -08:00
Add Toolbar action animation
This commit is contained in:
1 parent
89dd7bfefb
commit
6472601170
2 files changed
+20
-22
No files matched your search
@@ -17,6 +17,7 @@ class ToolbarAction @JvmOverloads constructor(context: Context,
|
||||
|
||||
private var mActionModeCallback: ActionMode.Callback? = null
|
||||
private val actionMode = NodeActionMode(this)
|
||||
private var isOpen = false
|
||||
|
||||
init {
|
||||
visibility = View.GONE
|
||||
@@ -56,13 +57,17 @@ class ToolbarAction @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
|
||||
fun open() {
|
||||
visibility = View.VISIBLE
|
||||
//expand()
|
||||
if (!isOpen) {
|
||||
isOpen = true
|
||||
expand()
|
||||
}
|
||||
}
|
||||
|
||||
fun close() {
|
||||
//collapse()
|
||||
visibility = View.GONE
|
||||
if (isOpen) {
|
||||
isOpen = false
|
||||
collapse()
|
||||
}
|
||||
mActionModeCallback?.onDestroyActionMode(actionMode)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.view
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.Activity
|
||||
@@ -27,6 +26,7 @@ import android.content.pm.ActivityInfo
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
@@ -62,22 +62,17 @@ fun Activity.unlockScreenOrientation() {
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
}
|
||||
|
||||
private var actionBarHeight: Int = 0
|
||||
|
||||
fun Toolbar.collapse(animate: Boolean = true, listener: Animator.AnimatorListener? = null) {
|
||||
|
||||
if (layoutParams.height > 5)
|
||||
actionBarHeight = layoutParams.height
|
||||
|
||||
val slideAnimator = ValueAnimator
|
||||
.ofInt(height, 0)
|
||||
fun Toolbar.collapse(animate: Boolean = true) {
|
||||
val recordBarHeight = layoutParams.height
|
||||
val slideAnimator = ValueAnimator.ofInt(height, 0)
|
||||
if (animate)
|
||||
slideAnimator.duration = 300L
|
||||
listener?.let {
|
||||
slideAnimator.addListener(it)
|
||||
}
|
||||
slideAnimator.addUpdateListener { animation ->
|
||||
layoutParams.height = animation.animatedValue as Int
|
||||
if (layoutParams.height <= 1) {
|
||||
visibility = View.GONE
|
||||
layoutParams.height = recordBarHeight
|
||||
}
|
||||
requestLayout()
|
||||
}
|
||||
AnimatorSet().apply {
|
||||
@@ -86,15 +81,13 @@ fun Toolbar.collapse(animate: Boolean = true, listener: Animator.AnimatorListene
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun Toolbar.expand(animate: Boolean = true, listener: Animator.AnimatorListener? = null) {
|
||||
|
||||
fun Toolbar.expand(animate: Boolean = true) {
|
||||
visibility = View.VISIBLE
|
||||
val actionBarHeight = layoutParams.height
|
||||
val slideAnimator = ValueAnimator
|
||||
.ofInt(0, actionBarHeight)
|
||||
if (animate)
|
||||
slideAnimator.duration = 300L
|
||||
listener?.let {
|
||||
slideAnimator.addListener(it)
|
||||
}
|
||||
slideAnimator.addUpdateListener { animation ->
|
||||
layoutParams.height = animation.animatedValue as Int
|
||||
requestLayout()
|
||||
|
||||
Reference in new issue
Block a user