Fix Android window geometry, selection menu tracking
- SurfaceView windows are always translucent, so adjustResize cannot resize them: the keyboard overlapped the bottom of the window and the top bar sat under the status bar. Consume the insets in app instead: a smali-injected PadInsetsListener (identical block in build_emu.sh and build_phone.sh) shrinks the GioView to statusBarBottom..keyboardTop (or ..navBarTop) on every API 30+ insets dispatch, with setDecorFitsSystemWindows(false) so IME insets are delivered at targetSdk 34. - Fix a change-detection bug in the listener: the height write skipped the topMargin/bottomMargin checks on every IME state transition, so the margins were never applied while the keyboard animated. All three params are now checked with a single requestLayout on any change. - Selection menu now re-anchors to the selected word every frame while it is visible and hides when the word scrolls out of the viewport (positionSelectionMenu + regression test). - Doc: development_plan.md section 14 (invariants, geometry contract, build-script identity invariant). Verified on device: top bar below status bar and clickable, bottom bar flush with keyboard top (view 128..1517 at 1080x2400), BACK dismiss + re-tap re-raise without a show loop, typing saves, menu tracks scrolls.
This commit is contained in:
+119
-28
@@ -108,64 +108,155 @@ listener = '''
|
||||
|
||||
|
||||
# virtual methods
|
||||
# Resizes the GioView so the app draws above the visible keyboard instead of
|
||||
# behind it, and re-applies the status/nav bar insets as margins (the window
|
||||
# is edge-to-edge via setDecorFitsSystemWindows(false)).
|
||||
#
|
||||
# Coordinate frames: the window is full screen, but
|
||||
# DisplayMetrics.heightPixels is the app CONTENT height (status bar and nav
|
||||
# bar excluded). The typed insets are measured from the absolute display
|
||||
# edges, so the absolute display height is reconstructed as
|
||||
# contentH + statusTop + navBottom.
|
||||
#
|
||||
# v0 = statusTop, v1 = navBottom, v2 = imeInset, v3 = display height /
|
||||
# bottomLimit / height (int, sequential), v4 = object scratch, v5 = int
|
||||
# scratch. All registers <= v6 (const/16, if-* and invoke register lists are
|
||||
# 4-bit).
|
||||
.method public onApplyWindowInsets(Landroid/view/View;Landroid/view/WindowInsets;)Landroid/view/WindowInsets;
|
||||
.locals 4
|
||||
.locals 6
|
||||
|
||||
# int imeBottom = 0;
|
||||
const/4 v0, 0x0
|
||||
|
||||
# if (Build.VERSION.SDK_INT >= 30)
|
||||
# imeBottom = insets.getInsets(WindowInsets.Type.ime()).bottom;
|
||||
sget v1, Landroid/os/Build$VERSION;->SDK_INT:I
|
||||
const/4 v1, 0x0
|
||||
|
||||
const/16 v2, 0x1e
|
||||
const/4 v2, 0x0
|
||||
|
||||
if-lt v1, v2, :cond_pad_noime
|
||||
# content height (valid on every path; the API < 30 branch leaves the
|
||||
# inset values at 0)
|
||||
iget-object v4, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
|
||||
const/16 v1, 0x8
|
||||
invoke-virtual {v4}, Landroid/view/View;->getResources()Landroid/content/res/Resources;
|
||||
|
||||
invoke-virtual {p2, v1}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
move-result-object v4
|
||||
|
||||
move-result-object v1
|
||||
invoke-virtual {v4}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;
|
||||
|
||||
iget v0, v1, Landroid/graphics/Insets;->bottom:I
|
||||
move-result-object v4
|
||||
|
||||
iget v3, v4, Landroid/util/DisplayMetrics;->heightPixels:I
|
||||
|
||||
sget v4, Landroid/os/Build$VERSION;->SDK_INT:I
|
||||
|
||||
const/16 v5, 0x1e
|
||||
|
||||
# API < 30: no typed insets - fall through with all insets 0.
|
||||
if-lt v4, v5, :goto_pad_geom
|
||||
|
||||
# statusTop = insets.getInsets(Type.statusBars()).top
|
||||
const/4 v4, 0x1
|
||||
|
||||
invoke-virtual {p2, v4}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
|
||||
move-result-object v4
|
||||
|
||||
iget v0, v4, Landroid/graphics/Insets;->top:I
|
||||
|
||||
# navBottom = insets.getInsets(Type.navigationBars()).bottom
|
||||
const/4 v4, 0x6
|
||||
|
||||
invoke-virtual {p2, v4}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
|
||||
move-result-object v4
|
||||
|
||||
iget v1, v4, Landroid/graphics/Insets;->bottom:I
|
||||
|
||||
# imeInset = insets.getInsets(Type.ime()).bottom
|
||||
const/16 v4, 0x8
|
||||
|
||||
invoke-virtual {p2, v4}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
|
||||
move-result-object v4
|
||||
|
||||
iget v2, v4, Landroid/graphics/Insets;->bottom:I
|
||||
|
||||
:goto_pad_geom
|
||||
# absolute display height
|
||||
add-int v3, v3, v0
|
||||
|
||||
add-int v3, v3, v1
|
||||
|
||||
# bottomLimit: where the view bottom must not go below.
|
||||
# IME present: display bottom minus the IME inset (reaches the visible
|
||||
# keyboard top; the keyboard also covers the nav area).
|
||||
# otherwise: display bottom minus the nav bar.
|
||||
if-lez v2, :cond_pad_noime
|
||||
|
||||
sub-int v3, v3, v2
|
||||
|
||||
goto :goto_pad_bottom
|
||||
|
||||
:cond_pad_noime
|
||||
# int h = displayHeight - imeBottom;
|
||||
iget-object v1, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
sub-int v3, v3, v1
|
||||
|
||||
invoke-virtual {v1}, Landroid/view/View;->getResources()Landroid/content/res/Resources;
|
||||
:goto_pad_bottom
|
||||
# height = bottomLimit - statusTop, clamped to >= 0
|
||||
sub-int v3, v3, v0
|
||||
|
||||
move-result-object v1
|
||||
if-gez v3, :cond_pad_pos
|
||||
|
||||
invoke-virtual {v1}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;
|
||||
const/4 v3, 0x0
|
||||
|
||||
move-result-object v1
|
||||
:cond_pad_pos
|
||||
# apply to LayoutParams (height + topMargin = statusTop, bottomMargin =
|
||||
# navBottom)
|
||||
iget-object v4, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
|
||||
iget v1, v1, Landroid/util/DisplayMetrics;->heightPixels:I
|
||||
invoke-virtual {v4}, Landroid/view/View;->getLayoutParams()Landroid/view/ViewGroup$LayoutParams;
|
||||
|
||||
sub-int v1, v1, v0
|
||||
move-result-object v4
|
||||
|
||||
# if (mView.getLayoutParams().height != h) { ... = h; requestLayout(); }
|
||||
iget-object v2, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
check-cast v4, Landroid/view/ViewGroup$MarginLayoutParams;
|
||||
|
||||
invoke-virtual {v2}, Landroid/view/View;->getLayoutParams()Landroid/view/ViewGroup$LayoutParams;
|
||||
# v2 (free after geometry) = changed flag
|
||||
const/4 v2, 0x0
|
||||
|
||||
move-result-object v2
|
||||
iget v5, v4, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
|
||||
iget v3, v2, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
if-eq v5, v3, :cond_pad_checktop
|
||||
|
||||
if-eq v3, v1, :cond_pad_done
|
||||
iput v3, v4, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
|
||||
iput v1, v2, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
const/4 v2, 0x1
|
||||
|
||||
iget-object v3, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
:cond_pad_checktop
|
||||
iget v5, v4, Landroid/view/ViewGroup$MarginLayoutParams;->topMargin:I
|
||||
|
||||
invoke-virtual {v3}, Landroid/view/View;->requestLayout()V
|
||||
if-eq v5, v0, :cond_pad_checkbot
|
||||
|
||||
iput v0, v4, Landroid/view/ViewGroup$MarginLayoutParams;->topMargin:I
|
||||
|
||||
const/4 v2, 0x1
|
||||
|
||||
:cond_pad_checkbot
|
||||
iget v5, v4, Landroid/view/ViewGroup$MarginLayoutParams;->bottomMargin:I
|
||||
|
||||
if-eq v5, v1, :cond_pad_layout
|
||||
|
||||
iput v1, v4, Landroid/view/ViewGroup$MarginLayoutParams;->bottomMargin:I
|
||||
|
||||
const/4 v2, 0x1
|
||||
|
||||
:cond_pad_layout
|
||||
if-eqz v2, :cond_pad_done
|
||||
|
||||
iget-object v5, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
|
||||
invoke-virtual {v5}, Landroid/view/View;->requestLayout()V
|
||||
|
||||
:cond_pad_done
|
||||
return-object p2
|
||||
.end method
|
||||
|
||||
'''
|
||||
(base / "smali" / "org" / "gioui" / "PadInsetsListener.smali").write_text(listener)
|
||||
|
||||
|
||||
+119
-28
@@ -101,64 +101,155 @@ listener = '''
|
||||
|
||||
|
||||
# virtual methods
|
||||
# Resizes the GioView so the app draws above the visible keyboard instead of
|
||||
# behind it, and re-applies the status/nav bar insets as margins (the window
|
||||
# is edge-to-edge via setDecorFitsSystemWindows(false)).
|
||||
#
|
||||
# Coordinate frames: the window is full screen, but
|
||||
# DisplayMetrics.heightPixels is the app CONTENT height (status bar and nav
|
||||
# bar excluded). The typed insets are measured from the absolute display
|
||||
# edges, so the absolute display height is reconstructed as
|
||||
# contentH + statusTop + navBottom.
|
||||
#
|
||||
# v0 = statusTop, v1 = navBottom, v2 = imeInset, v3 = display height /
|
||||
# bottomLimit / height (int, sequential), v4 = object scratch, v5 = int
|
||||
# scratch. All registers <= v6 (const/16, if-* and invoke register lists are
|
||||
# 4-bit).
|
||||
.method public onApplyWindowInsets(Landroid/view/View;Landroid/view/WindowInsets;)Landroid/view/WindowInsets;
|
||||
.locals 4
|
||||
.locals 6
|
||||
|
||||
# int imeBottom = 0;
|
||||
const/4 v0, 0x0
|
||||
|
||||
# if (Build.VERSION.SDK_INT >= 30)
|
||||
# imeBottom = insets.getInsets(WindowInsets.Type.ime()).bottom;
|
||||
sget v1, Landroid/os/Build$VERSION;->SDK_INT:I
|
||||
const/4 v1, 0x0
|
||||
|
||||
const/16 v2, 0x1e
|
||||
const/4 v2, 0x0
|
||||
|
||||
if-lt v1, v2, :cond_pad_noime
|
||||
# content height (valid on every path; the API < 30 branch leaves the
|
||||
# inset values at 0)
|
||||
iget-object v4, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
|
||||
const/16 v1, 0x8
|
||||
invoke-virtual {v4}, Landroid/view/View;->getResources()Landroid/content/res/Resources;
|
||||
|
||||
invoke-virtual {p2, v1}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
move-result-object v4
|
||||
|
||||
move-result-object v1
|
||||
invoke-virtual {v4}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;
|
||||
|
||||
iget v0, v1, Landroid/graphics/Insets;->bottom:I
|
||||
move-result-object v4
|
||||
|
||||
iget v3, v4, Landroid/util/DisplayMetrics;->heightPixels:I
|
||||
|
||||
sget v4, Landroid/os/Build$VERSION;->SDK_INT:I
|
||||
|
||||
const/16 v5, 0x1e
|
||||
|
||||
# API < 30: no typed insets - fall through with all insets 0.
|
||||
if-lt v4, v5, :goto_pad_geom
|
||||
|
||||
# statusTop = insets.getInsets(Type.statusBars()).top
|
||||
const/4 v4, 0x1
|
||||
|
||||
invoke-virtual {p2, v4}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
|
||||
move-result-object v4
|
||||
|
||||
iget v0, v4, Landroid/graphics/Insets;->top:I
|
||||
|
||||
# navBottom = insets.getInsets(Type.navigationBars()).bottom
|
||||
const/4 v4, 0x6
|
||||
|
||||
invoke-virtual {p2, v4}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
|
||||
move-result-object v4
|
||||
|
||||
iget v1, v4, Landroid/graphics/Insets;->bottom:I
|
||||
|
||||
# imeInset = insets.getInsets(Type.ime()).bottom
|
||||
const/16 v4, 0x8
|
||||
|
||||
invoke-virtual {p2, v4}, Landroid/view/WindowInsets;->getInsets(I)Landroid/graphics/Insets;
|
||||
|
||||
move-result-object v4
|
||||
|
||||
iget v2, v4, Landroid/graphics/Insets;->bottom:I
|
||||
|
||||
:goto_pad_geom
|
||||
# absolute display height
|
||||
add-int v3, v3, v0
|
||||
|
||||
add-int v3, v3, v1
|
||||
|
||||
# bottomLimit: where the view bottom must not go below.
|
||||
# IME present: display bottom minus the IME inset (reaches the visible
|
||||
# keyboard top; the keyboard also covers the nav area).
|
||||
# otherwise: display bottom minus the nav bar.
|
||||
if-lez v2, :cond_pad_noime
|
||||
|
||||
sub-int v3, v3, v2
|
||||
|
||||
goto :goto_pad_bottom
|
||||
|
||||
:cond_pad_noime
|
||||
# int h = displayHeight - imeBottom;
|
||||
iget-object v1, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
sub-int v3, v3, v1
|
||||
|
||||
invoke-virtual {v1}, Landroid/view/View;->getResources()Landroid/content/res/Resources;
|
||||
:goto_pad_bottom
|
||||
# height = bottomLimit - statusTop, clamped to >= 0
|
||||
sub-int v3, v3, v0
|
||||
|
||||
move-result-object v1
|
||||
if-gez v3, :cond_pad_pos
|
||||
|
||||
invoke-virtual {v1}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;
|
||||
const/4 v3, 0x0
|
||||
|
||||
move-result-object v1
|
||||
:cond_pad_pos
|
||||
# apply to LayoutParams (height + topMargin = statusTop, bottomMargin =
|
||||
# navBottom)
|
||||
iget-object v4, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
|
||||
iget v1, v1, Landroid/util/DisplayMetrics;->heightPixels:I
|
||||
invoke-virtual {v4}, Landroid/view/View;->getLayoutParams()Landroid/view/ViewGroup$LayoutParams;
|
||||
|
||||
sub-int v1, v1, v0
|
||||
move-result-object v4
|
||||
|
||||
# if (mView.getLayoutParams().height != h) { ... = h; requestLayout(); }
|
||||
iget-object v2, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
check-cast v4, Landroid/view/ViewGroup$MarginLayoutParams;
|
||||
|
||||
invoke-virtual {v2}, Landroid/view/View;->getLayoutParams()Landroid/view/ViewGroup$LayoutParams;
|
||||
# v2 (free after geometry) = changed flag
|
||||
const/4 v2, 0x0
|
||||
|
||||
move-result-object v2
|
||||
iget v5, v4, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
|
||||
iget v3, v2, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
if-eq v5, v3, :cond_pad_checktop
|
||||
|
||||
if-eq v3, v1, :cond_pad_done
|
||||
iput v3, v4, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
|
||||
iput v1, v2, Landroid/view/ViewGroup$LayoutParams;->height:I
|
||||
const/4 v2, 0x1
|
||||
|
||||
iget-object v3, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
:cond_pad_checktop
|
||||
iget v5, v4, Landroid/view/ViewGroup$MarginLayoutParams;->topMargin:I
|
||||
|
||||
invoke-virtual {v3}, Landroid/view/View;->requestLayout()V
|
||||
if-eq v5, v0, :cond_pad_checkbot
|
||||
|
||||
iput v0, v4, Landroid/view/ViewGroup$MarginLayoutParams;->topMargin:I
|
||||
|
||||
const/4 v2, 0x1
|
||||
|
||||
:cond_pad_checkbot
|
||||
iget v5, v4, Landroid/view/ViewGroup$MarginLayoutParams;->bottomMargin:I
|
||||
|
||||
if-eq v5, v1, :cond_pad_layout
|
||||
|
||||
iput v1, v4, Landroid/view/ViewGroup$MarginLayoutParams;->bottomMargin:I
|
||||
|
||||
const/4 v2, 0x1
|
||||
|
||||
:cond_pad_layout
|
||||
if-eqz v2, :cond_pad_done
|
||||
|
||||
iget-object v5, p0, Lorg/gioui/PadInsetsListener;->mView:Landroid/view/View;
|
||||
|
||||
invoke-virtual {v5}, Landroid/view/View;->requestLayout()V
|
||||
|
||||
:cond_pad_done
|
||||
return-object p2
|
||||
.end method
|
||||
|
||||
'''
|
||||
(base / "smali" / "org" / "gioui" / "PadInsetsListener.smali").write_text(listener)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user