Display fancy speed indicator
This commit is contained in:
parent
2f0c627b15
commit
95f23c837c
@ -73,7 +73,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updatePlaybackSpeedButtonText() {
|
protected void updatePlaybackSpeedButtonText() {
|
||||||
if(butPlaybackSpeed == null) {
|
if (butPlaybackSpeed == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (controller == null) {
|
if (controller == null) {
|
||||||
@ -82,11 +82,12 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float speed = 1.0f;
|
float speed = 1.0f;
|
||||||
if(controller.canSetPlaybackSpeed()) {
|
if (controller.canSetPlaybackSpeed()) {
|
||||||
speed = PlaybackSpeedUtils.getCurrentPlaybackSpeed(controller.getMedia());
|
speed = PlaybackSpeedUtils.getCurrentPlaybackSpeed(controller.getMedia());
|
||||||
}
|
}
|
||||||
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.PlaybackHistoryFragment;
|
|||||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
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.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,101 @@
|
|||||||
|
package de.danoeh.antennapod.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
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 final Paint arcPaint = new Paint();
|
||||||
|
private final Paint indicatorPaint = new Paint();
|
||||||
|
private final Path trianglePath = new Path();
|
||||||
|
float angle = 0;
|
||||||
|
float targetAngle = 0.5f;
|
||||||
|
float degreePerFrame = 2;
|
||||||
|
float paddingArc = 20;
|
||||||
|
float paddingIndicator = 10;
|
||||||
|
double deg2rad = Math.PI / 180;
|
||||||
|
float paddingAngle = 30;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
arcPaint.setAntiAlias(true);
|
||||||
|
arcPaint.setColor(Color.GRAY);
|
||||||
|
arcPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
arcPaint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
|
arcPaint.setStrokeWidth(10);
|
||||||
|
|
||||||
|
indicatorPaint.setAntiAlias(true);
|
||||||
|
indicatorPaint.setColor(Color.GRAY);
|
||||||
|
indicatorPaint.setStyle(Paint.Style.FILL);
|
||||||
|
|
||||||
|
trianglePath.setFillType(Path.FillType.EVEN_ODD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed(float value) {
|
||||||
|
float MAX_ANGLE_PER_DIRECTION = 90+45- 2*paddingArc;
|
||||||
|
if (value >= 1) {
|
||||||
|
targetAngle = MAX_ANGLE_PER_DIRECTION * ((value-1)/3);
|
||||||
|
} else {
|
||||||
|
targetAngle = -MAX_ANGLE_PER_DIRECTION * (1-((value - 0.5f)*2));
|
||||||
|
}
|
||||||
|
degreePerFrame = Math.abs(targetAngle - angle) / 20;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
|
paddingArc = getMeasuredHeight()/5;
|
||||||
|
paddingIndicator = getMeasuredHeight()/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
float radiusInnerCircle = getWidth()/8;
|
||||||
|
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radiusInnerCircle, indicatorPaint);
|
||||||
|
|
||||||
|
trianglePath.rewind();
|
||||||
|
float bigRadius = getHeight() / 2 - paddingIndicator;
|
||||||
|
trianglePath.moveTo(getWidth() / 2 + (float)(bigRadius * Math.sin((-angle + 180) * deg2rad)),
|
||||||
|
getHeight() / 2 + (float)(bigRadius * Math.cos((-angle + 180) * deg2rad)));
|
||||||
|
trianglePath.lineTo(getWidth() / 2 + (float)(radiusInnerCircle * Math.sin((-angle + 180 -90) * deg2rad)),
|
||||||
|
getHeight() / 2 + (float)(radiusInnerCircle * Math.cos((-angle + 180-90) * deg2rad)));
|
||||||
|
trianglePath.lineTo(getWidth() / 2 + (float)(radiusInnerCircle * Math.sin((-angle + 180+90) * deg2rad)),
|
||||||
|
getHeight() / 2 + (float)(radiusInnerCircle * Math.cos((-angle + 180+90) * deg2rad)));
|
||||||
|
trianglePath.close();
|
||||||
|
canvas.drawPath(trianglePath, indicatorPaint);
|
||||||
|
|
||||||
|
RectF arcBounds = new RectF(paddingArc, paddingArc, getWidth()-paddingArc, getHeight()-paddingArc);
|
||||||
|
canvas.drawArc(arcBounds, -180-45, 90+45+angle-paddingAngle, false, arcPaint);
|
||||||
|
canvas.drawArc(arcBounds, -90 + paddingAngle+angle, 90+45 - paddingAngle-angle, false, arcPaint);
|
||||||
|
|
||||||
|
|
||||||
|
if (Math.abs(angle - targetAngle) > 0.5) {
|
||||||
|
angle += Math.signum(targetAngle - angle) * Math.min(degreePerFrame, Math.abs(targetAngle - angle));
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -159,7 +159,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"
|
||||||
@ -167,8 +167,6 @@
|
|||||||
android:layout_toStartOf="@id/butRev"
|
android:layout_toStartOf="@id/butRev"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:contentDescription="@string/set_playback_speed_label"
|
android:contentDescription="@string/set_playback_speed_label"
|
||||||
android:src="?attr/av_speed"
|
|
||||||
android:scaleType="fitCenter"
|
|
||||||
tools:src="@drawable/ic_playback_speed_white_48dp"
|
tools:src="@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" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user