Merge pull request #3785 from ByteHamster/speed-indicator-view
Display fancy speed indicator
This commit is contained in:
commit
78effc90a6
|
@ -84,6 +84,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
|
||||||
}
|
}
|
||||||
String speedStr = new DecimalFormat("0.00").format(speed);
|
String speedStr = new DecimalFormat("0.00").format(speed);
|
||||||
txtvPlaybackSpeed.setText(speedStr);
|
txtvPlaybackSpeed.setText(speedStr);
|
||||||
|
butPlaybackSpeed.setSpeed(speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -59,6 +59,7 @@ import de.danoeh.antennapod.fragment.QueueFragment;
|
||||||
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
||||||
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
||||||
import de.danoeh.antennapod.view.PagerIndicatorView;
|
import de.danoeh.antennapod.view.PagerIndicatorView;
|
||||||
|
import de.danoeh.antennapod.view.PlaybackSpeedIndicatorView;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
@ -91,7 +92,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
||||||
NavListAdapter.SUBSCRIPTION_LIST_TAG
|
NavListAdapter.SUBSCRIPTION_LIST_TAG
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageButton butPlaybackSpeed;
|
PlaybackSpeedIndicatorView butPlaybackSpeed;
|
||||||
TextView txtvPlaybackSpeed;
|
TextView txtvPlaybackSpeed;
|
||||||
ImageButton butCastDisconnect;
|
ImageButton butCastDisconnect;
|
||||||
private DrawerLayout drawerLayout;
|
private DrawerLayout drawerLayout;
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
package de.danoeh.antennapod.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
|
|
||||||
|
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 float angle = VALUE_UNSET;
|
||||||
|
private float targetAngle = 0.5f;
|
||||||
|
private float degreePerFrame = 2;
|
||||||
|
private float paddingArc = 20;
|
||||||
|
private float paddingIndicator = 10;
|
||||||
|
|
||||||
|
public PlaybackSpeedIndicatorView(Context context) {
|
||||||
|
super(context);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackSpeedIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() {
|
||||||
|
int[] colorAttrs = new int[] {R.attr.action_icon_color };
|
||||||
|
TypedArray a = getContext().obtainStyledAttributes(colorAttrs);
|
||||||
|
arcPaint.setColor(a.getColor(0, 0xffffffff));
|
||||||
|
indicatorPaint.setColor(a.getColor(0, 0xffffffff));
|
||||||
|
a.recycle();
|
||||||
|
|
||||||
|
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
|
||||||
|
targetAngle = -maxAnglePerDirection + 2 * maxAnglePerDirection * normalizedValue;
|
||||||
|
if (angle == VALUE_UNSET) {
|
||||||
|
angle = targetAngle;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
RectF arcBounds = new RectF(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) {
|
||||||
|
angle += Math.signum(targetAngle - angle) * Math.min(degreePerFrame, Math.abs(targetAngle - angle));
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -167,7 +167,7 @@
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:clickable="false" />
|
android:clickable="false" />
|
||||||
|
|
||||||
<ImageButton
|
<de.danoeh.antennapod.view.PlaybackSpeedIndicatorView
|
||||||
android:id="@+id/butPlaybackSpeed"
|
android:id="@+id/butPlaybackSpeed"
|
||||||
android:layout_width="@dimen/audioplayer_playercontrols_length"
|
android:layout_width="@dimen/audioplayer_playercontrols_length"
|
||||||
android:layout_height="@dimen/audioplayer_playercontrols_length"
|
android:layout_height="@dimen/audioplayer_playercontrols_length"
|
||||||
|
@ -176,8 +176,6 @@
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:contentDescription="@string/set_playback_speed_label"
|
android:contentDescription="@string/set_playback_speed_label"
|
||||||
app:srcCompat="?attr/av_speed"
|
|
||||||
android:scaleType="fitCenter"
|
|
||||||
tools:srcCompat="@drawable/ic_playback_speed_white_48dp"
|
tools:srcCompat="@drawable/ic_playback_speed_white_48dp"
|
||||||
tools:visibility="gone"
|
tools:visibility="gone"
|
||||||
tools:background="@android:color/holo_green_dark" />
|
tools:background="@android:color/holo_green_dark" />
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
<attr name="nav_drawer_background" format="color"/>
|
<attr name="nav_drawer_background" format="color"/>
|
||||||
<attr name="drawer_activated_color" format="color"/>
|
<attr name="drawer_activated_color" format="color"/>
|
||||||
<attr name="batch_edit_fab_icon" format="reference"/>
|
<attr name="batch_edit_fab_icon" format="reference"/>
|
||||||
|
<attr name="action_icon_color" format="color"/>
|
||||||
|
|
||||||
<declare-styleable name="SquareImageView">
|
<declare-styleable name="SquareImageView">
|
||||||
<attr name="useMinimum" format="boolean" />
|
<attr name="useMinimum" format="boolean" />
|
||||||
|
|
|
@ -70,8 +70,8 @@
|
||||||
<item name="ic_volume_adaption">@drawable/ic_volume_adaption_grey</item>
|
<item name="ic_volume_adaption">@drawable/ic_volume_adaption_grey</item>
|
||||||
<item name="master_switch_background">@color/master_switch_background_light</item>
|
<item name="master_switch_background">@color/master_switch_background_light</item>
|
||||||
<item name="currently_playing_background">@color/highlight_light</item>
|
<item name="currently_playing_background">@color/highlight_light</item>
|
||||||
|
|
||||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||||
|
<item name="action_icon_color">#FF757575</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.AntennaPod.Dark" parent="Theme.Base.AntennaPod.Dark">
|
<style name="Theme.AntennaPod.Dark" parent="Theme.Base.AntennaPod.Dark">
|
||||||
|
@ -146,6 +146,7 @@
|
||||||
<item name="master_switch_background">@color/master_switch_background_dark</item>
|
<item name="master_switch_background">@color/master_switch_background_dark</item>
|
||||||
<item name="currently_playing_background">@color/highlight_dark</item>
|
<item name="currently_playing_background">@color/highlight_dark</item>
|
||||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||||
|
<item name="action_icon_color">@color/white</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.AntennaPod.TrueBlack" parent="Theme.Base.AntennaPod.TrueBlack">
|
<style name="Theme.AntennaPod.TrueBlack" parent="Theme.Base.AntennaPod.TrueBlack">
|
||||||
|
|
Loading…
Reference in New Issue