From aaa44189f31b82de4ca5bb96654050922376d2bb Mon Sep 17 00:00:00 2001 From: Axel358 Date: Tue, 6 Feb 2024 05:31:06 -0500 Subject: [PATCH] fix: Notification overlay margins --- .../fragments/AdvancedPreferences.kt | 1 + .../cu/axel/smartdock/services/DockService.kt | 2 +- .../smartdock/services/NotificationService.kt | 20 +++++++++---------- .../java/cu/axel/smartdock/utils/AppUtils.kt | 2 ++ app/src/main/res/layout/dock.xml | 3 ++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/cu/axel/smartdock/fragments/AdvancedPreferences.kt b/app/src/main/java/cu/axel/smartdock/fragments/AdvancedPreferences.kt index 3ba4872e..698b1d17 100644 --- a/app/src/main/java/cu/axel/smartdock/fragments/AdvancedPreferences.kt +++ b/app/src/main/java/cu/axel/smartdock/fragments/AdvancedPreferences.kt @@ -135,6 +135,7 @@ class AdvancedPreferences : PreferenceFragmentCompat() { dockHeight.setOnDialogShownListener(object : SliderPreference.OnDialogShownListener { override fun onDialogShown() { val slider = dockHeight.slider + slider.isTickVisible = false slider.labelBehavior = LabelFormatter.LABEL_GONE slider.stepSize = 1f slider.value = dockHeight.sharedPreferences!!.getString("dock_height", "58")!!.toFloat() diff --git a/app/src/main/java/cu/axel/smartdock/services/DockService.kt b/app/src/main/java/cu/axel/smartdock/services/DockService.kt index b56fc077..7905b893 100644 --- a/app/src/main/java/cu/axel/smartdock/services/DockService.kt +++ b/app/src/main/java/cu/axel/smartdock/services/DockService.kt @@ -749,7 +749,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On else { windowMode = if (Build.VERSION.SDK_INT >= 28) 5 else 2 options.setLaunchBounds( - AppUtils.makeLaunchBounds(context, mode!!, dockLayout.measuredHeight, preferLastDisplay)) + AppUtils.makeLaunchBounds(context, mode!!, dockHeight, preferLastDisplay)) } if (Build.VERSION.SDK_INT > 28 && preferLastDisplay) options.setLaunchDisplayId(DeviceUtils.getSecondaryDisplay(this).displayId) diff --git a/app/src/main/java/cu/axel/smartdock/services/NotificationService.kt b/app/src/main/java/cu/axel/smartdock/services/NotificationService.kt index 5c3b821e..88a27aa4 100644 --- a/app/src/main/java/cu/axel/smartdock/services/NotificationService.kt +++ b/app/src/main/java/cu/axel/smartdock/services/NotificationService.kt @@ -60,7 +60,7 @@ class NotificationService : NotificationListenerService(), OnNotificationClickLi private var notificationArea: LinearLayout? = null private var preferLastDisplay = false private var y = 0 - private var x = 0 + private var margins = 0 private var dockHeight: Int = 0 private lateinit var notificationLayoutParams: WindowManager.LayoutParams override fun onCreate() { @@ -72,13 +72,13 @@ class NotificationService : NotificationListenerService(), OnNotificationClickLi windowManager = context.getSystemService(WINDOW_SERVICE) as WindowManager notificationLayoutParams = Utils.makeWindowParams(Utils.dpToPx(context, 300), -2, context, preferLastDisplay) - x = Utils.dpToPx(context, 2) + margins = Utils.dpToPx(context, 2) dockHeight = Utils.dpToPx(context, sharedPreferences.getString("dock_height", "56")!!.toInt()) - y = if (Build.VERSION.SDK_INT > 31 && sharedPreferences.getBoolean("navbar_fix", true)) + y = (if (Build.VERSION.SDK_INT > 31 && sharedPreferences.getBoolean("navbar_fix", true)) dockHeight - DeviceUtils.getNavBarHeight(context) else - dockHeight - notificationLayoutParams.x = x + dockHeight) + margins + notificationLayoutParams.x = margins notificationLayoutParams.gravity = Gravity.BOTTOM or Gravity.END notificationLayoutParams.y = y notificationLayout = LayoutInflater.from(this).inflate(R.layout.notification_popup, @@ -137,7 +137,7 @@ class NotificationService : NotificationListenerService(), OnNotificationClickLi ColorUtils.applySecondaryColor(this@NotificationService, sharedPreferences, notifCancelBtn) val notificationIcon = AppUtils.getAppIcon(context, sbn.packageName) notifIcon.setImageDrawable(notificationIcon) - val iconPadding = Utils.dpToPx(context, sharedPreferences.getString("icon_padding", "5")!!.toInt()) + val iconPadding = Utils.dpToPx(context, sharedPreferences.getString("icon_padding", "5")!!.toInt()) var iconBackground = -1 when (sharedPreferences.getString("icon_shape", "circle")) { "circle" -> iconBackground = R.drawable.circle @@ -277,7 +277,7 @@ class NotificationService : NotificationListenerService(), OnNotificationClickLi preferLastDisplay) layoutParams.gravity = Gravity.BOTTOM or Gravity.END layoutParams.y = y - layoutParams.x = x + layoutParams.x = margins layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH notificationPanel = LayoutInflater.from(context).inflate(R.layout.notification_panel, null) cancelAllBtn = notificationPanel!!.findViewById(R.id.cancel_all_n_btn) @@ -415,12 +415,12 @@ class NotificationService : NotificationListenerService(), OnNotificationClickLi updateLayoutParams() } - private fun updateLayoutParams(){ + private fun updateLayoutParams() { dockHeight = Utils.dpToPx(context, sharedPreferences.getString("dock_height", "56")!!.toInt()) - y = if (Build.VERSION.SDK_INT > 31 && sharedPreferences.getBoolean("navbar_fix", true)) + y = (if (Build.VERSION.SDK_INT > 31 && sharedPreferences.getBoolean("navbar_fix", true)) dockHeight - DeviceUtils.getNavBarHeight(context) else - dockHeight + dockHeight) + margins notificationLayoutParams.y = y windowManager.updateViewLayout(notificationLayout, notificationLayoutParams) diff --git a/app/src/main/java/cu/axel/smartdock/utils/AppUtils.kt b/app/src/main/java/cu/axel/smartdock/utils/AppUtils.kt index e1e72325..0218d37a 100644 --- a/app/src/main/java/cu/axel/smartdock/utils/AppUtils.kt +++ b/app/src/main/java/cu/axel/smartdock/utils/AppUtils.kt @@ -25,6 +25,7 @@ import java.io.FileReader import java.io.FileWriter import java.io.IOException import android.os.Process +import android.widget.Toast object AppUtils { const val PINNED_LIST = "pinned.lst" @@ -265,6 +266,7 @@ object AppUtils { val statusHeight = DeviceUtils.getStatusBarHeight(context) val navHeight = DeviceUtils.getNavBarHeight(context) val diff = if (dockHeight - navHeight > 0) dockHeight - navHeight else 0 + Toast.makeText(context, dockHeight.toString() + " " + navHeight + " " + diff.toString(), Toast.LENGTH_LONG).show() val usableHeight = if (Build.VERSION.SDK_INT > 31 && sharedPreferences.getBoolean("navbar_fix", true)) deviceHeight - diff - DeviceUtils.getStatusBarHeight(context) else diff --git a/app/src/main/res/layout/dock.xml b/app/src/main/res/layout/dock.xml index e2624da2..bde7bf05 100644 --- a/app/src/main/res/layout/dock.xml +++ b/app/src/main/res/layout/dock.xml @@ -1,6 +1,7 @@