Added animated play button
Drawables need to be defined in the app module, which has the vector compat library enabled. When enabling the library for the core module, the app breaks on API 19.
This commit is contained in:
parent
8768144c91
commit
f1cba8042f
@ -6,7 +6,6 @@ import android.util.Log;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -5,11 +5,13 @@ import android.util.AttributeSet;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.AppCompatImageButton;
|
import androidx.appcompat.widget.AppCompatImageButton;
|
||||||
|
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||||
|
|
||||||
public class PlayButton extends AppCompatImageButton {
|
public class PlayButton extends AppCompatImageButton {
|
||||||
private boolean isVideoScreen;
|
private boolean isShowPlay = true;
|
||||||
|
private boolean isVideoScreen = false;
|
||||||
|
|
||||||
public PlayButton(@NonNull Context context) {
|
public PlayButton(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -28,11 +30,25 @@ public class PlayButton extends AppCompatImageButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setIsShowPlay(boolean showPlay) {
|
public void setIsShowPlay(boolean showPlay) {
|
||||||
setContentDescription(getContext().getString(showPlay ? R.string.play_label : R.string.pause_label));
|
if (this.isShowPlay != showPlay) {
|
||||||
if (isVideoScreen) {
|
this.isShowPlay = showPlay;
|
||||||
setImageResource(showPlay ? R.drawable.ic_av_play_white_80dp : R.drawable.ic_av_pause_white_80dp);
|
setContentDescription(getContext().getString(showPlay ? R.string.play_label : R.string.pause_label));
|
||||||
} else {
|
if (isVideoScreen) {
|
||||||
setImageResource(ThemeUtils.getDrawableFromAttr(getContext(), showPlay ? R.attr.av_play : R.attr.av_pause));
|
setImageResource(showPlay ? R.drawable.ic_av_play_white_80dp : R.drawable.ic_av_pause_white_80dp);
|
||||||
|
} else if (!isShown()) {
|
||||||
|
setImageResource(ThemeUtils.getDrawableFromAttr(getContext(),
|
||||||
|
showPlay ? R.attr.av_play : R.attr.av_pause));
|
||||||
|
} else if (showPlay) {
|
||||||
|
AnimatedVectorDrawableCompat drawable = AnimatedVectorDrawableCompat.create(
|
||||||
|
getContext(), R.drawable.ic_animate_pause_play);
|
||||||
|
setImageDrawable(drawable);
|
||||||
|
drawable.start();
|
||||||
|
} else {
|
||||||
|
AnimatedVectorDrawableCompat drawable = AnimatedVectorDrawableCompat.create(
|
||||||
|
getContext(), R.drawable.ic_animate_play_pause);
|
||||||
|
setImageDrawable(drawable);
|
||||||
|
drawable.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
app/src/main/res/drawable/ic_animate_pause_play.xml
Normal file
27
app/src/main/res/drawable/ic_animate_pause_play.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<animated-vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:drawable="@drawable/ic_animate_play"
|
||||||
|
tools:ignore="NewApi">
|
||||||
|
<target android:name="path">
|
||||||
|
<aapt:attr name="android:animation">
|
||||||
|
<objectAnimator
|
||||||
|
android:duration="@integer/fragment_transition_duration"
|
||||||
|
android:propertyName="pathData"
|
||||||
|
android:valueFrom="@string/svg_animatable_pause"
|
||||||
|
android:valueTo="@string/svg_animatable_play"
|
||||||
|
android:valueType="pathType"/>
|
||||||
|
</aapt:attr>
|
||||||
|
</target>
|
||||||
|
<target android:name="group">
|
||||||
|
<aapt:attr name="android:animation">
|
||||||
|
<objectAnimator
|
||||||
|
android:duration="@integer/fragment_transition_duration"
|
||||||
|
android:propertyName="rotation"
|
||||||
|
android:valueFrom="-90"
|
||||||
|
android:valueTo="0"/>
|
||||||
|
</aapt:attr>
|
||||||
|
</target>
|
||||||
|
</animated-vector>
|
14
app/src/main/res/drawable/ic_animate_play.xml
Normal file
14
app/src/main/res/drawable/ic_animate_play.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:viewportWidth="24.0">
|
||||||
|
<group android:name="group"
|
||||||
|
android:pivotX="12"
|
||||||
|
android:pivotY="12">
|
||||||
|
<path android:name="path"
|
||||||
|
android:fillColor="?attr/action_icon_color"
|
||||||
|
android:pathData="@string/svg_animatable_play"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
27
app/src/main/res/drawable/ic_animate_play_pause.xml
Normal file
27
app/src/main/res/drawable/ic_animate_play_pause.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<animated-vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:drawable="@drawable/ic_animate_play"
|
||||||
|
tools:ignore="NewApi">
|
||||||
|
<target android:name="path">
|
||||||
|
<aapt:attr name="android:animation">
|
||||||
|
<objectAnimator
|
||||||
|
android:duration="@integer/fragment_transition_duration"
|
||||||
|
android:propertyName="pathData"
|
||||||
|
android:valueFrom="@string/svg_animatable_play"
|
||||||
|
android:valueTo="@string/svg_animatable_pause"
|
||||||
|
android:valueType="pathType"/>
|
||||||
|
</aapt:attr>
|
||||||
|
</target>
|
||||||
|
<target android:name="group">
|
||||||
|
<aapt:attr name="android:animation">
|
||||||
|
<objectAnimator
|
||||||
|
android:duration="@integer/fragment_transition_duration"
|
||||||
|
android:propertyName="rotation"
|
||||||
|
android:valueFrom="0"
|
||||||
|
android:valueTo="90"/>
|
||||||
|
</aapt:attr>
|
||||||
|
</target>
|
||||||
|
</animated-vector>
|
5
app/src/main/res/values/svg.xml
Normal file
5
app/src/main/res/values/svg.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="svg_animatable_play" translatable="false">M 8 5 L 8 12 L 19 12 L 19 12 M 8 19 L 8 12 L 19 12 L 19 12</string>
|
||||||
|
<string name="svg_animatable_pause" translatable="false">M 5 6 L 5 10 L 19 10 L 19 6 M 5 18 L 5 14 L 19 14 L 19 18</string>
|
||||||
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user