animate the FAB transition between Plus and Event icons

This commit is contained in:
tibbi 2022-02-27 21:37:23 +01:00
parent aba8d7167e
commit b6471bfaed
2 changed files with 33 additions and 2 deletions

View file

@ -909,17 +909,48 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
private fun showExtendedFab() {
animateFabIcon(false)
arrayOf(fab_event_label, fab_extended_overlay, fab_task_icon, fab_task_label).forEach {
it.fadeIn()
}
}
private fun hideExtendedFab() {
animateFabIcon(true)
arrayOf(fab_event_label, fab_extended_overlay, fab_task_icon, fab_task_label).forEach {
it.fadeOut()
}
}
private fun animateFabIcon(showPlus: Boolean) {
val newDrawableId = if (showPlus) {
R.drawable.ic_plus_vector
} else {
R.drawable.ic_today_vector
}
val newDrawable = resources.getColoredDrawableWithColor(newDrawableId, getAdjustedPrimaryColor())
val duration = 75L
var rotation = 90f
if (showPlus) {
rotation *= -1
}
calendar_fab.animate()
.rotationBy(rotation)
.setDuration(duration)
.withEndAction {
calendar_fab.rotation = -rotation
calendar_fab.setImageDrawable(newDrawable)
calendar_fab.animate()
.rotationBy(rotation)
.setDuration(duration)
.start()
}
.start()
}
private fun openNewEvent() {
hideKeyboard()
val lastFragment = currentFragments.last()

View file

@ -54,8 +54,8 @@
android:src="@drawable/ic_task_vector"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/calendar_fab"
app:layout_constraintEnd_toEndOf="@id/calendar_fab"
app:layout_constraintStart_toStartOf="@id/calendar_fab" />
app:layout_constraintEnd_toEndOf="@+id/calendar_fab"
app:layout_constraintStart_toStartOf="@+id/calendar_fab" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fab_task_label"