Last active
September 4, 2024 05:58
-
-
Save mpost/180bf15676006a50c3f7 to your computer and use it in GitHub Desktop.
This gist demonstrates how to create an animated pause/resume media playback button for Android. It uses animated vector drawables and state transitions to orchestrate the effect. Some background: https://plus.google.com/u/0/+MoritzPost/posts/3EFF8uC7jXv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<color name="action_pause">#FF8F00</color> | |
<color name="action_resume">#43A047</color> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="fillColor" | |
android:valueFrom="@color/action_pause" | |
android:valueTo="@color/action_resume" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android"> | |
<objectAnimator | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="rotation" | |
android:valueFrom="0" | |
android:valueTo="90" /> | |
<objectAnimator | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="translateX" | |
android:valueFrom="0" | |
android:valueTo="8" /> | |
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="pathData" | |
android:valueFrom="@string/drawable_vector_pause_left" | |
android:valueTo="@string/drawable_vector_resume_left" | |
android:valueType="pathType" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="pathData" | |
android:valueFrom="@string/drawable_vector_pause_right" | |
android:valueTo="@string/drawable_vector_resume_right" | |
android:valueType="pathType" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="fillColor" | |
android:valueFrom="@color/action_resume" | |
android:valueTo="@color/action_pause" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android"> | |
<objectAnimator | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="rotation" | |
android:valueFrom="90" | |
android:valueTo="180" /> | |
<objectAnimator | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="translateX" | |
android:valueFrom="8" | |
android:valueTo="0" /> | |
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="pathData" | |
android:valueFrom="@string/drawable_vector_resume_left" | |
android:valueTo="@string/drawable_vector_pause_left" | |
android:valueType="pathType" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="@android:integer/config_longAnimTime" | |
android:propertyName="pathData" | |
android:valueFrom="@string/drawable_vector_resume_right" | |
android:valueTo="@string/drawable_vector_pause_right" | |
android:valueType="pathType" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |
android:width="192dp" | |
android:height="192dp" | |
android:viewportWidth="192" | |
android:viewportHeight="192"> | |
<path | |
android:name="background" | |
android:fillColor="@color/action_pause" | |
android:pathData="l192,0 0,192 -192,0 z" /> | |
<group | |
android:name="rotationGroup" | |
android:pivotX="96" | |
android:pivotY="96"> | |
<path | |
android:name="left" | |
android:fillColor="@android:color/white" | |
android:pathData="@string/drawable_vector_pause_left" /> | |
<path | |
android:name="right" | |
android:fillColor="@android:color/white" | |
android:pathData="@string/drawable_vector_pause_right" /> | |
</group> | |
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android" | |
android:constantSize="true"> | |
<item | |
android:id="@+id/pressed_selected" | |
android:state_selected="true" | |
android:state_pressed="true" | |
android:drawable="@drawable/ic_resume" /> | |
<item | |
android:id="@+id/action_resume_state" | |
android:drawable="@drawable/ic_resume" | |
android:state_selected="true" /> | |
<item | |
android:id="@+id/action_pause_state" | |
android:drawable="@drawable/ic_pause" /> | |
<transition | |
android:fromId="@id/pressed_selected" | |
android:toId="@id/action_resume_state" | |
android:drawable="@drawable/ic_pause_to_ic_resume" /> | |
<transition | |
android:fromId="@id/pressed_selected" | |
android:toId="@id/action_pause_state" | |
android:drawable="@drawable/ic_resume_to_ic_pause" /> | |
</animated-selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" | |
android:drawable="@drawable/ic_pause"> | |
<target | |
android:name="background" | |
android:animation="@anim/drawable_pause_to_resume_background" /> | |
<target | |
android:name="rotationGroup" | |
android:animation="@anim/drawable_pause_to_resume_group" /> | |
<target | |
android:name="left" | |
android:animation="@anim/drawable_pause_to_resume_left" /> | |
<target | |
android:name="right" | |
android:animation="@anim/drawable_pause_to_resume_right" /> | |
</animated-vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |
android:width="192dp" | |
android:height="192dp" | |
android:viewportWidth="192" | |
android:viewportHeight="192"> | |
<path | |
android:name="background" | |
android:fillColor="@color/action_resume" | |
android:pathData="l192,0 0,192 -192,0 z" /> | |
<group | |
android:name="rotationGroup" | |
android:pivotX="96" | |
android:pivotY="96" | |
android:translateX="8" | |
android:rotation="90"> | |
<path | |
android:name="left" | |
android:fillColor="@android:color/white" | |
android:pathData="@string/drawable_vector_resume_left" /> | |
<path | |
android:name="right" | |
android:fillColor="@android:color/white" | |
android:pathData="@string/drawable_vector_resume_right" /> | |
</group> | |
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" | |
android:drawable="@drawable/ic_resume"> | |
<target | |
android:name="background" | |
android:animation="@anim/drawable_resume_to_pause_background" /> | |
<target | |
android:name="rotationGroup" | |
android:animation="@anim/drawable_resume_to_pause_group" /> | |
<target | |
android:name="left" | |
android:animation="@anim/drawable_resume_to_pause_left" /> | |
<target | |
android:name="right" | |
android:animation="@anim/drawable_resume_to_pause_right" /> | |
</animated-vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="drawable_vector_pause_left">M72,64 l16,0 0,64 -16,0 z</string> | |
<string name="drawable_vector_pause_right">M104,64 l16,0 0,64 -16,0 z</string> | |
<string name="drawable_vector_resume_left">M96,64 l0,0 0,64 -40,0 z</string> | |
<string name="drawable_vector_resume_right">M96,64 l0,0 40,64 -40,0 z</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment