Skip to content

Commit

Permalink
Make widget configurable by long-pressing (#6410)
Browse files Browse the repository at this point in the history
  • Loading branch information
mueller-ma committed Apr 3, 2023
1 parent 0388471 commit 3e101cc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Expand Up @@ -3,6 +3,8 @@
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;
Expand Down Expand Up @@ -84,6 +86,23 @@ public void onStopTrackingTouch(SeekBar seekBar) {
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() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/player_widget_info.xml
Expand Up @@ -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>
Expand Up @@ -176,6 +176,9 @@ public static void updateWidget(Context context, WidgetState widgetState) {
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);
Expand Down

0 comments on commit 3e101cc

Please sign in to comment.