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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
|
|
@ -5,11 +5,13 @@ import android.util.AttributeSet;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||
|
||||
public class PlayButton extends AppCompatImageButton {
|
||||
private boolean isVideoScreen;
|
||||
private boolean isShowPlay = true;
|
||||
private boolean isVideoScreen = false;
|
||||
|
||||
public PlayButton(@NonNull Context context) {
|
||||
super(context);
|
||||
|
@ -28,11 +30,25 @@ public class PlayButton extends AppCompatImageButton {
|
|||
}
|
||||
|
||||
public void setIsShowPlay(boolean showPlay) {
|
||||
setContentDescription(getContext().getString(showPlay ? R.string.play_label : R.string.pause_label));
|
||||
if (isVideoScreen) {
|
||||
setImageResource(showPlay ? R.drawable.ic_av_play_white_80dp : R.drawable.ic_av_pause_white_80dp);
|
||||
} else {
|
||||
setImageResource(ThemeUtils.getDrawableFromAttr(getContext(), showPlay ? R.attr.av_play : R.attr.av_pause));
|
||||
if (this.isShowPlay != showPlay) {
|
||||
this.isShowPlay = showPlay;
|
||||
setContentDescription(getContext().getString(showPlay ? R.string.play_label : R.string.pause_label));
|
||||
if (isVideoScreen) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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…
Reference in New Issue