[docs] KeepHerSafeApps: Round trip on the tablet, the page between Android's bars, review, gaps closed, lessons
This commit is contained in:
@@ -6,12 +6,17 @@ package cz.mareknovak.domi.rosea
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.annotation.Keep
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
|
||||
class MainActivity : TauriActivity() {
|
||||
private var webView: WebView? = null
|
||||
@@ -20,6 +25,31 @@ class MainActivity : TauriActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
// Tauri's activity draws edge to edge, and the WebView does not reliably report the bars as
|
||||
// env(safe-area-inset-*): the clock sat over the title and the navigation bar over *Bring her
|
||||
// back from a file* (keep-her-safe-apps review). So the page is kept between the bars, and
|
||||
// the bars show the garden's own paper, light or dark as the system is.
|
||||
paintBehindBars()
|
||||
val bars = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content)) { view, insets ->
|
||||
val inset = insets.getInsets(bars)
|
||||
view.setPadding(inset.left, inset.top, inset.right, inset.bottom)
|
||||
WindowInsetsCompat.Builder(insets)
|
||||
.setInsets(WindowInsetsCompat.Type.systemBars(), Insets.NONE)
|
||||
.setInsets(WindowInsetsCompat.Type.displayCutout(), Insets.NONE)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
// The manifest lets the activity live through a theme change (uiMode), so the paint follows it here.
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
paintBehindBars()
|
||||
}
|
||||
|
||||
private fun paintBehindBars() {
|
||||
val night = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
window.decorView.setBackgroundColor(Color.parseColor(if (night) PAPER_DARK else PAPER))
|
||||
}
|
||||
|
||||
// *Save her to a file*: Android WebView does nothing with a blob download, so the game asks
|
||||
@@ -83,5 +113,8 @@ class MainActivity : TauriActivity() {
|
||||
private const val TAG = "RoseaFile"
|
||||
private val NAME = Regex("^rose-\\d{4}-\\d{2}-\\d{2}\\.json$")
|
||||
private const val MAX_CHARS = 8 * 1024 * 1024
|
||||
// --paper in packages/ui/src/tokens.css, light and dark; a test holds them equal.
|
||||
private const val PAPER = "#fbf6f1"
|
||||
private const val PAPER_DARK = "#1d1819"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user