diff --git a/.gitignore b/.gitignore index df9f0c2..2c6f035 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ DerivedData/ .swiftpm/configuration/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc - +.history # macOS files .DS_Store diff --git a/android/src/main/java/com/dumon/plugin/geolocation/DumonGeolocation.kt b/android/src/main/java/com/dumon/plugin/geolocation/DumonGeolocation.kt index d43947f..794da84 100644 --- a/android/src/main/java/com/dumon/plugin/geolocation/DumonGeolocation.kt +++ b/android/src/main/java/com/dumon/plugin/geolocation/DumonGeolocation.kt @@ -1,6 +1,11 @@ package com.dumon.plugin.geolocation import android.Manifest +import android.graphics.Color +import android.os.Build +import android.view.View +import android.view.WindowInsetsController +import android.view.WindowManager import com.getcapacitor.* import com.getcapacitor.annotation.CapacitorPlugin import com.getcapacitor.annotation.Permission @@ -129,6 +134,62 @@ class DumonGeolocation : Plugin() { } } + @PluginMethod + fun configureEdgeToEdge(call: PluginCall) { + val bgColorHex = call.getString("bgColor") ?: "#FFFFFF" + val style = call.getString("style") ?: "DARK" + + val window = bridge?.activity?.window + if (window == null) { + call.reject("No active window") + return + } + + // Background color + val parsedColor = Color.parseColor(bgColorHex) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + window.statusBarColor = parsedColor + window.navigationBarColor = parsedColor + } + + // Edge-to-edge fit + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.setDecorFitsSystemWindows(true) + val controller = window.insetsController + if (controller != null) { + if (style.uppercase() == "DARK") { + controller.setSystemBarsAppearance( + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } else { + controller.setSystemBarsAppearance( + 0, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } + } + } else { + @Suppress("DEPRECATION") + window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) + + @Suppress("DEPRECATION") + val flags = if (style.uppercase() == "DARK") { + View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } else { + 0 + } + + @Suppress("DEPRECATION") + window.decorView.systemUiVisibility = flags + } + + call.resolve() + } + private fun emitPositionUpdate() { val now = System.currentTimeMillis() if (now - lastEmitTimestamp < emitIntervalMs) return