PasswordFragment: animate FAB in action mode
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
e5d178ea3c
commit
eb5a30c3a9
3 changed files with 51 additions and 2 deletions
|
@ -13,6 +13,8 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.Animation
|
||||||
|
import android.view.animation.AnimationUtils
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
@ -156,7 +158,7 @@ class PasswordFragment : Fragment() {
|
||||||
// Inflate a menu resource providing context menu items
|
// Inflate a menu resource providing context menu items
|
||||||
mode.menuInflater.inflate(R.menu.context_pass, menu)
|
mode.menuInflater.inflate(R.menu.context_pass, menu)
|
||||||
// hide the fab
|
// hide the fab
|
||||||
binding.fab.visibility = View.GONE
|
animateFab(false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +204,30 @@ class PasswordFragment : Fragment() {
|
||||||
recyclerAdapter.requireSelectionTracker().clearSelection()
|
recyclerAdapter.requireSelectionTracker().clearSelection()
|
||||||
actionMode = null
|
actionMode = null
|
||||||
// show the fab
|
// show the fab
|
||||||
binding.fab.visibility = View.VISIBLE
|
animateFab(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun animateFab(show: Boolean) = with(binding.fab) {
|
||||||
|
val animation = AnimationUtils.loadAnimation(
|
||||||
|
context, if (show) R.anim.scale_up else R.anim.scale_down
|
||||||
|
)
|
||||||
|
animation.setAnimationListener(object : Animation.AnimationListener {
|
||||||
|
override fun onAnimationRepeat(animation: Animation?) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationEnd(animation: Animation?) {
|
||||||
|
if (!show) visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationStart(animation: Animation?) {
|
||||||
|
if (show) visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
animate().rotationBy(if (show) -90f else 90f)
|
||||||
|
.setStartDelay(if (show) 100 else 0)
|
||||||
|
.setDuration(100)
|
||||||
|
.start()
|
||||||
|
startAnimation(animation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
app/src/main/res/anim/scale_down.xml
Normal file
12
app/src/main/res/anim/scale_down.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<scale
|
||||||
|
android:duration="300"
|
||||||
|
android:fromXScale="1.0"
|
||||||
|
android:fromYScale="1.0"
|
||||||
|
android:interpolator="@android:anim/linear_interpolator"
|
||||||
|
android:pivotX="50%"
|
||||||
|
android:pivotY="50%"
|
||||||
|
android:toXScale="0"
|
||||||
|
android:toYScale="0" />
|
||||||
|
</set>
|
12
app/src/main/res/anim/scale_up.xml
Normal file
12
app/src/main/res/anim/scale_up.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<scale
|
||||||
|
android:duration="300"
|
||||||
|
android:fromXScale="0"
|
||||||
|
android:fromYScale="0"
|
||||||
|
android:interpolator="@android:anim/linear_interpolator"
|
||||||
|
android:pivotX="50%"
|
||||||
|
android:pivotY="50%"
|
||||||
|
android:toXScale="1.0"
|
||||||
|
android:toYScale="1.0" />
|
||||||
|
</set>
|
Loading…
Reference in a new issue