Skip to content

Commit b6471bf

Browse files
committed
animate the FAB transition between Plus and Event icons
1 parent aba8d71 commit b6471bf

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,17 +909,48 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
909909
}
910910

911911
private fun showExtendedFab() {
912+
animateFabIcon(false)
912913
arrayOf(fab_event_label, fab_extended_overlay, fab_task_icon, fab_task_label).forEach {
913914
it.fadeIn()
914915
}
915916
}
916917

917918
private fun hideExtendedFab() {
919+
animateFabIcon(true)
918920
arrayOf(fab_event_label, fab_extended_overlay, fab_task_icon, fab_task_label).forEach {
919921
it.fadeOut()
920922
}
921923
}
922924

925+
private fun animateFabIcon(showPlus: Boolean) {
926+
val newDrawableId = if (showPlus) {
927+
R.drawable.ic_plus_vector
928+
} else {
929+
R.drawable.ic_today_vector
930+
}
931+
val newDrawable = resources.getColoredDrawableWithColor(newDrawableId, getAdjustedPrimaryColor())
932+
933+
val duration = 75L
934+
var rotation = 90f
935+
if (showPlus) {
936+
rotation *= -1
937+
}
938+
939+
calendar_fab.animate()
940+
.rotationBy(rotation)
941+
.setDuration(duration)
942+
.withEndAction {
943+
calendar_fab.rotation = -rotation
944+
calendar_fab.setImageDrawable(newDrawable)
945+
946+
calendar_fab.animate()
947+
.rotationBy(rotation)
948+
.setDuration(duration)
949+
.start()
950+
}
951+
.start()
952+
}
953+
923954
private fun openNewEvent() {
924955
hideKeyboard()
925956
val lastFragment = currentFragments.last()

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
android:src="@drawable/ic_task_vector"
5555
android:visibility="gone"
5656
app:layout_constraintBottom_toTopOf="@+id/calendar_fab"
57-
app:layout_constraintEnd_toEndOf="@id/calendar_fab"
58-
app:layout_constraintStart_toStartOf="@id/calendar_fab" />
57+
app:layout_constraintEnd_toEndOf="@+id/calendar_fab"
58+
app:layout_constraintStart_toStartOf="@+id/calendar_fab" />
5959

6060
<com.simplemobiletools.commons.views.MyTextView
6161
android:id="@+id/fab_task_label"

0 commit comments

Comments
 (0)