Animated FAB

This commit is contained in:
Karim Abou Zeid 2015-04-03 16:52:58 +02:00
commit 35dbb1ee95
17 changed files with 179 additions and 10 deletions

View file

@ -23,8 +23,8 @@ android {
applicationId "com.kabouzeid.gramophone"
minSdkVersion 16
targetSdkVersion 22
versionCode 9
versionName "0.9.5b"
versionCode 10
versionName "0.9.6b"
}
compileOptions {

View file

@ -1,5 +1,6 @@
package com.kabouzeid.gramophone.ui.activities.base;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.util.Pair;
import android.util.Log;
@ -41,6 +42,9 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
}
private void setUpFab() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
getFab().setImageResource(R.drawable.ic_pause_resume);
}
updateFabState();
final GestureDetector gestureDetector = new GestureDetector(this, new SmallOnGestureListener() {
@Override
@ -76,9 +80,9 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
private void updateFabState() {
if (MusicPlayerRemote.isPlaying()) {
getFab().setImageResource(R.drawable.ic_pause_white_24dp);
setFabPause();
} else {
getFab().setImageResource(R.drawable.ic_play_arrow_white_24dp);
setFabPlay();
}
}
@ -141,20 +145,34 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
public void onMusicRemoteEvent(MusicRemoteEvent event) {
switch (event.getAction()) {
case MusicRemoteEvent.PLAY:
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_white_24dp));
setFabPause();
break;
case MusicRemoteEvent.PAUSE:
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp));
setFabPlay();
break;
case MusicRemoteEvent.RESUME:
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_white_24dp));
setFabPause();
break;
case MusicRemoteEvent.STOP:
getFab().setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp));
setFabPlay();
break;
case MusicRemoteEvent.QUEUE_COMPLETED:
getFab().setImageResource(R.drawable.ic_play_arrow_white_24dp);
setFabPlay();
break;
}
}
private void setFabPlay(){
getFab().setSelected(true);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
getFab().setImageResource(R.drawable.ic_play_arrow_white_24dp);
}
}
private void setFabPause(){
getFab().setSelected(false);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
getFab().setImageResource(R.drawable.ic_pause_white_24dp);
}
}
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="90" />
</set>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="pathData"
android:valueFrom="@string/drawable_vector_pause_left"
android:valueTo="@string/drawable_vector_resume_left"
android:valueType="pathType" />

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="pathData"
android:valueFrom="@string/drawable_vector_pause_right"
android:valueTo="@string/drawable_vector_resume_right"
android:valueType="pathType" />

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="rotation"
android:valueFrom="90"
android:valueTo="180" />
</set>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="pathData"
android:valueFrom="@string/drawable_vector_resume_left"
android:valueTo="@string/drawable_vector_pause_left"
android:valueType="pathType" />

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="pathData"
android:valueFrom="@string/drawable_vector_resume_right"
android:valueTo="@string/drawable_vector_pause_right"
android:valueType="pathType" />

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:name="rotationGroup"
android:pivotX="12"
android:pivotY="12">
<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>

View file

@ -0,0 +1,30 @@
<?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>

View file

@ -0,0 +1,13 @@
<?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="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>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:name="rotationGroup"
android:pivotX="12"
android:pivotY="12"
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>

View file

@ -0,0 +1,13 @@
<?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="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>

View file

@ -24,7 +24,7 @@
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?default_bar_color">
android:background="?card_color">
<LinearLayout
android:layout_width="wrap_content"

View file

@ -19,6 +19,7 @@
<attr name="themed_drawable_activated_color" format="color"/>
<attr name="default_bar_color" format="color"/>
<attr name="card_color" format="color"/>
<attr name="toolbarPopupTheme" format="reference"/>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="drawable_vector_pause_left">M6,5 l4,0 0,14 -4,0 z</string>
<string name="drawable_vector_pause_right">M14,5 l4,0 0,14 -4,0 z</string>
<string name="drawable_vector_resume_left">M12,5 l0,0 0,11 -7,0 z</string>
<string name="drawable_vector_resume_right">M12,5 l0,0 7,11 -7,0 z</string>
</resources>

View file

@ -27,6 +27,7 @@
<item name="themed_drawable_activated_color">@color/materialmusic_dark_themed_drawable_activated_color</item>
<item name="default_bar_color">@color/materialmusic_dark_default_bar_color</item>
<item name="card_color">@color/materialmusic_dark_default_bar_color</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>
@ -60,6 +61,7 @@
<item name="themed_drawable_activated_color">@color/materialmusic_themed_drawable_activated_color</item>
<item name="default_bar_color">@color/materialmusic_default_bar_color</item>
<item name="card_color">@color/white</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>