Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(ui): leave the cards their gutter on a portrait phone

booboosuic1ff37827efe
diff --git a/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt b/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt
index 87453d4..24d07c3 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt
@@ -703,9 +703,7 @@ class FirstRunUi(
return minOf(screen - dp(2 * GUTTER_DP), (screen * 0.96f).toInt())
}
- private fun screenW(): Int = wm?.currentWindowMetrics?.bounds?.width()
- ?: context.resources.displayMetrics.widthPixels
+ private fun screenW(): Int = Glass.usableSize(context).first
- private fun screenH(): Int = wm?.currentWindowMetrics?.bounds?.height()
- ?: context.resources.displayMetrics.heightPixels
+ private fun screenH(): Int = Glass.usableSize(context).second
}
diff --git a/app/src/main/java/net/kuafuai/andee/ui/Glass.kt b/app/src/main/java/net/kuafuai/andee/ui/Glass.kt
index b433815..3ad5267 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/Glass.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/Glass.kt
@@ -15,6 +15,7 @@ import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.ViewGroup
+import android.view.WindowInsets
import android.view.WindowManager
import android.view.animation.OvershootInterpolator
import android.view.animation.PathInterpolator
@@ -207,6 +208,23 @@ object Glass {
// ---- Window ----
+ /**
+ * Width and height a centred card can actually occupy: the display minus
+ * the status bar, navigation bar and cutout.
+ *
+ * Not `currentWindowMetrics.bounds` alone. An overlay without
+ * `FLAG_LAYOUT_IN_SCREEN` is laid out between the bars, so a card sized
+ * as "display minus a gutter" spends its gutter on the bars — invisible on
+ * a landscape tablet, flush against both bars on a portrait phone.
+ */
+ fun usableSize(context: Context): Pair<Int, Int> {
+ val m = (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).currentWindowMetrics
+ val i = m.windowInsets.getInsetsIgnoringVisibility(
+ WindowInsets.Type.systemBars() or WindowInsets.Type.displayCutout(),
+ )
+ return (m.bounds.width() - i.left - i.right) to (m.bounds.height() - i.top - i.bottom)
+ }
+
/**
* Ask the compositor to blur behind this window. Returns whether it agreed.
*
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
index 628744d..ef1a9cb 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
@@ -959,9 +959,7 @@ class SelfCheckUi(
return minOf(screen - dp(2 * GUTTER_DP), (screen * 0.96f).toInt())
}
- private fun screenW(): Int = wm?.currentWindowMetrics?.bounds?.width()
- ?: context.resources.displayMetrics.widthPixels
+ private fun screenW(): Int = Glass.usableSize(context).first
- private fun screenH(): Int = wm?.currentWindowMetrics?.bounds?.height()
- ?: context.resources.displayMetrics.heightPixels
+ private fun screenH(): Int = Glass.usableSize(context).second
}
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt
index 6ab763e..95826a2 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt
@@ -313,12 +313,12 @@ class SettingsUi(
* sides anyway; the point is only that it does not touch the edge.
*/
private fun cardWidth(): Int {
- val screen = wm.currentWindowMetrics.bounds.width()
+ val screen = Glass.usableSize(context).first
return minOf(screen - dp(2 * GUTTER_DP), (screen * 0.98f).toInt())
}
private fun cardHeight(): Int {
- val screen = wm.currentWindowMetrics.bounds.height()
+ val screen = Glass.usableSize(context).second
return minOf(screen - dp(2 * GUTTER_DP), (screen * 0.96f).toInt())
}