From 72b85f247269f3038a3498995a97ade748f773d9 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 22 Mar 2020 23:14:59 +0100 Subject: Do not rotate speed indicator if setSpeed is never called --- .../danoeh/antennapod/view/PlaybackSpeedIndicatorView.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/src/main/java/de/danoeh/antennapod/view/PlaybackSpeedIndicatorView.java b/app/src/main/java/de/danoeh/antennapod/view/PlaybackSpeedIndicatorView.java index d5c4e3c6d..52c6e5375 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/PlaybackSpeedIndicatorView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/PlaybackSpeedIndicatorView.java @@ -20,7 +20,7 @@ public class PlaybackSpeedIndicatorView extends View { private final Paint indicatorPaint = new Paint(); private final Path trianglePath = new Path(); private float angle = VALUE_UNSET; - private float targetAngle = 0.5f; + private float targetAngle = VALUE_UNSET; private float degreePerFrame = 2; private float paddingArc = 20; private float paddingIndicator = 10; @@ -41,6 +41,9 @@ public class PlaybackSpeedIndicatorView extends View { } private void setup() { + setSpeed(1.0f); // Set default angle to 1.0 + targetAngle = VALUE_UNSET; // Do not move to first value that is set externally + int[] colorAttrs = new int[] {R.attr.action_icon_color }; TypedArray a = getContext().obtainStyledAttributes(colorAttrs); arcPaint.setColor(a.getColor(0, 0xffffffff)); @@ -61,10 +64,11 @@ public class PlaybackSpeedIndicatorView extends View { 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 - targetAngle = -maxAnglePerDirection + 2 * maxAnglePerDirection * normalizedValue; - if (angle == VALUE_UNSET) { - angle = targetAngle; + float target = -maxAnglePerDirection + 2 * maxAnglePerDirection * normalizedValue; + if (targetAngle == VALUE_UNSET) { + angle = target; } + targetAngle = target; degreePerFrame = Math.abs(targetAngle - angle) / 20; invalidate(); } @@ -100,7 +104,7 @@ public class PlaybackSpeedIndicatorView extends View { 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) { + if (Math.abs(angle - targetAngle) > 0.5 && targetAngle != VALUE_UNSET) { angle += Math.signum(targetAngle - angle) * Math.min(degreePerFrame, Math.abs(targetAngle - angle)); invalidate(); } -- cgit v1.2.3