From 3e101cca2a8c2373a41f17c0baf5ffd58beb7a7a Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Mon, 3 Apr 2023 21:50:13 +0200 Subject: [PATCH] Make widget configurable by long-pressing (#6410) --- .../activity/WidgetConfigActivity.java | 19 +++++++++++++++++++ app/src/main/res/xml/player_widget_info.xml | 1 + .../antennapod/core/widget/WidgetUpdater.java | 3 +++ 3 files changed, 23 insertions(+) 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 fdbcde54b..c33af33a4 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java @@ -3,6 +3,8 @@ package de.danoeh.antennapod.activity; import android.appwidget.AppWidgetManager; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; +import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.CheckBox; @@ -84,6 +86,23 @@ public class WidgetConfigActivity extends AppCompatActivity { ckFastForward.setOnClickListener(v -> displayPreviewPanel()); ckSkip = findViewById(R.id.ckSkip); ckSkip.setOnClickListener(v -> displayPreviewPanel()); + + setInitialState(); + } + + private void setInitialState() { + SharedPreferences prefs = getSharedPreferences(PlayerWidget.PREFS_NAME, MODE_PRIVATE); + ckPlaybackSpeed.setChecked(prefs.getBoolean(PlayerWidget.KEY_WIDGET_PLAYBACK_SPEED + appWidgetId, false)); + ckRewind.setChecked(prefs.getBoolean(PlayerWidget.KEY_WIDGET_REWIND + appWidgetId, false)); + ckFastForward.setChecked(prefs.getBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + appWidgetId, false)); + ckSkip.setChecked(prefs.getBoolean(PlayerWidget.KEY_WIDGET_SKIP + appWidgetId, false)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + int color = prefs.getInt(PlayerWidget.KEY_WIDGET_COLOR + appWidgetId, 0); + int opacity = Color.alpha(color) * 100 / 0xFF; + + opacitySeekBar.setProgress(opacity, false); + } + displayPreviewPanel(); } private void displayPreviewPanel() { diff --git a/app/src/main/res/xml/player_widget_info.xml b/app/src/main/res/xml/player_widget_info.xml index 803cc89ed..25f4e274a 100644 --- a/app/src/main/res/xml/player_widget_info.xml +++ b/app/src/main/res/xml/player_widget_info.xml @@ -7,5 +7,6 @@ android:minHeight="40dp" android:minWidth="250dp" android:minResizeWidth="40dp" + android:widgetFeatures="reconfigurable" android:configure="de.danoeh.antennapod.activity.WidgetConfigActivity"> 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 dda8a37fb..b27325cf8 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 @@ -176,6 +176,9 @@ public abstract class WidgetUpdater { 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); + } else { + views.setInt(R.id.extendedButtonsContainer, "setVisibility", View.GONE); + views.setInt(R.id.butPlay, "setVisibility", View.VISIBLE); } int backgroundColor = prefs.getInt(PlayerWidget.KEY_WIDGET_COLOR + id, PlayerWidget.DEFAULT_COLOR);