From 9b78d4c3f39b085184ae54e88b22fb71f3fc13a3 Mon Sep 17 00:00:00 2001
From: Nicolas Araujo <63880378+nicoolasj@users.noreply.github.com>
Date: Sun, 24 Apr 2022 17:36:37 -0300
Subject: [PATCH] Put playback speed in widget (#5774)
---
app/src/main/AndroidManifest.xml | 11 ++
.../activity/PlaybackSpeedDialogActivity.java | 29 ++++
.../activity/WidgetConfigActivity.java | 9 +-
.../res/layout/activity_widget_config.xml | 154 ++++++++++--------
.../core/receiver/PlayerWidget.java | 2 +
.../antennapod/core/widget/WidgetUpdater.java | 9 +-
core/src/main/res/layout/player_widget.xml | 10 ++
core/src/main/res/values/styles.xml | 11 +-
.../PlaybackSpeedActivityStarter.java | 40 +++++
.../src/main/res/values/pending_intent.xml | 1 +
.../res/drawable/ic_widget_playback_speed.xml | 16 ++
11 files changed, 218 insertions(+), 74 deletions(-)
create mode 100644 app/src/main/java/de/danoeh/antennapod/activity/PlaybackSpeedDialogActivity.java
create mode 100644 ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/PlaybackSpeedActivityStarter.java
create mode 100644 ui/png-icons/src/main/res/drawable/ic_widget_playback_speed.xml
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ff6c917dd..93f1494f2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -43,6 +43,17 @@
android:allowAudioPlaybackCapture="true"
android:networkSecurityConfig="@xml/network_security_config">
+
+
+
+
+
+
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PlaybackSpeedDialogActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PlaybackSpeedDialogActivity.java
new file mode 100644
index 000000000..137724acd
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/activity/PlaybackSpeedDialogActivity.java
@@ -0,0 +1,29 @@
+package de.danoeh.antennapod.activity;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import de.danoeh.antennapod.core.preferences.UserPreferences;
+import de.danoeh.antennapod.dialog.VariableSpeedDialog;
+
+public class PlaybackSpeedDialogActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTranslucentTheme());
+ super.onCreate(savedInstanceState);
+ VariableSpeedDialog speedDialog = new InnerVariableSpeedDialog();
+ speedDialog.show(getSupportFragmentManager(), null);
+ }
+
+ public static class InnerVariableSpeedDialog extends VariableSpeedDialog {
+ @Override
+ public void onDismiss(@NonNull DialogInterface dialog) {
+ super.onDismiss(dialog);
+ getActivity().finish();
+ }
+ }
+}
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java
index 7245ce675..32789e51a 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java
@@ -20,6 +20,7 @@ public class WidgetConfigActivity extends AppCompatActivity {
private SeekBar opacitySeekBar;
private TextView opacityTextView;
private View widgetPreview;
+ private CheckBox ckPlaybackSpeed;
private CheckBox ckRewind;
private CheckBox ckFastForward;
private CheckBox ckSkip;
@@ -75,6 +76,8 @@ public class WidgetConfigActivity extends AppCompatActivity {
progress.setVisibility(View.VISIBLE);
progress.setText(R.string.position_default_label);
+ ckPlaybackSpeed = findViewById(R.id.ckPlaybackSpeed);
+ ckPlaybackSpeed.setOnClickListener(v -> displayPreviewPanel());
ckRewind = findViewById(R.id.ckRewind);
ckRewind.setOnClickListener(v -> displayPreviewPanel());
ckFastForward = findViewById(R.id.ckFastForward);
@@ -84,10 +87,13 @@ public class WidgetConfigActivity extends AppCompatActivity {
}
private void displayPreviewPanel() {
- boolean showExtendedPreview = ckRewind.isChecked() || ckFastForward.isChecked() || ckSkip.isChecked();
+ boolean showExtendedPreview =
+ ckPlaybackSpeed.isChecked() || ckRewind.isChecked() || ckFastForward.isChecked() || ckSkip.isChecked();
widgetPreview.findViewById(R.id.extendedButtonsContainer)
.setVisibility(showExtendedPreview ? View.VISIBLE : View.GONE);
widgetPreview.findViewById(R.id.butPlay).setVisibility(showExtendedPreview ? View.GONE : View.VISIBLE);
+ widgetPreview.findViewById(R.id.butPlaybackSpeed)
+ .setVisibility(ckPlaybackSpeed.isChecked() ? View.VISIBLE : View.GONE);
widgetPreview.findViewById(R.id.butFastForward)
.setVisibility(ckFastForward.isChecked() ? View.VISIBLE : View.GONE);
widgetPreview.findViewById(R.id.butSkip).setVisibility(ckSkip.isChecked() ? View.VISIBLE : View.GONE);
@@ -100,6 +106,7 @@ public class WidgetConfigActivity extends AppCompatActivity {
SharedPreferences prefs = getSharedPreferences(PlayerWidget.PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(PlayerWidget.KEY_WIDGET_COLOR + appWidgetId, backgroundColor);
+ editor.putBoolean(PlayerWidget.KEY_WIDGET_PLAYBACK_SPEED + appWidgetId, ckPlaybackSpeed.isChecked());
editor.putBoolean(PlayerWidget.KEY_WIDGET_SKIP + appWidgetId, ckSkip.isChecked());
editor.putBoolean(PlayerWidget.KEY_WIDGET_REWIND + appWidgetId, ckRewind.isChecked());
editor.putBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + appWidgetId, ckFastForward.isChecked());
diff --git a/app/src/main/res/layout/activity_widget_config.xml b/app/src/main/res/layout/activity_widget_config.xml
index 8c540fcc6..6e7bd8eb9 100644
--- a/app/src/main/res/layout/activity_widget_config.xml
+++ b/app/src/main/res/layout/activity_widget_config.xml
@@ -1,5 +1,6 @@
-
+ android:scaleType="centerCrop"
+ app:srcCompat="@drawable/teaser" />
+ android:layout_margin="16dp"
+ layout="@layout/player_widget" />
+
-
+ android:layout_height="wrap_content">
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:padding="16dp">
-
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
-
+
+
+
+
+
+
+ android:layout_marginTop="16dp"
+ android:layout_marginBottom="16dp"
+ android:max="100"
+ android:progress="100" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java b/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java
index 46faeec50..4e5aff696 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java
@@ -14,6 +14,7 @@ public class PlayerWidget extends AppWidgetProvider {
public static final String PREFS_NAME = "PlayerWidgetPrefs";
private static final String KEY_ENABLED = "WidgetEnabled";
public static final String KEY_WIDGET_COLOR = "widget_color";
+ public static final String KEY_WIDGET_PLAYBACK_SPEED = "widget_playback_speed";
public static final String KEY_WIDGET_SKIP = "widget_skip";
public static final String KEY_WIDGET_FAST_FORWARD = "widget_fast_forward";
public static final String KEY_WIDGET_REWIND = "widget_rewind";
@@ -47,6 +48,7 @@ public class PlayerWidget extends AppWidgetProvider {
for (int appWidgetId : appWidgetIds) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().remove(KEY_WIDGET_COLOR + appWidgetId).apply();
+ prefs.edit().remove(KEY_WIDGET_PLAYBACK_SPEED + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_REWIND + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_FAST_FORWARD + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_SKIP + appWidgetId).apply();
diff --git a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java
index 1253c747b..8afba881a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java
@@ -31,6 +31,7 @@ import de.danoeh.antennapod.core.util.TimeSpeedConverter;
import de.danoeh.antennapod.model.playback.Playable;
import de.danoeh.antennapod.playback.base.PlayerStatus;
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
+import de.danoeh.antennapod.ui.appstartintent.PlaybackSpeedActivityStarter;
import de.danoeh.antennapod.ui.appstartintent.VideoPlayerActivityStarter;
/**
@@ -73,6 +74,9 @@ public abstract class WidgetUpdater {
} else {
startMediaPlayer = new MainActivityStarter(context).withOpenPlayer().getPendingIntent();
}
+
+ PendingIntent startPlaybackSpeedDialog = new PlaybackSpeedActivityStarter(context).getPendingIntent();
+
RemoteViews views;
views = new RemoteViews(context.getPackageName(), R.layout.player_widget);
@@ -81,6 +85,7 @@ public abstract class WidgetUpdater {
int iconSize = context.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer);
views.setOnClickPendingIntent(R.id.imgvCover, startMediaPlayer);
+ views.setOnClickPendingIntent(R.id.butPlaybackSpeed, startPlaybackSpeedDialog);
try {
icon = Glide.with(context)
@@ -165,13 +170,15 @@ public abstract class WidgetUpdater {
} else {
views.setViewVisibility(R.id.layout_center, View.VISIBLE);
}
+ boolean showPlaybackSpeed = prefs.getBoolean(PlayerWidget.KEY_WIDGET_PLAYBACK_SPEED + id, false);
boolean showRewind = prefs.getBoolean(PlayerWidget.KEY_WIDGET_REWIND + id, false);
boolean showFastForward = prefs.getBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + id, false);
boolean showSkip = prefs.getBoolean(PlayerWidget.KEY_WIDGET_SKIP + id, false);
- if (showRewind || showSkip || showFastForward) {
+ if (showPlaybackSpeed || showRewind || showSkip || showFastForward) {
views.setInt(R.id.extendedButtonsContainer, "setVisibility", View.VISIBLE);
views.setInt(R.id.butPlay, "setVisibility", View.GONE);
+ views.setInt(R.id.butPlaybackSpeed, "setVisibility", showPlaybackSpeed ? View.VISIBLE : View.GONE);
views.setInt(R.id.butRew, "setVisibility", showRewind ? View.VISIBLE : View.GONE);
views.setInt(R.id.butFastForward, "setVisibility", showFastForward ? View.VISIBLE : View.GONE);
views.setInt(R.id.butSkip, "setVisibility", showSkip ? View.VISIBLE : View.GONE);
diff --git a/core/src/main/res/layout/player_widget.xml b/core/src/main/res/layout/player_widget.xml
index 60d40e6b5..6f3842e8b 100644
--- a/core/src/main/res/layout/player_widget.xml
+++ b/core/src/main/res/layout/player_widget.xml
@@ -88,6 +88,16 @@
android:orientation="horizontal"
android:visibility="gone">
+
+
-
diff --git a/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/PlaybackSpeedActivityStarter.java b/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/PlaybackSpeedActivityStarter.java
new file mode 100644
index 000000000..ac7e72a4e
--- /dev/null
+++ b/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/PlaybackSpeedActivityStarter.java
@@ -0,0 +1,40 @@
+package de.danoeh.antennapod.ui.appstartintent;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+
+/**
+ * Launches the playback speed dialog activity of the app with specific arguments.
+ * Does not require a dependency on the actual implementation of the activity.
+ */
+public class PlaybackSpeedActivityStarter {
+ public static final String INTENT = "de.danoeh.antennapod.intents.PLAYBACK_SPEED";
+ private final Intent intent;
+ private final Context context;
+
+ public PlaybackSpeedActivityStarter(Context context) {
+ this.context = context;
+ intent = new Intent(INTENT);
+ intent.setPackage(context.getPackageName());
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
+ } else {
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ }
+ }
+
+ public Intent getIntent() {
+ return intent;
+ }
+
+ public PendingIntent getPendingIntent() {
+ return PendingIntent.getActivity(context, R.id.pending_intent_playback_speed, getIntent(),
+ PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
+ }
+
+ public void start() {
+ context.startActivity(getIntent());
+ }
+}
diff --git a/ui/app-start-intent/src/main/res/values/pending_intent.xml b/ui/app-start-intent/src/main/res/values/pending_intent.xml
index 1e426e954..ed7e9b2cd 100644
--- a/ui/app-start-intent/src/main/res/values/pending_intent.xml
+++ b/ui/app-start-intent/src/main/res/values/pending_intent.xml
@@ -6,6 +6,7 @@
+
diff --git a/ui/png-icons/src/main/res/drawable/ic_widget_playback_speed.xml b/ui/png-icons/src/main/res/drawable/ic_widget_playback_speed.xml
new file mode 100644
index 000000000..482b6617e
--- /dev/null
+++ b/ui/png-icons/src/main/res/drawable/ic_widget_playback_speed.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
\ No newline at end of file