From 91467b1f49afb995de0dc5a900da01045a3252f8 Mon Sep 17 00:00:00 2001 From: osodebailar Date: Wed, 23 Mar 2022 16:25:02 +0100 Subject: [PATCH] rounded dialogs like in android 12 --- .../androidaps/dialogs/CalibrationDialog.kt | 1 - .../androidaps/dialogs/CarbsDialog.kt | 1 - .../androidaps/dialogs/CareDialog.kt | 1 - .../androidaps/dialogs/ExtendedBolusDialog.kt | 1 - .../androidaps/dialogs/FillDialog.kt | 1 - .../androidaps/dialogs/InsulinDialog.kt | 1 - .../androidaps/dialogs/ProfileSwitchDialog.kt | 1 - .../androidaps/dialogs/TempBasalDialog.kt | 1 - .../androidaps/dialogs/TempTargetDialog.kt | 1 - .../androidaps/dialogs/TreatmentDialog.kt | 1 - .../androidaps/dialogs/WizardDialog.kt | 9 ++++++++ .../dialogs/ChooseOperationDialog.kt | 2 -- .../androidaps/dialogs/BolusProgressDialog.kt | 16 ++++++++++++++ .../dialogs/DialogFragmentWithDate.kt | 11 ++++++++++ core/src/main/res/drawable-hdpi/dialog.xml | 21 +++++++++++++++++++ core/src/main/res/values-night/colors.xml | 6 +++++- core/src/main/res/values-night/styles.xml | 5 ++++- core/src/main/res/values/attrs.xml | 2 ++ core/src/main/res/values/colors.xml | 4 ++++ core/src/main/res/values/styles.xml | 3 +++ 20 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 core/src/main/res/drawable-hdpi/dialog.xml diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt index bd5daaf965..20a0de18de 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt @@ -27,7 +27,6 @@ import javax.inject.Inject class CalibrationDialog : DialogFragmentWithDate() { @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var xDripBroadcast: XDripBroadcast @Inject lateinit var uel: UserEntryLogger diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index ff4f64e0f4..ce39706342 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -41,7 +41,6 @@ import kotlin.math.max class CarbsDialog : DialogFragmentWithDate() { @Inject lateinit var ctx: Context - @Inject lateinit var rh: ResourceHelper @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var profileFunction: ProfileFunction diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index 03cb215a7f..d466956251 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -41,7 +41,6 @@ class CareDialog : DialogFragmentWithDate() { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var ctx: Context - @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var translator: Translator @Inject lateinit var uel: UserEntryLogger diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 7d4525bd8f..0f76468de0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -35,7 +35,6 @@ import kotlin.math.abs class ExtendedBolusDialog : DialogFragmentWithDate() { @Inject lateinit var ctx: Context - @Inject lateinit var rh: ResourceHelper @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var commandQueue: CommandQueue @Inject lateinit var activePlugin: ActivePlugin diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index cb26aa1a5a..7dd9f8eb1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -41,7 +41,6 @@ import kotlin.math.abs class FillDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker - @Inject lateinit var rh: ResourceHelper @Inject lateinit var ctx: Context @Inject lateinit var commandQueue: CommandQueue @Inject lateinit var activePlugin: ActivePlugin diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index a4172a8727..d9b2b027d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -44,7 +44,6 @@ import kotlin.math.max class InsulinDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker - @Inject lateinit var rh: ResourceHelper @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var commandQueue: CommandQueue diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index 41efc7e42c..935d511153 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -46,7 +46,6 @@ import kotlin.collections.ArrayList class ProfileSwitchDialog : DialogFragmentWithDate() { - @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var repository: AppRepository diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt index aba8fb579f..f6d23f5fab 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt @@ -33,7 +33,6 @@ import kotlin.math.abs class TempBasalDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker - @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var commandQueue: CommandQueue diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index dba15262a5..a4edaa61ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -42,7 +42,6 @@ import javax.inject.Inject class TempTargetDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker - @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var uel: UserEntryLogger diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 55fd9a773b..8083f3c3d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -43,7 +43,6 @@ import kotlin.math.abs class TreatmentDialog : DialogFragmentWithDate() { @Inject lateinit var constraintChecker: ConstraintChecker - @Inject lateinit var rh: ResourceHelper @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var commandQueue: CommandQueue @Inject lateinit var ctx: Context diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 9af21b0194..de01e72d60 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -2,6 +2,9 @@ package info.nightscout.androidaps.dialogs import android.annotation.SuppressLint import android.content.Context +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +import android.graphics.drawable.Drawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher @@ -13,6 +16,7 @@ import android.view.WindowManager import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.CompoundButton +import androidx.core.content.ContextCompat import androidx.fragment.app.FragmentManager import dagger.android.HasAndroidInjector import dagger.android.support.DaggerDialogFragment @@ -120,6 +124,11 @@ class WizardDialog : DaggerDialogFragment() { isCancelable = true dialog?.setCanceledOnTouchOutside(false) + val drawable: Drawable? = context?.let { ContextCompat.getDrawable(it, info.nightscout.androidaps.core.R.drawable.dialog) } + drawable?.setColorFilter(PorterDuffColorFilter((context?.let { rh.gac(it, info.nightscout.androidaps.core.R.attr.dialogFragmentBackground) }!!), PorterDuff.Mode.SRC_IN)) + + dialog?.window?.setBackgroundDrawable(drawable) + _binding = DialogWizardBinding.inflate(inflater, container, false) return binding.root } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt index c20789e4d0..1dea0c50a6 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt @@ -13,8 +13,6 @@ import javax.inject.Inject class ChooseOperationDialog : DialogFragmentWithDate() { - @Inject lateinit var rh: ResourceHelper - private var checkedIndex = -1 private var _binding: AutomationDialogChooseOperationBinding? = null diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt index 8634e6982f..57e4902472 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/BolusProgressDialog.kt @@ -1,5 +1,9 @@ package info.nightscout.androidaps.dialogs +import android.content.Context +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +import android.graphics.drawable.Drawable import android.os.Bundle import android.os.SystemClock import android.view.LayoutInflater @@ -7,6 +11,7 @@ import android.view.View import android.view.ViewGroup import android.view.Window import android.view.WindowManager +import androidx.core.content.ContextCompat import dagger.android.support.DaggerDialogFragment import info.nightscout.androidaps.activities.BolusProgressHelperActivity import info.nightscout.androidaps.core.R @@ -24,6 +29,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.shared.sharedPreferences.SP import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import javax.inject.Inject @@ -37,6 +43,7 @@ class BolusProgressDialog : DaggerDialogFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var uel: UserEntryLogger + @Inject lateinit var sp: SP private val disposable = CompositeDisposable() @@ -83,6 +90,15 @@ class BolusProgressDialog : DaggerDialogFragment() { isCancelable = false dialog?.setCanceledOnTouchOutside(false) + val drawable: Drawable? = context?.let { ContextCompat.getDrawable(it, R.drawable.dialog) } + if ( sp.getBoolean(R.string.key_use_dark_mode, true)) { + drawable?.setColorFilter(PorterDuffColorFilter((rh.gc(R.color.background_dark)), PorterDuff.Mode.SRC_IN)) + } else { + drawable?.setColorFilter(PorterDuffColorFilter((rh.gc(R.color.background_light)), PorterDuff.Mode.SRC_IN)) + } + + dialog?.window?.setBackgroundDrawable(drawable) + _binding = DialogBolusprogressBinding.inflate(inflater, container, false) return binding.root } diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt index 8c74786594..83d0c54013 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt @@ -2,6 +2,9 @@ package info.nightscout.androidaps.dialogs import android.app.DatePickerDialog import android.app.TimePickerDialog +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +import android.graphics.drawable.Drawable import android.os.Bundle import android.text.format.DateFormat import android.view.View @@ -10,6 +13,7 @@ import android.view.Window import android.view.WindowManager import android.widget.Button import android.widget.TextView +import androidx.core.content.ContextCompat import androidx.fragment.app.FragmentManager import dagger.android.support.DaggerDialogFragment import info.nightscout.androidaps.core.R @@ -17,6 +21,7 @@ import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.extensions.toVisibility +import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import java.util.* import javax.inject.Inject @@ -26,6 +31,7 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() { @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var sp: SP @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var rh: ResourceHelper fun interface OnValueChangedListener { fun onValueChanged(value: Long) @@ -68,6 +74,11 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() { dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) isCancelable = true dialog?.setCanceledOnTouchOutside(false) + + val drawable: Drawable? = context?.let { ContextCompat.getDrawable(it, info.nightscout.androidaps.core.R.drawable.dialog) } + drawable?.setColorFilter(PorterDuffColorFilter((context?.let { rh.gac(it, info.nightscout.androidaps.core.R.attr.dialogFragmentBackground) }!!), PorterDuff.Mode.SRC_IN)) + + dialog?.window?.setBackgroundDrawable(drawable) } fun updateDateTime(timeMs: Long) { diff --git a/core/src/main/res/drawable-hdpi/dialog.xml b/core/src/main/res/drawable-hdpi/dialog.xml new file mode 100644 index 0000000000..35266fa9fd --- /dev/null +++ b/core/src/main/res/drawable-hdpi/dialog.xml @@ -0,0 +1,21 @@ + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/res/values-night/colors.xml b/core/src/main/res/values-night/colors.xml index 643368416e..f667f08368 100644 --- a/core/src/main/res/values-night/colors.xml +++ b/core/src/main/res/values-night/colors.xml @@ -25,9 +25,13 @@ #1c171c #FFFFFF - #424242 + #000000 #B3FFFFFF + + #262626 + #FFFFFF + #d0d0d0 @color/white diff --git a/core/src/main/res/values-night/styles.xml b/core/src/main/res/values-night/styles.xml index 3bd4ff2ea0..da02bfa5b8 100644 --- a/core/src/main/res/values-night/styles.xml +++ b/core/src/main/res/values-night/styles.xml @@ -113,6 +113,9 @@ @color/splashBackground @color/black + + @color/background_dark + 12dp