v0.85.1: andTunes 0.4.1 — a speaker's volume shows as a bar on the right edge instead of a toast
This commit is contained in:
@@ -25,7 +25,6 @@ import android.widget.TextView;
|
||||
abstract class BaseActivity extends Activity implements PlaybackService.Listener {
|
||||
protected AudioManager audio;
|
||||
private TextView nowBar;
|
||||
private static android.widget.Toast volumeToast;
|
||||
|
||||
@Override protected void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
@@ -109,12 +108,7 @@ abstract class BaseActivity extends Activity implements PlaybackService.Listener
|
||||
if (r != null) {
|
||||
float level = Math.max(0f, Math.min(1f, r.volume() + dir * 0.05f));
|
||||
r.setVolume(level);
|
||||
// One toast, rewritten: a spin of the wheel would queue dozens.
|
||||
if (volumeToast != null) volumeToast.cancel();
|
||||
volumeToast = android.widget.Toast.makeText(getApplicationContext(),
|
||||
r.name() + " volume " + Math.round(level * 100) + "%",
|
||||
android.widget.Toast.LENGTH_SHORT);
|
||||
volumeToast.show();
|
||||
VolumeBar.show(this, level);
|
||||
return;
|
||||
}
|
||||
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package me.teafry.andtunes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
/**
|
||||
* A speaker's volume while the wheel turns it: a pill along the right edge,
|
||||
* black from the bottom up to the level and white above, with a black border.
|
||||
* Full is all black, silent all white. It shows only while the volume is being
|
||||
* adjusted and goes away a moment after the wheel stops.
|
||||
*/
|
||||
final class VolumeBar extends View {
|
||||
private static final long HIDE_AFTER_MS = 1200;
|
||||
|
||||
private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private final Paint border = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private final RectF pill = new RectF();
|
||||
private final Path clip = new Path();
|
||||
private final Runnable hide = () -> setVisibility(GONE);
|
||||
private float level;
|
||||
|
||||
private VolumeBar(Context c) {
|
||||
super(c);
|
||||
border.setStyle(Paint.Style.STROKE);
|
||||
border.setStrokeWidth(Ui.dp(c, 3));
|
||||
border.setColor(Ui.BLACK);
|
||||
fill.setStyle(Paint.Style.FILL);
|
||||
setVisibility(GONE);
|
||||
}
|
||||
|
||||
/** Show {@code level} (0..1) over {@code a}, adding the bar to it if needed. */
|
||||
static void show(Activity a, float level) {
|
||||
ViewGroup content = a.findViewById(android.R.id.content);
|
||||
if (content == null) return;
|
||||
VolumeBar bar = null;
|
||||
for (int i = 0; i < content.getChildCount(); i++) {
|
||||
if (content.getChildAt(i) instanceof VolumeBar) bar = (VolumeBar) content.getChildAt(i);
|
||||
}
|
||||
if (bar == null) {
|
||||
bar = new VolumeBar(a);
|
||||
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
|
||||
Ui.dp(a, 36), Ui.dp(a, 400), Gravity.END | Gravity.CENTER_VERTICAL);
|
||||
lp.rightMargin = Ui.dp(a, 16);
|
||||
content.addView(bar, lp);
|
||||
}
|
||||
bar.update(level);
|
||||
}
|
||||
|
||||
private void update(float l) {
|
||||
level = Math.max(0f, Math.min(1f, l));
|
||||
bringToFront();
|
||||
setVisibility(VISIBLE);
|
||||
invalidate();
|
||||
removeCallbacks(hide);
|
||||
postDelayed(hide, HIDE_AFTER_MS);
|
||||
}
|
||||
|
||||
@Override protected void onDraw(Canvas canvas) {
|
||||
float inset = border.getStrokeWidth() / 2f;
|
||||
pill.set(inset, inset, getWidth() - inset, getHeight() - inset);
|
||||
float r = pill.width() / 2f;
|
||||
clip.reset();
|
||||
clip.addRoundRect(pill, r, r, Path.Direction.CW);
|
||||
|
||||
canvas.save();
|
||||
canvas.clipPath(clip);
|
||||
fill.setColor(Ui.WHITE);
|
||||
canvas.drawRect(pill, fill);
|
||||
float top = pill.bottom - pill.height() * level;
|
||||
fill.setColor(Ui.BLACK);
|
||||
canvas.drawRect(pill.left, top, pill.right, pill.bottom, fill);
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawRoundRect(pill, r, r, border);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -26,8 +26,8 @@ import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
VERSION_NAME = "0.4.0"
|
||||
VERSION_CODE = 7
|
||||
VERSION_NAME = "0.4.1"
|
||||
VERSION_CODE = 8
|
||||
|
||||
PACKAGE = "me.teafry.andtunes"
|
||||
MIN_SDK = 26
|
||||
|
||||
Reference in New Issue
Block a user