Make widget configurable by long-pressing (#6410)

This commit is contained in:
mueller-ma 2023-04-03 21:50:13 +02:00 committed by GitHub
parent 038847177e
commit 3e101cca2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -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() {

View File

@ -7,5 +7,6 @@
android:minHeight="40dp"
android:minWidth="250dp"
android:minResizeWidth="40dp"
android:widgetFeatures="reconfigurable"
android:configure="de.danoeh.antennapod.activity.WidgetConfigActivity">
</appwidget-provider>

View File

@ -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);