diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 321d188d3a..adb8a546d0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -45,8 +45,17 @@
android:roundIcon="${appIconRound}"
android:supportsRtl="true"
android:theme="@style/AppTheme.Launcher" >
+
+
+
+
+
+
+
diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.kt b/app/src/main/java/info/nightscout/androidaps/MainApp.kt
index 3bc938d2f8..cbecb3cc31 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.kt
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.kt
@@ -41,6 +41,7 @@ import info.nightscout.androidaps.utils.LocalAlertUtils
import info.nightscout.androidaps.utils.ProcessLifecycleListener
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.locale.LocaleHelper
+import info.nightscout.androidaps.widget.updateWidget
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
diff --git a/app/src/main/java/info/nightscout/androidaps/di/UIModule.kt b/app/src/main/java/info/nightscout/androidaps/di/UIModule.kt
index 13083f32a5..160601bad2 100644
--- a/app/src/main/java/info/nightscout/androidaps/di/UIModule.kt
+++ b/app/src/main/java/info/nightscout/androidaps/di/UIModule.kt
@@ -2,8 +2,9 @@ package info.nightscout.androidaps.di
import dagger.Module
import dagger.android.ContributesAndroidInjector
-import info.nightscout.androidaps.Widget
+import info.nightscout.androidaps.widget.WidgetConfigureActivity
import info.nightscout.androidaps.skins.SkinListPreference
+import info.nightscout.androidaps.widget.Widget
@Module
@Suppress("unused")
@@ -11,4 +12,6 @@ abstract class UIModule {
@ContributesAndroidInjector abstract fun skinListPreferenceInjector(): SkinListPreference
@ContributesAndroidInjector abstract fun aapsWidgetInjector(): Widget
+ @ContributesAndroidInjector abstract fun contributesWidgetConfigureActivity(): WidgetConfigureActivity
+
}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt
index 01c19acbcc..3370908ea2 100644
--- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt
+++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt
@@ -15,12 +15,12 @@ import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration
import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin
import info.nightscout.androidaps.queue.commands.Command
-import info.nightscout.androidaps.updateWidget
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.LocalAlertUtils
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
+import info.nightscout.androidaps.widget.updateWidget
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import java.util.concurrent.TimeUnit
diff --git a/app/src/main/java/info/nightscout/androidaps/Widget.kt b/app/src/main/java/info/nightscout/androidaps/widget/Widget.kt
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/Widget.kt
rename to app/src/main/java/info/nightscout/androidaps/widget/Widget.kt
index aef1b1fd8d..4c3d145915 100644
--- a/app/src/main/java/info/nightscout/androidaps/Widget.kt
+++ b/app/src/main/java/info/nightscout/androidaps/widget/Widget.kt
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps
+package info.nightscout.androidaps.widget
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
@@ -6,10 +6,14 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
+import android.graphics.Color
import android.graphics.Paint
import android.view.View
import android.widget.RemoteViews
import dagger.android.HasAndroidInjector
+import info.nightscout.androidaps.Constants
+import info.nightscout.androidaps.MainActivity
+import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.database.interfaces.end
import info.nightscout.androidaps.extensions.directionToIcon
@@ -73,13 +77,16 @@ class Widget : AppWidgetProvider() {
private fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
aapsLogger.debug(LTag.WIDGET, "updateAppWidget called")
+
val views = RemoteViews(context.packageName, R.layout.widget_layout)
+ val alpha = sp.getInt(WidgetConfigureActivity.PREF_PREFIX_KEY + appWidgetId, WidgetConfigureActivity.DEFAULT_OPACITY)
// Create an Intent to launch MainActivity when clicked
val intent = Intent(context, MainActivity::class.java).also { it.action = intentAction }
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
// Widgets allow click handlers to only launch pending intents
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent)
+ views.setInt(R.id.widget_layout, "setBackgroundColor", Color.argb(alpha, 0, 0, 0))
updateBg(views)
updateTemporaryBasal(views)
@@ -104,11 +111,13 @@ class Widget : AppWidgetProvider() {
}
)
views.setImageViewResource(R.id.arrow, trendCalculator.getTrendArrow(overviewData.lastBg).directionToIcon())
- views.setInt(R.id.arrow, "setColorFilter", when {
- overviewData.isLow -> rh.gc(R.color.low)
- overviewData.isHigh -> rh.gc(R.color.high)
- else -> rh.gc(R.color.inrange)
- })
+ views.setInt(
+ R.id.arrow, "setColorFilter", when {
+ overviewData.isLow -> rh.gc(R.color.low)
+ overviewData.isHigh -> rh.gc(R.color.high)
+ else -> rh.gc(R.color.inrange)
+ }
+ )
val glucoseStatus = glucoseStatusProvider.glucoseStatusData
if (glucoseStatus != null) {
diff --git a/app/src/main/java/info/nightscout/androidaps/widget/WidgetConfigureActivity.kt b/app/src/main/java/info/nightscout/androidaps/widget/WidgetConfigureActivity.kt
new file mode 100644
index 0000000000..4647b86454
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/widget/WidgetConfigureActivity.kt
@@ -0,0 +1,78 @@
+package info.nightscout.androidaps.widget
+
+import android.appwidget.AppWidgetManager
+import android.content.Intent
+import android.os.Bundle
+import android.widget.SeekBar
+import dagger.android.DaggerActivity
+import info.nightscout.androidaps.databinding.WidgetConfigureBinding
+import info.nightscout.shared.sharedPreferences.SP
+import javax.inject.Inject
+
+/**
+ * The configuration screen for the [Widget] AppWidget.
+ */
+class WidgetConfigureActivity : DaggerActivity() {
+
+ @Inject lateinit var sp: SP
+
+ companion object {
+
+ @Suppress("PrivatePropertyName")
+ const val PREF_PREFIX_KEY = "appwidget_"
+ const val DEFAULT_OPACITY = 25
+ }
+
+ private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID
+ private var value = 0
+
+ private lateinit var binding: WidgetConfigureBinding
+
+ public override fun onCreate(icicle: Bundle?) {
+ super.onCreate(icicle)
+
+ // Set the result to CANCELED. This will cause the widget host to cancel
+ // out of the widget placement if the user presses the back button.
+ setResult(RESULT_CANCELED)
+
+ binding = WidgetConfigureBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+
+ binding.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
+ override fun onStopTrackingTouch(seekBar: SeekBar) {
+ // Make sure we pass back the original appWidgetId
+ val resultValue = Intent()
+ resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
+ setResult(RESULT_OK, resultValue)
+ finish()
+ }
+
+ override fun onStartTrackingTouch(seekBar: SeekBar) {}
+ override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
+ value = progress
+ saveTitlePref(appWidgetId, value)
+ updateWidget(this@WidgetConfigureActivity)
+ }
+ })
+
+ // Find the widget id from the intent.
+ appWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
+
+ // If this activity was started with an intent without an app widget ID, finish with an error.
+ if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
+ finish()
+ return
+ }
+
+ binding.seekBar.progress = loadTitlePref(appWidgetId)
+ }
+
+ // Write the prefix to the SharedPreferences object for this widget
+ fun saveTitlePref(appWidgetId: Int, value: Int) {
+ sp.putInt(PREF_PREFIX_KEY + appWidgetId, value)
+ }
+
+ // Read the prefix from the SharedPreferences object for this widget.
+ // If there is no preference saved, get the default from a resource
+ private fun loadTitlePref(appWidgetId: Int): Int = sp.getInt(PREF_PREFIX_KEY + appWidgetId, 25)
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable-nodpi/widget_background.xml b/app/src/main/res/drawable-nodpi/widget_background.xml
deleted file mode 100644
index 3b269ba8be..0000000000
--- a/app/src/main/res/drawable-nodpi/widget_background.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v21/app_widget_background.xml b/app/src/main/res/drawable-v21/widget_background.xml
similarity index 100%
rename from app/src/main/res/drawable-v21/app_widget_background.xml
rename to app/src/main/res/drawable-v21/widget_background.xml
diff --git a/app/src/main/res/drawable-v21/app_widget_inner_view_background.xml b/app/src/main/res/drawable-v21/widget_inner_view_background.xml
similarity index 100%
rename from app/src/main/res/drawable-v21/app_widget_inner_view_background.xml
rename to app/src/main/res/drawable-v21/widget_inner_view_background.xml
diff --git a/app/src/main/res/layout/widget_configure.xml b/app/src/main/res/layout/widget_configure.xml
new file mode 100644
index 0000000000..3709f04a23
--- /dev/null
+++ b/app/src/main/res/layout/widget_configure.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_layout.xml b/app/src/main/res/layout/widget_layout.xml
index 5783ce2e77..7fa0fb9973 100644
--- a/app/src/main/res/layout/widget_layout.xml
+++ b/app/src/main/res/layout/widget_layout.xml
@@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:background="@drawable/widget_background"
+ android:background="@color/black"
android:theme="@style/AppTheme.Launcher.AppWidgetContainer">
\ No newline at end of file
diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml
new file mode 100644
index 0000000000..70add0eacb
--- /dev/null
+++ b/app/src/main/res/values-v31/themes.xml
@@ -0,0 +1,6 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index cd1106a8a0..4b2fe0de22 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1209,4 +1209,5 @@
Show loop records
Hide loop records
AndroidAPS widget
+ Configure opacity
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 985f488e58..74f76fe8cf 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -1,4 +1,5 @@
+
-
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/widget_info.xml b/app/src/main/res/xml/widget_info.xml
index 819118751e..801dca46d9 100644
--- a/app/src/main/res/xml/widget_info.xml
+++ b/app/src/main/res/xml/widget_info.xml
@@ -1,5 +1,6 @@
\ No newline at end of file
+ android:widgetCategory="home_screen"
+ android:widgetFeatures="reconfigurable|configuration_optional" />
\ No newline at end of file