Skip to content

Commit 6f02363

Browse files
committed
sample: Restore reversible FAB animation
1 parent 7d17908 commit 6f02363

4 files changed

Lines changed: 59 additions & 24 deletions

File tree

sample/src/main/java/me/saket/inboxrecyclerview/sample/inbox/InboxActivity.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package me.saket.inboxrecyclerview.sample.inbox
22

3+
import android.annotation.SuppressLint
34
import android.graphics.Color
45
import android.graphics.drawable.AnimatedVectorDrawable
56
import android.os.Bundle
67
import android.view.View
78
import androidx.appcompat.app.AppCompatActivity
9+
import androidx.appcompat.content.res.AppCompatResources.getDrawable
810
import androidx.recyclerview.widget.LinearLayoutManager
911
import com.google.android.material.floatingactionbutton.FloatingActionButton
1012
import com.jakewharton.rxrelay2.PublishRelay
@@ -17,7 +19,6 @@ import me.saket.inboxrecyclerview.sample.EmailRepository
1719
import me.saket.inboxrecyclerview.sample.R
1820
import me.saket.inboxrecyclerview.sample.about.AboutActivity
1921
import me.saket.inboxrecyclerview.sample.email.EmailThreadFragment
20-
import me.saket.inboxrecyclerview.sample.widgets.ReversibleAnimatedVectorDrawable
2122

2223
class InboxActivity : AppCompatActivity() {
2324

@@ -55,6 +56,7 @@ class InboxActivity : AppCompatActivity() {
5556
}
5657
}
5758

59+
@SuppressLint("CheckResult")
5860
private fun setupThreadList() {
5961
recyclerView.layoutManager = LinearLayoutManager(this)
6062
recyclerView.expandablePage = emailPageLayout
@@ -70,6 +72,7 @@ class InboxActivity : AppCompatActivity() {
7072
}
7173
}
7274

75+
@SuppressLint("CheckResult")
7376
private fun setupThreadPage() {
7477
var threadFragment = supportFragmentManager.findFragmentById(emailPageLayout.id) as EmailThreadFragment?
7578
if (threadFragment == null) {
@@ -90,15 +93,20 @@ class InboxActivity : AppCompatActivity() {
9093
}
9194

9295
private fun setupFab() {
93-
val editToReplyAllIcon = ReversibleAnimatedVectorDrawable(fab.drawable as AnimatedVectorDrawable)
96+
val avd = { iconRes: Int -> getDrawable(this, iconRes) as AnimatedVectorDrawable }
97+
fab.setImageDrawable(avd(R.drawable.avd_edit_to_reply_all))
9498

9599
emailPageLayout.addStateChangeCallbacks(object : SimplePageStateChangeCallbacks() {
96100
override fun onPageAboutToExpand(expandAnimDuration: Long) {
97-
editToReplyAllIcon.play()
101+
val icon = avd(R.drawable.avd_edit_to_reply_all)
102+
fab.setImageDrawable(icon)
103+
icon.start()
98104
}
99105

100106
override fun onPageAboutToCollapse(collapseAnimDuration: Long) {
101-
editToReplyAllIcon.reverse()
107+
val icon = avd(R.drawable.avd_reply_all_to_edit)
108+
fab.setImageDrawable(icon)
109+
icon.start()
102110
}
103111
})
104112
}

sample/src/main/java/me/saket/inboxrecyclerview/sample/widgets/ReversibleAnimatedVectorDrawable.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<animated-vector xmlns:aapt="http://schemas.android.com/aapt"
2+
xmlns:android="http://schemas.android.com/apk/res/android">
3+
<aapt:attr name="android:drawable">
4+
<vector
5+
android:name="vector"
6+
android:width="24dp"
7+
android:height="24dp"
8+
android:viewportHeight="24"
9+
android:viewportWidth="24">
10+
<group
11+
android:name="group"
12+
android:pivotX="12"
13+
android:pivotY="12"
14+
android:rotation="0">
15+
<group android:name="vector_1">
16+
<path
17+
android:name="path"
18+
android:fillColor="#000"
19+
android:pathData="M 3 17.46 L 3 20.5 C 3 20.78 3.22 21 3.5 21 L 6.54 21 C 6.67 21 6.8 20.95 6.89 20.85 L 17.81 9.94 L 14.06 6.19 L 3.15 17.1 C 3.05 17.2 3 17.32 3 17.46 Z M 20.71 7.04 C 21.1 6.65 21.1 6.02 20.71 5.63 L 18.37 3.29 C 17.98 2.9 17.35 2.9 16.96 3.29 L 15.13 5.12 L 18.88 8.87 L 20.71 7.04 Z"
20+
android:strokeWidth="1" />
21+
</group>
22+
</group>
23+
</vector>
24+
</aapt:attr>
25+
<target android:name="path">
26+
<aapt:attr name="android:animation">
27+
<objectAnimator
28+
android:duration="200"
29+
android:interpolator="@android:interpolator/fast_out_slow_in"
30+
android:propertyName="pathData"
31+
android:valueFrom="M 6.69 15.69 C 6.89 15.89 7 16.16 7 16.44 C 7 17.38 5.86 17.86 5.19 17.18 C 3.697 15.687 2.203 14.193 0.71 12.7 C 0.32 12.31 0.32 11.68 0.71 11.29 C 2.203 9.797 3.697 8.303 5.19 6.81 C 5.86 6.14 7 6.62 7 7.56 L 7 7.56 C 7 7.84 6.89 8.11 6.69 8.31 L 3 12 C 4.23 13.23 5.46 14.46 6.69 15.69 M 6.7 12.7 L 11.29 17.29 C 11.92 17.92 13 17.47 13 16.58 L 13 14.9 C 18 14.9 21.5 16.5 24 20 C 23 15 20 10 13 9 L 13 9 L 13 7.41 C 13 6.52 11.92 6.07 11.29 6.7 C 9.76 8.23 8.23 9.76 6.7 11.29 C 6.31 11.68 6.31 12.31 6.7 12.7"
32+
android:valueTo="M 18.88 8.87 C 19.49 8.26 20.1 7.65 20.71 7.04 C 20.71 7.04 20.71 7.04 20.71 7.04 C 21.1 6.65 21.1 6.02 20.71 5.63 C 20.515 5.435 20.32 5.24 20.125 5.045 C 19.93 4.85 19.735 4.655 19.54 4.46 C 19.345 4.265 19.15 4.07 18.955 3.875 L 18.37 3.29 C 17.98 2.9 17.35 2.9 16.96 3.29 L 15.13 5.12 C 16.38 6.37 17.63 7.62 18.88 8.87 M 3 17.46 L 3 20.5 C 3 20.78 3.22 21 3.5 21 L 6.54 21 C 6.605 21 6.67 20.988 6.73 20.962 C 6.79 20.938 6.845 20.9 6.89 20.85 L 17.81 9.94 L 14.06 6.19 C 10.423 9.827 6.787 13.463 3.15 17.1 C 3.05 17.2 3 17.32 3 17.46 C 3 17.46 3 17.46 3 17.46"
33+
android:valueType="pathType" />
34+
</aapt:attr>
35+
</target>
36+
<target android:name="group">
37+
<aapt:attr name="android:animation">
38+
<objectAnimator
39+
android:duration="200"
40+
android:interpolator="@android:interpolator/fast_out_slow_in"
41+
android:propertyName="rotation"
42+
android:valueFrom="360"
43+
android:valueTo="0"
44+
android:valueType="floatType" />
45+
</aapt:attr>
46+
</target>
47+
</animated-vector>

sample/src/main/res/layout/activity_inbox.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
android:id="@+id/inbox_fab"
4242
android:layout_width="wrap_content"
4343
android:layout_height="wrap_content"
44-
android:src="@drawable/avd_edit_to_reply_all"
4544
android:tint="#172629"
4645
app:layout_anchor="@+id/inbox_bottomappbar" />
4746
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)