Skip to content

Commit

Permalink
fix: Notification overlay margins
Browse files Browse the repository at this point in the history
  • Loading branch information
axel358 committed Feb 6, 2024
1 parent c3ed192 commit aaa4418
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/cu/axel/smartdock/services/NotificationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/cu/axel/smartdock/utils/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/dock.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<cu.axel.smartdock.widgets.HoverInterceptorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/blue"
android:elevation="5dp" >

<Button
Expand All @@ -21,7 +22,7 @@
android:id="@+id/dock_trigger"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@android:color/transparent" />
android:background="@android:color/white" />

<RelativeLayout
android:id="@+id/dock_layout"
Expand Down

0 comments on commit aaa4418

Please sign in to comment.