Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ class FreeFlickEditorInsetsInstrumentedTest {
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
val bottom = maxOf(bars.bottom, insets.getInsets(WindowInsetsCompat.Type.ime()).bottom)
val bounds = win.windowManager.currentWindowMetrics.bounds
val label = context.getString(if (custom) R.string.popup_apply else R.string.popup_save)
val label = activity.getString(if (custom) R.string.popup_apply else R.string.popup_save)
val apply = descendants(root).filterIsInstance<TextView>().singleOrNull { it.text == label } ?: return false
val location = IntArray(2); apply.getLocationOnScreen(location)
val rect = Rect(location[0], location[1], location[0] + apply.width, location[1] + apply.height)
val maxGap = (32 * root.resources.displayMetrics.density).toInt()
lastGeometry = "custom=$custom ime=$ime bounds=$bounds bars=$bars bottom=$bottom action=$rect rootPadding=${root.paddingBottom}"
val rootLocation = IntArray(2); root.getLocationOnScreen(rootLocation)
lastGeometry = "custom=$custom ime=$ime bounds=$bounds bars=$bars bottom=$bottom action=$rect " +
"rootY=${rootLocation[1]} rootHeight=${root.height} rootPadding=${root.paddingBottom} " +
"softInputMode=${win.attributes.softInputMode}"
return apply.isShown && apply.isEnabled && rect.width() > 0 && rect.height() > 0 &&
rect.left >= bounds.left + bars.left && rect.right <= bounds.right - bars.right &&
rect.top >= bounds.top + bars.top && rect.bottom <= bounds.bottom - bottom &&
Expand All @@ -76,22 +79,35 @@ class FreeFlickEditorInsetsInstrumentedTest {
@Test fun customEditorKeepsApplyAboveSystemBarsAndImeAfterRecreation() = checkEditor(true)
@Test fun builtInEditorKeepsSaveAboveSystemBarsAndImeWithoutDoublePadding() = checkEditor(false)

private fun checkEditor(custom: Boolean) {
@Test fun builtInEditorOpensFromSearchWhileTheImeIsAlreadyVisible() = checkEditor(false, true)

private fun checkEditor(custom: Boolean, visibleImeAtEntry: Boolean = false) {
assumeTrue("Use an isolated review app", context.packageName.endsWith(".settingsuxreview"))
ActivityScenario.launch<MainActivity>(Intent(context, MainActivity::class.java)).use { scenario ->
scenario.awaitSettingsContentReady()
if (visibleImeAtEntry) {
scenario.onActivity { activity ->
(activity.supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main) as NavHostFragment)
.navController.navigate(R.id.settingSearchFragment)
}
await(scenario, "Search did not show the IME") {
ViewCompat.getRootWindowInsets(it.window.decorView)?.isVisible(WindowInsetsCompat.Type.ime()) == true
}
}
scenario.onActivity { activity ->
if (custom) CustomFreeFlickEditorDialog.create(PopupKeyConfigCodec.encode(PopupKeyConfigCodec.create("review-key", "tap")))
.showNow(activity.supportFragmentManager, "insets-editor")
else (activity.supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main) as NavHostFragment)
.navController.navigate(R.id.popupMapEditorFragment)
}
await(scenario, "Editor did not open") { editor(it, custom)?.view != null }
scenario.onActivity { activity ->
val root = editor(activity, custom)!!.requireView()
WindowCompat.getInsetsController(window(activity, custom), root).hide(WindowInsetsCompat.Type.ime())
if (!visibleImeAtEntry) {
scenario.onActivity { activity ->
val root = editor(activity, custom)!!.requireView()
WindowCompat.getInsetsController(window(activity, custom), root).hide(WindowInsetsCompat.Type.ime())
}
await(scenario, "Actions overlap system bars or have excessive bottom padding") { safeActions(it, custom, false) }
}
await(scenario, "Actions overlap system bars or have excessive bottom padding") { safeActions(it, custom, false) }
scenario.onActivity { activity ->
val field = descendants(editor(activity, custom)!!.requireView()).filterIsInstance<TextInputEditText>().first()
field.requestFocus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,38 @@ class PopupMapEditorFragment : Fragment() {
refresh()
editorReady = true
return column().apply {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
var currentInsets: WindowInsetsCompat? = null
fun applyEditorInsets(view: View, insets: WindowInsetsCompat) {
val safeTypes = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
val bars = insets.getInsets(safeTypes)
val rootBars = ViewCompat.getRootWindowInsets(view)?.getInsets(safeTypes) ?: bars
// MainActivity already applies/consumes system bars; the dialog does not.
// Subtract an ancestor's bottom inset from IME padding to apply it once.
val ancestorBottom = (rootBars.bottom - bars.bottom).coerceAtLeast(0)
val imeBottom = (insets.getInsets(WindowInsetsCompat.Type.ime()).bottom - ancestorBottom).coerceAtLeast(0)
view.updatePadding(left = bars.left, top = bars.top, right = bars.right,
bottom = maxOf(bars.bottom, imeBottom))
val ime = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
val bottom = if (android.os.Build.VERSION.SDK_INT >= 30 && view.isLaidOut) {
val location = IntArray(2)
view.getLocationOnScreen(location)
val windowBottom = requireActivity().windowManager.currentWindowMetrics.bounds.bottom
// adjustResize may already have removed the IME area from this view.
// Apply only the overlap that remains after the parent's layout/insets.
val overlap = (location[1] + view.height - (windowBottom - ime))
.coerceIn(0, ime)
maxOf(bars.bottom, overlap)
} else {
val ancestorBottom = (rootBars.bottom - bars.bottom).coerceAtLeast(0)
maxOf(bars.bottom, (ime - ancestorBottom).coerceAtLeast(0))
}
view.updatePadding(left = bars.left, top = bars.top, right = bars.right, bottom = bottom)
}
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
currentInsets = insets
applyEditorInsets(view, insets)
insets
}
addOnLayoutChangeListener { view, _, _, _, _, _, _, _, _ ->
// Updating padding inside layout can leave weighted children at their old size.
view.post {
if (view.isAttachedToWindow) currentInsets?.let { applyEditorInsets(view, it) }
}
}
doOnAttach { root -> root.post { ViewCompat.requestApplyInsets(root) } }
addView(scroll,LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0,1f))
addView(footer,LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT))
Expand Down
Loading