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(android): correct mobile home gestures and overlay navigation
aixialunbb07e9553103
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xmlindex de0de6f..be9234b 100644--- a/app/src/main/AndroidManifest.xml+++ b/app/src/main/AndroidManifest.xml@@ -203,6 +203,7 @@Theme.Body.Stage.NoPreview,它让前者不闪黑。 --><activityandroid:name=".ui.SelfCheckActivity"+ android:autoRemoveFromRecents="true"android:theme="@style/Theme.Body.Stage.NoPreview"android:exported="true"android:launchMode="singleTop"@@ -246,6 +247,8 @@android:name=".ui.TextInputActivity"android:theme="@android:style/Theme.Translucent.NoTitleBar"android:excludeFromRecents="true"+ android:autoRemoveFromRecents="true"+ android:taskAffinity=""android:launchMode="singleTop"android:windowSoftInputMode="adjustResize"android:exported="false"diff --git a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt b/app/src/main/java/net/kuafuai/andee/BodyCoreService.ktindex c8cefd6..ea6b309 100644--- a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt+++ b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt@@ -365,6 +365,22 @@ class BodyCoreService : Service() {dispatcher.compactForUser()}+ // A user home gesture must also leave the app underneath the overlay.+ override fun onHomeSwipe() {+ dispatcher.compactForUser()+ val handled = ScreenBodyService.get()?.performGlobalAction(+ AccessibilityService.GLOBAL_ACTION_HOME,+ ) == true+ if (!handled) {+ runCatching {+ startActivity(Intent(Intent.ACTION_MAIN).apply {+ addCategory(Intent.CATEGORY_HOME)+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ })+ }.onFailure { android.util.Log.w("BodyCoreService", "Cannot open home", it) }+ }+ }+/*** Re-show a page from the scrollback, or read a message fullscreen.*@@ -1191,6 +1207,8 @@ class BodyCoreService : Service() {return}typingFromFullscreen = true+ // The short-lived Activity may not emit its own accessibility event.+ noteOwnActivity()net.kuafuai.andee.ui.TextInputActivity.start(this, then)}@@ -1211,6 +1229,7 @@ class BodyCoreService : Service() {* a better reason than the user's place does.*/private fun typingFinished() {+ noteOwnActivity()window.setTypingTop(0)window.setAway(false)if (typingFromFullscreen && !window.isCompact()) dispatcher.expand()@@ -1364,6 +1383,7 @@ class BodyCoreService : Service() {* app the brain is about to drive.*/private fun closeTyping() {+ if (net.kuafuai.andee.ui.TextInputActivity.isShowing) noteOwnActivity()net.kuafuai.andee.ui.TextInputActivity.dismiss()}@@ -1445,6 +1465,7 @@ class BodyCoreService : Service() {android.content.IntentFilter().apply {addAction(android.content.Intent.ACTION_SCREEN_ON)addAction(android.content.Intent.ACTION_SCREEN_OFF)+ addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)},androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED,)@@ -1483,7 +1504,26 @@ class BodyCoreService : Service() {private val screenReceiver = object : android.content.BroadcastReceiver() {override fun onReceive(c: android.content.Context?, i: android.content.Intent?) {- screenOn = i?.action != android.content.Intent.ACTION_SCREEN_OFF+ when (i?.action) {+ Intent.ACTION_SCREEN_ON -> screenOn = true+ Intent.ACTION_SCREEN_OFF -> screenOn = false+ // Home can leave the launcher already in front behind our overlay,+ // so there may be no accessibility foreground change to observe.+ Intent.ACTION_CLOSE_SYSTEM_DIALOGS -> {+ val reason = i.getStringExtra("reason")+ // Recentapps also accompanies our own task transitions.+ // Ignore those delayed broadcasts, but keep the system edge+ // gesture working when Android owns the touch stream.+ val internalTransition = android.os.SystemClock.uptimeMillis() -+ ownActivityTransitionAt < 1_000L+ if ((reason == "homekey" || (reason == "recentapps" && !internalTransition)) &&+ ::window.isInitialized && ::dispatcher.isInitialized && !window.isCompact()+ ) {+ android.util.Log.i("AndeeNavigation", "fold from system reason=$reason")+ dispatcher.compactForUser()+ }+ }+ }}}@@ -1641,7 +1681,82 @@ class BodyCoreService : Service() {* body happens to be up to hear about it. What needs a body is the scene* logic, and that is all this does.*/- fun noteForegroundPackage(pkg: String) {+ /** Navigation between apps, excluding transient keyboard and system windows. */+ private val homeNavigation = net.kuafuai.andee.ui.HomeNavigationTracker()++ /** The launcher package — what "home" resolves to. Cached; it does not change while we run. */+ private val homePackage: String? by lazy {+ packageManager.resolveActivity(+ Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0,+ )?.activityInfo?.packageName+ }++ /**+ * The launcher's home *activity*, the class that is only ever in front when+ * the user is actually on the home screen. On this ROM that is+ * `com.hihonor.android.launcher.unihome.UniHomeLauncher`; a slow home swipe+ * passes through the recents `ListView` first, so both count in+ * [noteForegroundPackage] — but the launcher's menu, its folders and every+ * systemui surface report the same package under different class names, and+ * none of them are home.+ */+ private val homeActivity: String? by lazy {+ packageManager.resolveActivity(+ Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0,+ )?.activityInfo?.name+ }++ /**+ * Whether [cls] is the launcher's home activity, tolerating the short class+ * name some ROMs report in the event in place of the fully-qualified one+ * [homeActivity] resolves to.+ */+ private fun isHomeActivity(cls: String?): Boolean {+ val ha = homeActivity ?: return false+ if (cls == null) return false+ if (cls == ha) return true+ val simple = ha.substringAfterLast('.')+ return cls == simple || cls.endsWith(".$simple")+ }++ /** Input methods do not change the app navigation tracked by [homeNavigation]. */+ private val inputMethodPackages: Set<String> by lazy {+ runCatching {+ val imm = getSystemService(android.content.Context.INPUT_METHOD_SERVICE)+ as android.view.inputmethod.InputMethodManager+ imm.enabledInputMethodList.map { it.packageName }.toSet()+ }.getOrDefault(emptySet())+ }++ private var ownActivityTransitionAt = 0L++ /** Mark an app-owned trampoline even when it finishes before accessibility sees it. */+ fun noteOwnActivity() {+ ownActivityTransitionAt = android.os.SystemClock.uptimeMillis()+ homeNavigation.note(packageName, packageName, homePackage, false)+ }++ fun noteForegroundPackage(pkg: String, cls: String? = null) {+ val returnedFromAnotherApp = homeNavigation.note(+ pkg, packageName, homePackage,+ pkg in inputMethodPackages || pkg == "android" || pkg == "com.android.systemui",+ )+ // The launcher entry expands the overlay and immediately finishes.+ // That can report Home again without ever reporting our short-lived+ // Activity. A launcher -> launcher event is therefore not navigation;+ // folding on it makes every subsequent icon launch close itself.+ // Explicit Home/Recents uses the system-dialog receiver, and an upward+ // swipe on the card uses onHomeSwipe, even with Home already underneath.+ val isRecents = pkg == homePackage &&+ (cls == RECENTS_CLASS || cls == "$homePackage.quickstep.RecentsActivity")+ val isHomeSurface = pkg == homePackage && isHomeActivity(cls)+ val wentHome = isRecents || (isHomeSurface && returnedFromAnotherApp)+ if (wentHome) android.util.Log.i("AndeeNavigation", "fold from foreground pkg=$pkg cls=$cls")+ if (wentHome && ::window.isInitialized && ::dispatcher.isInitialized &&+ !window.isCompact()+ ) {+ dispatcher.compactForUser()+ }maybeAutoEnterScene(pkg)}@@ -3440,6 +3555,14 @@ class BodyCoreService : Service() {private const val TAG = "Body"+ /**+ * The window class the launcher reports for its recents screen. A slow+ * home swipe drags through recents before it lands on home, and folding+ * on it is what ties the fold to the swipe itself rather than only to+ * the gesture's end. See [noteForegroundPackage].+ */+ private const val RECENTS_CLASS = "android.widget.ListView"+/** Start-intent extra: also claim the microphone. See [promoteForMicrophone]. */private const val EXTRA_MICROPHONE = "microphone"diff --git a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.ktindex 4d42892..5e7db0b 100644--- a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt+++ b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt@@ -82,10 +82,12 @@ class ScreenBodyService : AccessibilityService() {*/override fun onAccessibilityEvent(event: AccessibilityEvent?) {if (event == null) return- if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {- event.packageName?.toString()?.let { pkg ->- net.kuafuai.andee.device.DeviceState.foregroundPkg = pkg- BodyCoreService.get()?.noteForegroundPackage(pkg)+ when (event.eventType) {+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> {+ event.packageName?.toString()?.let { pkg ->+ net.kuafuai.andee.device.DeviceState.foregroundPkg = pkg+ BodyCoreService.get()?.noteForegroundPackage(pkg, event.className?.toString())+ }}}BodyCoreService.get()?.noteAccessibilityEvent(event)diff --git a/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt b/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.ktindex 4c9a5a4..04d3012 100644--- a/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt@@ -201,6 +201,18 @@ class FloatingWindowUi(/** ⤡ in the subtitle band — the user asking for the screen back. */fun onMinimizeClick()+ /**+ * A swipe up from the bottom edge of the full card — the system home+ * gesture, which a fullscreen touchable overlay would otherwise swallow+ * before the launcher ever saw it (a touch that has entered this window+ * cannot be forwarded by returning false from `onTouchEvent`). The+ * window detects it itself and reports it, because that is the one path+ * that does not need the accessibility service — which this ROM is free+ * to revoke. The host folds the card, exactly as [onMinimizeClick]+ * does: the two are the same intent reached by two gestures.+ */+ fun onHomeSwipe()+/*** Two taps on the ball — the user wants to type instead of talk.*@@ -525,6 +537,14 @@ class FloatingWindowUi(private var slide: ValueAnimator? = null+ /**+ * The fold/unfold animation in flight, or null. Owns the root view's scale+ * during a zoom between the full card and the corner square — see+ * [enterCompact] and [exitCompact]. Separate from [slide], which is the+ * compact ball's perch slide and never overlaps a fold.+ */+ private var foldAnim: ValueAnimator? = null+fun isShown(): Boolean = root != null/**@@ -563,10 +583,13 @@ class FloatingWindowUi(gravity = Gravity.TOP or Gravity.STARTx = dm.widthPixels - side - dp(COMPACT_MARGIN_DP)y = dm.heightPixels - side - dp(COMPACT_MARGIN_DP)- // FLAG_LAYOUT_IN_SCREEN alone is not enough: since API 30 the window- // also fits the system-bar insets by default, so on the Honor phone a- // MATCH_PARENT card still started below the status bar and stopped- // above the navigation bar. Zero lets the card cover the display.+ // Truly edge-to-edge. Since API 30 the window fits the system-bar+ // insets by default (statusBars | navigationBars | captionBar), so a+ // MATCH_PARENT card stopped below the status bar *and* above the+ // navigation bar — a band of the user's wallpaper left at the bottom+ // is exactly the "not fullscreen" look. Fit nothing so the card runs+ // from the display's top to its bottom; the toolbar steps around the+ // status bar itself in [insetTopBar].fitInsetsTypes = 0layoutInDisplayCutoutMode =WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS@@ -2124,6 +2147,7 @@ class FloatingWindowUi(private fun enterCompact() {val p = params ?: returnslide?.cancel()+ foldAnim?.cancel()// A signboard cannot survive the fold — the window shrinks to a corner// square smaller than the pane. Evict through [signboardEvictor] so// CardUi's own callbacks fire (timeout semantics, holding state).@@ -2136,30 +2160,70 @@ class FloatingWindowUi(fullGeometry = intArrayOf(p.x, p.y, p.width, p.height)val side = dp(COMPACT_DP)val dm = context.resources.displayMetrics- p.width = side- p.height = side- // X is normally the resting corner, a thumb's width in (see- // [compactHomeY] for why the same gap is deliberate on Y). A fold that- // lands already clinging skips the resting corner entirely, though —- // nothing will slide it afterwards — so it has to be born at [perchX],- // or the same cling would sit at a different X depending on whether the- // task started before or after the card folded.- p.x = if (perched) perchX() else dm.widthPixels - side - dp(COMPACT_MARGIN_DP)- p.y = compactHomeY()- // The fold usually happens because a task started, so the perch is- // normally already wanted by the time we get here. Applied outright- // rather than slid: it is one motion with the fold, not a second one.- homeX = p.x- homeY = p.y+ // The corner the card is shrinking into. X is normally the resting+ // corner, a thumb's width in (see [compactHomeY] for why the same gap is+ // deliberate on Y). A fold that lands already clinging is born at+ // [perchX] instead, or the cling would sit at a different X depending on+ // whether the task started before or after the fold.+ val cx = if (perched) perchX() else dm.widthPixels - side - dp(COMPACT_MARGIN_DP)+ val cy = if (perched) perchY() else compactHomeY()+ // homeY is the *resting* corner, always — a clinging fold parks at+ // perchY but must climb back to compactHomeY when the task ends.+ homeX = cx+ homeY = compactHomeY()perchApplied = perched- if (perched) p.y = perchY()- applyCompactAppearance()- syncWorking()- retimeStroll()- // Everything above is placed from whatever [winYOrigin] the *last* fold- // measured, because the square's own frame does not exist until this one- // has been laid out. Re-measure as soon as it does.- ui.post { reseatCompact() }+ val v = root+ if (v == null) {+ // Nothing on screen yet — land the geometry outright.+ p.x = cx; p.y = cy; p.width = side; p.height = side+ applyCompactAppearance()+ syncWorking()+ retimeStroll()+ ui.post { reseatCompact() }+ return+ }+ // The card is a floating overlay, so it cannot ride the launcher's own+ // home animation — the system zooms the launcher behind it, which is+ // already at home. Draw the same zoom ourselves: shrink the whole card+ // toward the screen centre and fade the *window* out, then land the+ // window on the corner square once the content is gone. The fade is+ // window alpha — the ball is a TextureView, which does not reliably+ // honour a view-level alpha, but the compositor always honours `p.alpha`.+ // The fade is also what makes the shape change invisible — a tall card+ // cannot scale into a square corner without it.+ v.pivotX = dm.widthPixels / 2f+ v.pivotY = dm.heightPixels / 2f+ v.scaleX = 1f+ v.scaleY = 1f+ foldAnim = ValueAnimator.ofFloat(1f, 0f).apply {+ duration = FOLD_ANIM_MS+ interpolator = DecelerateInterpolator()+ addUpdateListener { a ->+ val t = a.animatedValue as Float+ val s = FOLD_SCALE_MIN + (1f - FOLD_SCALE_MIN) * t+ v.scaleX = s+ v.scaleY = s+ p.alpha = t+ runCatching { wm.updateViewLayout(v, p) }+ }+ addListener(object : android.animation.AnimatorListenerAdapter() {+ override fun onAnimationEnd(animation: android.animation.Animator) {+ foldAnim = null+ v.scaleX = 1f+ v.scaleY = 1f+ p.alpha = 1f+ p.x = cx; p.y = cy; p.width = side; p.height = side+ runCatching { wm.updateViewLayout(v, p) }+ applyCompactAppearance()+ syncWorking()+ retimeStroll()+ // Placed from whatever [winYOrigin] the last fold measured —+ // re-measure now that the square's own frame exists.+ ui.post { reseatCompact() }+ }+ })+ start()+ }}/**@@ -2190,51 +2254,99 @@ class FloatingWindowUi(private fun exitCompact() {val p = params ?: returnslide?.cancel()+ foldAnim?.cancel()// Same eviction as the fold, in the other direction: the card grows// and the signboard's compact geometry (ball at the window's bottom)// is meaningless inside it.evictSignboard()perchApplied = false+ // The restore target is always the full card: [enterCompact] snapshots+ // `fullGeometry` only after the typing band is put back, so it is the+ // edge-to-edge rectangle. Belt-and-braces against a stale compact-sized+ // value (service killed while folded, then restored): never grow to+ // anything smaller than about a third of the screen.+ val dm = context.resources.displayMetricsval g = fullGeometry ?: intArrayOf(0, 0,WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT,)- // Belt-and-braces: a stale stored geometry can be a compact-sized- // rectangle (service killed while folded, then restored). Growing the- // window to a corner square is worse than useless, so never restore- // anything smaller than about a third of the screen.- val dm = context.resources.displayMetrics- if (g[2] >= dm.widthPixels / 3 && g[3] >= dm.heightPixels / 3) {- p.x = g[0]; p.y = g[1]; p.width = g[2]; p.height = g[3]- } else {- p.x = 0; p.y = 0- p.width = WindowManager.LayoutParams.MATCH_PARENT- p.height = WindowManager.LayoutParams.MATCH_PARENT- }+ val whole = g[2] >= dm.widthPixels / 3 && g[3] >= dm.heightPixels / 3+ val fx = if (whole) g[0] else 0+ val fy = if (whole) g[1] else 0+ val fw = if (whole) g[2] else WindowManager.LayoutParams.MATCH_PARENT+ val fh = if (whole) g[3] else WindowManager.LayoutParams.MATCH_PARENTfullGeometry = null- // The fill is [applyWindow]'s to set — it is the only place that knows- // whether the compositor agreed to blur — and [setCompact] calls it- // immediately after this, before the next frame.+ val v = root+ if (v == null) {+ p.x = fx; p.y = fy; p.width = fw; p.height = fh+ showCardChrome()+ ball?.scaleX = BALL_SCALE+ ball?.scaleY = BALL_SCALE+ syncWorking()+ retimeStroll()+ return+ }+ // The chrome comes up immediately so it is there to grow into, and the+ // ball takes its full-card scale now. The real ball area height is set+ // by [BallHostFrame.onSizeChanged] once the window is laid out full.+ showCardChrome()+ ball?.scaleX = BALL_SCALE+ ball?.scaleY = BALL_SCALE+ // Land the window fullscreen first, then zoom the content up out of the+ // centre — the mirror of the fold's shrink-and-fade.+ p.x = fx; p.y = fy; p.width = fw; p.height = fh+ runCatching { wm.updateViewLayout(v, p) }+ v.pivotX = dm.widthPixels / 2f+ v.pivotY = dm.heightPixels / 2f+ v.scaleX = FOLD_SCALE_MIN+ v.scaleY = FOLD_SCALE_MIN+ p.alpha = 0f+ runCatching { wm.updateViewLayout(v, p) }+ foldAnim = ValueAnimator.ofFloat(0f, 1f).apply {+ duration = FOLD_ANIM_MS+ interpolator = DecelerateInterpolator()+ addUpdateListener { a ->+ val t = a.animatedValue as Float+ val s = FOLD_SCALE_MIN + (1f - FOLD_SCALE_MIN) * t+ v.scaleX = s+ v.scaleY = s+ p.alpha = t+ runCatching { wm.updateViewLayout(v, p) }+ }+ addListener(object : android.animation.AnimatorListenerAdapter() {+ override fun onAnimationEnd(animation: android.animation.Animator) {+ foldAnim = null+ v.scaleX = 1f+ v.scaleY = 1f+ p.alpha = 1f+ syncWorking()+ retimeStroll()+ }+ })+ start()+ }+ }++ /**+ * Bring back the pieces of the card that the fold hid. Called at the start+ * of an unfold, so the chrome is already there while the card grows into it.+ *+ * The two areas' heights are deliberately not set here: the window is still+ * the corner square, and the real height only exists after the layout pass+ * the geometry change is about to trigger — see [BallHostFrame.onSizeChanged].+ */+ private fun showCardChrome() {topBarView?.visibility = View.VISIBLEsceneChip?.visibility = if (sceneTitle != null) View.VISIBLE else View.GONEmuteKey?.visibility = View.VISIBLEhistoryView?.visibility = View.VISIBLEtipsView?.visibility = View.VISIBLEbackdrop?.visibility = View.VISIBLE- // The two areas' heights are deferred to [BallHostFrame.onSizeChanged]- // rather than computed here: the window is still the corner square at- // this point, and the real height only exists after the layout pass- // that this geometry change is about to trigger.- //// Anything that arrived while folded — which is most of it, since the- // card is folded for the whole time the assistant is working — has- // only ever been appended to a list that wasn't being laid out.+ // card is folded for the whole time the assistant is working — has only+ // ever been appended to a list that wasn't being laid out.historyView?.refresh()- ball?.scaleX = BALL_SCALE- ball?.scaleY = BALL_SCALE- syncWorking()- retimeStroll()}/**@@ -2248,7 +2360,12 @@ class FloatingWindowUi(private fun applyWindow() {val v = root ?: returnval p = params ?: return- p.alpha = if (captureHidden || away) 0f else 1f+ // A fold/unfold fade owns the window alpha while it runs — it writes+ // `p.alpha` on every frame, so this must not stamp 1f back over the+ // start value (which for an unfold is 0f). Outside that, capture and+ // away are the only reasons the whole window goes transparent.+ p.alpha = if (foldAnim?.isRunning == true) p.alpha+ else if (captureHidden || away) 0f else 1f// FLAG_LAYOUT_IN_SCREEN is what makes the unfolded card actually// fullscreen. Without it the window's frame is the *content* area —// the display minus the status and navigation bars — so a MATCH_PARENT@@ -2923,6 +3040,67 @@ class FloatingWindowUi(return dx * dx + dy * dy <= r * r}+ // ---- Home-swipe gesture (full card only) ----+ //+ // A swipe up from the bottom strip is the system home gesture, which+ // this fullscreen touchable overlay would otherwise swallow before the+ // launcher could act (a touch that has entered this window cannot be+ // forwarded by returning false from [onTouchEvent]). Detected here, in+ // [dispatchTouchEvent] and therefore on *every* event whether or not a+ // child owns the touch. [onInterceptTouchEvent] is only re-consulted on+ // MOVE once a child has claimed the DOWN, and the bottom strip is the+ // one place nothing does — the community row's gesture-bar padding is a+ // dead zone, so a DOWN there reaches no child and the intercept never+ // sees the MOVE that is the whole gesture. This is the one path to+ // "home folds the card" that does not need the accessibility service,+ // which this ROM is entitled to revoke.+ private var homeSwipeTracking = false+ private var homeSwipeStartX = 0f+ private var homeSwipeStartY = 0f+ private var homeSwipeCommitted = false++ override fun dispatchTouchEvent(e: MotionEvent): Boolean {+ if (e.actionMasked == MotionEvent.ACTION_DOWN) {+ // Use display coordinates: a resized card's bottom can sit+ // beside the input field, far above the phone's navigation edge.+ val screenBottom = wm.maximumWindowMetrics.bounds.bottom+ homeSwipeTracking = !compact && signboard == null && typingTop == 0 &&+ foldAnim?.isRunning != true &&+ HomeSwipeRegion.contains(e.rawY, screenBottom, dp(HOME_SWIPE_STRIP_DP))+ homeSwipeStartX = e.x+ homeSwipeStartY = e.y+ homeSwipeCommitted = false+ }+ if (homeSwipeTracking && e.actionMasked == MotionEvent.ACTION_MOVE &&+ !homeSwipeCommitted+ ) {+ val up = homeSwipeStartY - e.y+ if (up >= dp(HOME_SWIPE_TRIGGER_DP) &&+ up > kotlin.math.abs(e.x - homeSwipeStartX)+ ) {+ // Cancel a child's pending click/scroll before taking the gesture.+ val cancel = MotionEvent.obtain(e)+ cancel.action = MotionEvent.ACTION_CANCEL+ super.dispatchTouchEvent(cancel)+ cancel.recycle()+ homeSwipeCommitted = true+ android.util.Log.i("AndeeNavigation", "home swipe startY=$homeSwipeStartY rawY=${e.rawY} screenBottom=${wm.maximumWindowMetrics.bounds.bottom}")+ listeners.onHomeSwipe()+ }+ }+ val owned = homeSwipeTracking+ val handled = if (homeSwipeCommitted) true else super.dispatchTouchEvent(e)+ if (e.actionMasked == MotionEvent.ACTION_UP ||+ e.actionMasked == MotionEvent.ACTION_CANCEL+ ) {+ homeSwipeTracking = false+ homeSwipeCommitted = false+ }+ // Accept DOWN even over empty bottom padding. Returning false here+ // would prevent this window from receiving the rest of the swipe.+ return owned || handled+ }+override fun onTouchEvent(e: MotionEvent): Boolean {val p = params ?: return falseval ballH = ballAreaView?.height ?: return false@@ -3112,6 +3290,16 @@ class FloatingWindowUi(*/private const val SWIPE_COMMIT = 3f+ /** Only the physical navigation edge may start a home gesture. */+ private const val HOME_SWIPE_STRIP_DP = 24++ /**+ * How far the finger must climb from its down position, inside the home+ * strip, before the swipe is committed as home. Several times the touch+ * slop, so a tap on the community row's glyphs never reads as a swipe.+ */+ private const val HOME_SWIPE_TRIGGER_DP = 48+/*** Where the card splits: ball above, scrollback below. Also the touch* boundary between them (see [BallHostFrame.onSizeChanged]) — the list@@ -3200,6 +3388,20 @@ class FloatingWindowUi(private const val PERCH_SLIDE_MS = 240L+ /**+ * How long the card takes to zoom between full and folded. Kept near the+ * perch slide so the two motions read as one family, and short enough+ * that a fold never delays a task starting — see [enterCompact].+ */+ private const val FOLD_ANIM_MS = 220L++ /**+ * How far the card shrinks during a fold before it fades out. Not the+ * corner square's own scale — the card is tall and the corner is square,+ * so the two can never match; the fade covers the hand-off.+ */+ private const val FOLD_SCALE_MIN = 0.5f+/** The last-few-pixels pull onto the ledge when a drag lets go. */private const val SNAP_MS = 150Ldiff --git a/app/src/main/java/net/kuafuai/andee/ui/HomeNavigationTracker.kt b/app/src/main/java/net/kuafuai/andee/ui/HomeNavigationTracker.ktnew file mode 100644index 0000000..e18eaf4--- /dev/null+++ b/app/src/main/java/net/kuafuai/andee/ui/HomeNavigationTracker.kt@@ -0,0 +1,14 @@+package net.kuafuai.andee.ui++/** Tracks app navigation without mistaking IME/system-window events for leaving an app. */+internal class HomeNavigationTracker {+ private var previousApp: String? = null++ fun note(pkg: String, ownPackage: String, homePackage: String?, transient: Boolean): Boolean {+ if (transient) return false+ val previous = previousApp+ previousApp = pkg+ return homePackage != null && pkg == homePackage && previous != null &&+ previous != homePackage && previous != ownPackage+ }+}diff --git a/app/src/main/java/net/kuafuai/andee/ui/HomeSwipeRegion.kt b/app/src/main/java/net/kuafuai/andee/ui/HomeSwipeRegion.ktnew file mode 100644index 0000000..ed5b2e6--- /dev/null+++ b/app/src/main/java/net/kuafuai/andee/ui/HomeSwipeRegion.kt@@ -0,0 +1,7 @@+package net.kuafuai.andee.ui++/** Screen-space hit test, independent of the overlay's resized height. */+internal object HomeSwipeRegion {+ fun contains(rawY: Float, screenBottom: Int, edgeSize: Int): Boolean =+ rawY >= screenBottom - edgeSize && rawY < screenBottom+}diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.ktindex 76bf764..9aaa682 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt@@ -266,6 +266,11 @@ class SelfCheckActivity : StageActivity() {*/private var settings: SettingsUi? = null+ /** The icon is a trampoline to an overlay, not a blank recent-task card. */+ private fun finishLauncherEntry() {+ if (isTaskRoot) finishAndRemoveTask() else finish()+ }+override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)@@ -361,8 +366,9 @@ class SelfCheckActivity : StageActivity() {val svc = BodyCoreService.get()if (!restored && !checkOpen && !carrying && svc != null && svc.ensureOverlays()) {+ svc.noteOwnActivity()svc.dispatcherForNotification()?.expand()- finish()+ finishLauncherEntry()return}// Accessibility is ours and the overlay grant is in hand, so the ball@@ -373,7 +379,7 @@ class SelfCheckActivity : StageActivity() {// checklist for a device that is working, which is the exact report// this branch was rewritten to stop producing.if (!restored && !checkOpen && !carrying && svc == null && ScreenBodyService.get() != null && Settings.canDrawOverlays(this)) {- finish()+ finishLauncherEntry()return}diff --git a/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.ktindex 8d6ed88..03f059d 100644--- a/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.kt@@ -242,6 +242,15 @@ class TextInputActivity : Activity() {backdrop.setImageBitmap(bmp)backdrop.foreground = ColorDrawable(Backdrop.scrim())}+ // Tap the empty space above the strip = done typing. The field keeps+ // focus otherwise — an EditText never lets go on its own — and the pill+ // has no ✕, only camera/album/words/send. Clearing focus hides the+ // keyboard, and the inset listener below already closes the field once+ // the keys are really gone ([scheduleCloseWhenGone]).+ backdrop.setOnClickListener {+ field.clearFocus()+ hideKeyboard()+ }// One row, anchored at the bottom. See the backdrop above for why the// window is no longer see-through.@@ -673,6 +682,14 @@ class TextInputActivity : Activity() {}}+ private fun hideKeyboard() {+ runCatching { field.windowInsetsController?.hide(android.view.WindowInsets.Type.ime()) }+ runCatching {+ (getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)+ .hideSoftInputFromWindow(field.windowToken, 0)+ }+ }+private fun glyph(label: String, color: String, onClick: () -> Unit): TextView =TextView(this).apply {text = label