Remove animated playback speed button (#7401)

The button is behind the dialog anyway, so nobody can see the animation
This commit is contained in:
ByteHamster 2024-09-14 11:21:15 +02:00 committed by GitHub
parent b776e44717
commit 50fa85882e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 119 deletions

View File

@ -63,7 +63,6 @@ import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.model.playback.Playable;
import de.danoeh.antennapod.playback.cast.CastEnabledActivity;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.common.PlaybackSpeedIndicatorView;
import io.reactivex.Maybe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
@ -79,8 +78,8 @@ public class AudioPlayerFragment extends Fragment implements
public static final int POS_DESCRIPTION = 1;
private static final int NUM_CONTENT_FRAGMENTS = 2;
PlaybackSpeedIndicatorView butPlaybackSpeed;
TextView txtvPlaybackSpeed;
private ImageButton butPlaybackSpeed;
private TextView txtvPlaybackSpeed;
private ViewPager2 pager;
private TextView txtvPosition;
private TextView txtvLength;
@ -245,7 +244,6 @@ public class AudioPlayerFragment extends Fragment implements
public void updatePlaybackSpeedButton(SpeedChangedEvent event) {
String speedStr = new DecimalFormat("0.00").format(event.getNewSpeed());
txtvPlaybackSpeed.setText(speedStr);
butPlaybackSpeed.setSpeed(event.getNewSpeed());
}
private void loadMediaInfo(boolean includingChapters) {

View File

@ -205,17 +205,19 @@
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />
<de.danoeh.antennapod.ui.common.PlaybackSpeedIndicatorView
<ImageButton
android:id="@+id/butPlaybackSpeed"
android:layout_width="@dimen/audioplayer_playercontrols_length"
android:layout_height="@dimen/audioplayer_playercontrols_length"
android:padding="8dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/butRev"
android:layout_toLeftOf="@id/butRev"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/playback_speed"
android:scaleType="fitCenter"
app:foregroundColor="?attr/action_icon_color"
tools:srcCompat="@drawable/ic_playback_speed" />
app:srcCompat="@drawable/ic_playback_speed" />
<TextView
android:id="@+id/txtvPlaybackSpeed"

View File

@ -1,113 +0,0 @@
package de.danoeh.antennapod.ui.common;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
public class PlaybackSpeedIndicatorView extends View {
private static final float DEG_2_RAD = (float) (Math.PI / 180);
private static final float PADDING_ANGLE = 30;
private static final float VALUE_UNSET = -4242;
private final Paint arcPaint = new Paint();
private final Paint indicatorPaint = new Paint();
private final Path trianglePath = new Path();
private final RectF arcBounds = new RectF();
private float angle = VALUE_UNSET;
private float targetAngle = VALUE_UNSET;
private float degreePerFrame = 1.6f;
private float paddingArc = 20;
private float paddingIndicator = 10;
public PlaybackSpeedIndicatorView(Context context) {
super(context);
setup(null);
}
public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setup(attrs);
}
public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setup(attrs);
}
private void setup(@Nullable AttributeSet attrs) {
setSpeed(1.0f); // Set default angle to 1.0
targetAngle = VALUE_UNSET; // Do not move to first value that is set externally
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.PlaybackSpeedIndicatorView);
int color = typedArray.getColor(R.styleable.PlaybackSpeedIndicatorView_foregroundColor, Color.GREEN);
typedArray.recycle();
arcPaint.setColor(color);
indicatorPaint.setColor(color);
arcPaint.setAntiAlias(true);
arcPaint.setStyle(Paint.Style.STROKE);
arcPaint.setStrokeCap(Paint.Cap.ROUND);
indicatorPaint.setAntiAlias(true);
indicatorPaint.setStyle(Paint.Style.FILL);
trianglePath.setFillType(Path.FillType.EVEN_ODD);
}
public void setSpeed(float value) {
float maxAnglePerDirection = 90 + 45 - 2 * paddingArc;
// Speed values above 3 are probably not too common. Cap at 3 for better differentiation
float normalizedValue = Math.min(2.5f, value - 0.5f) / 2.5f; // Linear between 0 and 1
float target = -maxAnglePerDirection + 2 * maxAnglePerDirection * normalizedValue;
if (targetAngle == VALUE_UNSET) {
angle = target;
}
targetAngle = target;
degreePerFrame = Math.abs(targetAngle - angle) / 20;
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
paddingArc = getMeasuredHeight() / 4.5f;
paddingIndicator = getMeasuredHeight() / 6f;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float radiusInnerCircle = getWidth() / 10f;
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, radiusInnerCircle, indicatorPaint);
trianglePath.rewind();
float bigRadius = getHeight() / 2f - paddingIndicator;
trianglePath.moveTo(getWidth() / 2f + (float) (bigRadius * Math.sin((-angle + 180) * DEG_2_RAD)),
getHeight() / 2f + (float) (bigRadius * Math.cos((-angle + 180) * DEG_2_RAD)));
trianglePath.lineTo(getWidth() / 2f + (float) (radiusInnerCircle * Math.sin((-angle + 180 - 90) * DEG_2_RAD)),
getHeight() / 2f + (float) (radiusInnerCircle * Math.cos((-angle + 180 - 90) * DEG_2_RAD)));
trianglePath.lineTo(getWidth() / 2f + (float) (radiusInnerCircle * Math.sin((-angle + 180 + 90) * DEG_2_RAD)),
getHeight() / 2f + (float) (radiusInnerCircle * Math.cos((-angle + 180 + 90) * DEG_2_RAD)));
trianglePath.close();
canvas.drawPath(trianglePath, indicatorPaint);
arcPaint.setStrokeWidth(getHeight() / 15f);
arcBounds.set(paddingArc, paddingArc, getWidth() - paddingArc, getHeight() - paddingArc);
canvas.drawArc(arcBounds, -180 - 45, 90 + 45 + angle - PADDING_ANGLE, false, arcPaint);
canvas.drawArc(arcBounds, -90 + PADDING_ANGLE + angle, 90 + 45 - PADDING_ANGLE - angle, false, arcPaint);
if (Math.abs(angle - targetAngle) > 0.5 && targetAngle != VALUE_UNSET) {
angle += Math.signum(targetAngle - angle) * Math.min(degreePerFrame, Math.abs(targetAngle - angle));
invalidate();
}
}
}