diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-10-23 23:11:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-23 23:11:51 +0200 |
commit | f41bdcbaf21cc6f8172ee14ea211634292e985f3 (patch) | |
tree | 6a219c66e76ee0bd909b3f088d76fb411df1b7bf /app/src/main | |
parent | 58764f7ccbd2037eaf126f0f8b1a9916a7ae7765 (diff) | |
parent | ff44f97dd6447a2b2ac077bc547306f8a232b3cd (diff) | |
download | AntennaPod-f41bdcbaf21cc6f8172ee14ea211634292e985f3.zip |
Merge pull request #3544 from M-arcel/develop
Transparent widget
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/AndroidManifest.xml | 11 | ||||
-rwxr-xr-x | app/src/main/assets/logo.png | bin | 60183 -> 0 bytes | |||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java | 107 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_widget_config.xml | 80 | ||||
-rw-r--r-- | app/src/main/res/xml/player_widget_info.xml | 3 | ||||
-rw-r--r-- | app/src/main/templates/about.html | 2 |
6 files changed, 200 insertions, 3 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 488d4e473..8224407a2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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" diff --git a/app/src/main/assets/logo.png b/app/src/main/assets/logo.png Binary files differdeleted file mode 100755 index 3b5261b28..000000000 --- a/app/src/main/assets/logo.png +++ /dev/null diff --git a/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java new file mode 100644 index 000000000..474b96c38 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/activity/WidgetConfigActivity.java @@ -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; + } +} diff --git a/app/src/main/res/layout/activity_widget_config.xml b/app/src/main/res/layout/activity_widget_config.xml new file mode 100644 index 000000000..ca8aba52d --- /dev/null +++ b/app/src/main/res/layout/activity_widget_config.xml @@ -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> diff --git a/app/src/main/res/xml/player_widget_info.xml b/app/src/main/res/xml/player_widget_info.xml index 1dbfabcd6..79cdd4a69 100644 --- a/app/src/main/res/xml/player_widget_info.xml +++ b/app/src/main/res/xml/player_widget_info.xml @@ -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>
\ No newline at end of file diff --git a/app/src/main/templates/about.html b/app/src/main/templates/about.html index fd70ab549..c419609af 100644 --- a/app/src/main/templates/about.html +++ b/app/src/main/templates/about.html @@ -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> |