Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 071c40e

Browse files
committed
Added FAB AnimatedStateList drawable between inbox & details screen
Change-Id: I8e0c74ab63b31a5836cc4dd4314a9b389b0bac2f
1 parent 473e0bb commit 071c40e

File tree

6 files changed

+405
-126
lines changed

6 files changed

+405
-126
lines changed

app/src/main/java/com/materialstudies/reply/ui/MainActivity.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.materialstudies.reply.ui
1818

19-
import android.graphics.drawable.AnimatedVectorDrawable
2019
import android.os.Bundle
2120
import android.view.MenuItem
2221
import android.view.View
@@ -159,11 +158,7 @@ class MainActivity : AppCompatActivity(),
159158

160159
private fun setBottomAppBarForHome(@MenuRes menuRes: Int) {
161160
binding.run {
162-
// TODO(hunterstich) Create ASL which animates back instead of resetting.
163-
(fab.drawable as AnimatedVectorDrawable).apply {
164-
reset()
165-
state = intArrayOf(android.R.attr.state_activated)
166-
}
161+
fab.setImageState(intArrayOf(-android.R.attr.state_activated), true)
167162
bottomAppBar.replaceMenu(menuRes)
168163
fab.contentDescription = getString(R.string.fab_compose_email_content_description)
169164
bottomAppBarTitle.visibility = View.VISIBLE
@@ -174,7 +169,7 @@ class MainActivity : AppCompatActivity(),
174169

175170
private fun setBottomAppBarForEmail(@MenuRes menuRes: Int) {
176171
binding.run {
177-
(fab.drawable as AnimatedVectorDrawable).start()
172+
fab.setImageState(intArrayOf(android.R.attr.state_activated), true)
178173
bottomAppBar.replaceMenu(menuRes)
179174
fab.contentDescription = getString(R.string.fab_reply_email_content_description)
180175
bottomAppBarTitle.visibility = View.INVISIBLE
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (c) 2019 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
in compliance with the License. You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software distributed under the License
11+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
or implied. See the License for the specific language governing permissions and limitations under
13+
the License.
14+
-->
15+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
16+
17+
<item
18+
android:id="@+id/edit"
19+
android:drawable="@drawable/ic_edit_on_secondary"
20+
android:state_activated="false"/>
21+
22+
<item
23+
android:id="@+id/reply"
24+
android:drawable="@drawable/ic_reply_all_on_secondary"
25+
android:state_activated="true"/>
26+
27+
<transition
28+
android:fromId="@id/edit"
29+
android:toId="@id/reply"
30+
android:drawable="@drawable/avd_edit_to_reply"/>
31+
32+
<transition
33+
android:fromId="@id/reply"
34+
android:toId="@id/edit"
35+
android:drawable="@drawable/avd_reply_to_edit"/>
36+
37+
</animated-selector>

app/src/main/res/drawable/avd_edit_reply.xml

Lines changed: 0 additions & 117 deletions
This file was deleted.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<!--
2+
Copyright (c) 2019 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
in compliance with the License. You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software distributed under the License
10+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
or implied. See the License for the specific language governing permissions and limitations under
12+
the License.
13+
-->
14+
<animated-vector
15+
xmlns:android="http://schemas.android.com/apk/res/android"
16+
xmlns:aapt="http://schemas.android.com/aapt">
17+
<aapt:attr name="android:drawable">
18+
<vector
19+
android:name="vector"
20+
android:width="24dp"
21+
android:height="24dp"
22+
android:viewportWidth="24"
23+
android:viewportHeight="24">
24+
<group android:name="group">
25+
<path
26+
android:name="path"
27+
android:pathData="M 3 17.25 L 3 21 L 6.75 21 L 17.81 9.94 L 14.06 6.19 L 3 17.25 Z M 21.41 6.34 L 17.66 2.59 L 15.13 5.13 L 18.88 8.88 L 21.41 6.34 Z"
28+
android:fillColor="#000"
29+
android:strokeWidth="1"/>
30+
</group>
31+
<group android:name="group_1">
32+
<path
33+
android:name="path_1"
34+
android:pathData="M 13 9 L 13 5 L 6 12 L 13 19 L 13 14.9 C 18 14.9 21.5 16.5 24 20 C 23 15 20 10 13 9 Z"
35+
android:fillColor="#000"
36+
android:strokeWidth="1"/>
37+
<group android:name="group_2">
38+
<path
39+
android:name="path_2"
40+
android:pathData="M 7 8 L 7 5 L 0 12 L 7 19 L 7 16 L 3 12 L 7 8 Z"
41+
android:fillColor="#000"
42+
android:strokeWidth="1"/>
43+
</group>
44+
</group>
45+
</vector>
46+
</aapt:attr>
47+
<target android:name="group">
48+
<aapt:attr name="android:animation">
49+
<set>
50+
<objectAnimator
51+
android:propertyName="scaleY"
52+
android:duration="100"
53+
android:valueFrom="1"
54+
android:valueTo="0"
55+
android:valueType="floatType"
56+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
57+
<objectAnimator
58+
android:propertyName="scaleX"
59+
android:duration="100"
60+
android:valueFrom="1"
61+
android:valueTo="0"
62+
android:valueType="floatType"
63+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
64+
<objectAnimator
65+
android:propertyName="pivotX"
66+
android:duration="100"
67+
android:valueFrom="12"
68+
android:valueTo="12"
69+
android:valueType="floatType"
70+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
71+
<objectAnimator
72+
android:propertyName="pivotY"
73+
android:duration="100"
74+
android:valueFrom="12"
75+
android:valueTo="12"
76+
android:valueType="floatType"
77+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
78+
</set>
79+
</aapt:attr>
80+
</target>
81+
<target android:name="group_1">
82+
<aapt:attr name="android:animation">
83+
<set>
84+
<objectAnimator
85+
android:propertyName="scaleX"
86+
android:startOffset="100"
87+
android:duration="200"
88+
android:valueFrom="0"
89+
android:valueTo="1"
90+
android:valueType="floatType"
91+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
92+
<objectAnimator
93+
android:propertyName="scaleY"
94+
android:startOffset="100"
95+
android:duration="200"
96+
android:valueFrom="0"
97+
android:valueTo="1"
98+
android:valueType="floatType"
99+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
100+
<objectAnimator
101+
android:propertyName="pivotX"
102+
android:startOffset="100"
103+
android:duration="200"
104+
android:valueFrom="22"
105+
android:valueTo="22"
106+
android:valueType="floatType"
107+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
108+
<objectAnimator
109+
android:propertyName="pivotY"
110+
android:startOffset="100"
111+
android:duration="200"
112+
android:valueFrom="16"
113+
android:valueTo="16"
114+
android:valueType="floatType"
115+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
116+
<objectAnimator
117+
android:propertyName="rotation"
118+
android:startOffset="100"
119+
android:duration="177"
120+
android:valueFrom="30"
121+
android:valueTo="0"
122+
android:valueType="floatType"
123+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
124+
<objectAnimator
125+
android:propertyName="translateY"
126+
android:duration="300"
127+
android:valueFrom="-0.8"
128+
android:valueTo="-0.8"
129+
android:valueType="floatType"
130+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
131+
</set>
132+
</aapt:attr>
133+
</target>
134+
<target android:name="path_1">
135+
<aapt:attr name="android:animation">
136+
<set>
137+
<objectAnimator
138+
android:propertyName="fillAlpha"
139+
android:duration="100"
140+
android:valueFrom="0"
141+
android:valueTo="0"
142+
android:valueType="floatType"
143+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
144+
<objectAnimator
145+
android:propertyName="fillAlpha"
146+
android:startOffset="100"
147+
android:duration="200"
148+
android:valueFrom="1"
149+
android:valueTo="1"
150+
android:valueType="floatType"
151+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
152+
</set>
153+
</aapt:attr>
154+
</target>
155+
<target android:name="path_2">
156+
<aapt:attr name="android:animation">
157+
<set>
158+
<objectAnimator
159+
android:propertyName="fillAlpha"
160+
android:duration="188"
161+
android:valueFrom="0"
162+
android:valueTo="0"
163+
android:valueType="floatType"
164+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
165+
<objectAnimator
166+
android:propertyName="fillAlpha"
167+
android:startOffset="188"
168+
android:duration="112"
169+
android:valueFrom="1"
170+
android:valueTo="1"
171+
android:valueType="floatType"
172+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
173+
</set>
174+
</aapt:attr>
175+
</target>
176+
<target android:name="group_2">
177+
<aapt:attr name="android:animation">
178+
<objectAnimator
179+
android:propertyName="translateX"
180+
android:startOffset="105"
181+
android:duration="195"
182+
android:valueFrom="15"
183+
android:valueTo="0"
184+
android:valueType="floatType"
185+
android:interpolator="@android:interpolator/fast_out_slow_in"/>
186+
</aapt:attr>
187+
</target>
188+
</animated-vector>

0 commit comments

Comments
 (0)