commit
f41bdcbaf2
|
@ -35,6 +35,15 @@
|
|||
android:restoreAnyVersion="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:logo="@mipmap/ic_launcher">
|
||||
|
||||
<activity
|
||||
android:name=".activity.WidgetConfigActivity"
|
||||
android:label="Widget settings">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGUR"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<meta-data android:name="com.google.android.gms.car.notification.SmallIcon"
|
||||
android:resource="@drawable/ic_antenna" />
|
||||
<meta-data
|
||||
|
@ -336,7 +345,7 @@
|
|||
<action android:name="de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS_RESPONSE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
<provider
|
||||
android:authorities="@string/provider_authority"
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RemoteViews;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.receiver.PlayerWidget;
|
||||
import de.danoeh.antennapod.core.service.PlayerWidgetJobService;
|
||||
|
||||
public class WidgetConfigActivity extends AppCompatActivity {
|
||||
private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
|
||||
private SeekBar opacitySeekBar;
|
||||
private TextView opacityTextView;
|
||||
private RelativeLayout widgetPreview;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(UserPreferences.getTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_widget_config);
|
||||
|
||||
Intent configIntent = getIntent();
|
||||
Bundle extras = configIntent.getExtras();
|
||||
if (extras != null) {
|
||||
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
}
|
||||
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
setResult(RESULT_CANCELED, resultValue);
|
||||
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
finish();
|
||||
}
|
||||
|
||||
displayDeviceBackground();
|
||||
opacityTextView = findViewById(R.id.widget_opacity_textView);
|
||||
opacitySeekBar = findViewById(R.id.widget_opacity_seekBar);
|
||||
widgetPreview = findViewById(R.id.widgetLayout);
|
||||
findViewById(R.id.butConfirm).setOnClickListener(this::confirmCreateWidget);
|
||||
opacitySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
opacityTextView.setText(seekBar.getProgress() + "%");
|
||||
int color = getColorWithAlpha(PlayerWidget.DEFAULT_COLOR, opacitySeekBar.getProgress());
|
||||
widgetPreview.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void displayDeviceBackground() {
|
||||
int permission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
if (Build.VERSION.SDK_INT < 27 || permission == PackageManager.PERMISSION_GRANTED) {
|
||||
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
|
||||
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
|
||||
ImageView background = findViewById(R.id.widget_config_background);
|
||||
background.setImageDrawable(wallpaperDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
private void confirmCreateWidget(View v) {
|
||||
int backgroundColor = getColorWithAlpha(PlayerWidget.DEFAULT_COLOR, opacitySeekBar.getProgress());
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(PlayerWidget.PREFS_NAME, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putInt(PlayerWidget.KEY_WIDGET_COLOR + appWidgetId, backgroundColor);
|
||||
editor.apply();
|
||||
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
setResult(RESULT_OK, resultValue);
|
||||
finish();
|
||||
PlayerWidgetJobService.updateWidget(this);
|
||||
}
|
||||
|
||||
private int getColorWithAlpha(int color, int opacity) {
|
||||
return (int) Math.round(0xFF * (0.01 * opacity)) * 0x1000000 + color;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="de.danoeh.antennapod.activity.WidgetConfigActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widget_config_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/teaser"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<include
|
||||
android:id="@+id/widget_config_preview"
|
||||
layout="@layout/player_widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="16dp" />
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/widget_opacity"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_opacity_textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end"
|
||||
android:text="100%"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/widget_opacity_seekBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:max="100"
|
||||
android:progress="100" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/butConfirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/widget_create_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -6,6 +6,7 @@
|
|||
android:previewImage="@drawable/ic_widget_preview"
|
||||
android:minHeight="40dp"
|
||||
android:minWidth="250dp"
|
||||
android:minResizeWidth="40dp">
|
||||
android:minResizeWidth="40dp"
|
||||
android:configure="de.danoeh.antennapod.activity.WidgetConfigActivity">
|
||||
|
||||
</appwidget-provider>
|
|
@ -67,7 +67,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="logobackground">
|
||||
<img id="logo" src="file:///android_asset/logo.png" alt="Logo"/>
|
||||
<img id="logo" src="file:///android_res/drawable/teaser.png" alt="Logo"/>
|
||||
</div>
|
||||
|
||||
<h1>AntennaPod</h1>
|
||||
|
|
|
@ -11,11 +11,12 @@ import java.util.Arrays;
|
|||
|
||||
import de.danoeh.antennapod.core.service.PlayerWidgetJobService;
|
||||
|
||||
|
||||
public class PlayerWidget extends AppWidgetProvider {
|
||||
private static final String TAG = "PlayerWidget";
|
||||
private static final String PREFS_NAME = "PlayerWidgetPrefs";
|
||||
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 int DEFAULT_COLOR = 0x00262C31;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -45,6 +46,16 @@ public class PlayerWidget extends AppWidgetProvider {
|
|||
setEnabled(context, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleted(Context context, int[] appWidgetIds) {
|
||||
Log.d(TAG, "OnDeleted");
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().remove(KEY_WIDGET_COLOR + appWidgetId).apply();
|
||||
}
|
||||
super.onDeleted(context, appWidgetIds);
|
||||
}
|
||||
|
||||
public static boolean isEnabled(Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
return prefs.getBoolean(KEY_ENABLED, false);
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -193,6 +194,11 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
|
|||
} else {
|
||||
views.setViewVisibility(R.id.layout_center, View.VISIBLE);
|
||||
}
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(PlayerWidget.PREFS_NAME, Context.MODE_PRIVATE);
|
||||
int backgroundColor = prefs.getInt(PlayerWidget.KEY_WIDGET_COLOR + id, PlayerWidget.DEFAULT_COLOR);
|
||||
views.setInt(R.id.widgetLayout, "setBackgroundColor", backgroundColor);
|
||||
|
||||
manager.updateAppWidget(id, views);
|
||||
}
|
||||
} else {
|
||||
|
@ -242,6 +248,5 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
|
|||
}
|
||||
Log.d(TAG, "Disconnected from service");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
|
0
app/src/main/assets/logo.png → core/src/main/res/drawable-nodpi/teaser.png
Executable file → Normal file
0
app/src/main/assets/logo.png → core/src/main/res/drawable-nodpi/teaser.png
Executable file → Normal file
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
|
@ -5,10 +5,12 @@
|
|||
android:padding="@dimen/widget_margin" >
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/widgetLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#262C31" >
|
||||
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/butPlay"
|
||||
android:contentDescription="@string/play_label"
|
||||
|
@ -17,7 +19,7 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_margin="12dp"
|
||||
android:background="@drawable/borderless_button_dark"
|
||||
android:background="@android:color/transparent"
|
||||
android:src="@drawable/ic_play_arrow_white_24dp" />
|
||||
|
||||
<LinearLayout
|
||||
|
@ -28,7 +30,7 @@
|
|||
android:layout_alignParentStart="true"
|
||||
android:layout_toLeftOf="@id/butPlay"
|
||||
android:layout_toStartOf="@id/butPlay"
|
||||
android:background="@drawable/borderless_button_dark"
|
||||
android:background="@android:color/transparent"
|
||||
android:gravity="fill_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
|
@ -36,6 +38,7 @@
|
|||
android:id="@+id/imgvCover"
|
||||
android:layout_width="@android:dimen/app_icon_size"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/ic_antenna"
|
||||
android:layout_margin="12dp" />
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -755,4 +755,8 @@
|
|||
<string name="notification_channel_error">Errors</string>
|
||||
<string name="notification_channel_error_description">Shown if something went wrong, for example if download or gpodder sync fails.</string>
|
||||
<string name="import_bad_file">Invalid/corrupt file</string>
|
||||
|
||||
<!-- Widget settings -->
|
||||
<string name="widget_create_button">Create widget</string>
|
||||
<string name="widget_opacity">Opacity</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue