diff --git a/app/src/main/java/com/quillstudios/pokegoalshelper/ui/FloatingUIActivity.kt b/app/src/main/java/com/quillstudios/pokegoalshelper/ui/FloatingUIActivity.kt index f68aedf..35bb558 100644 --- a/app/src/main/java/com/quillstudios/pokegoalshelper/ui/FloatingUIActivity.kt +++ b/app/src/main/java/com/quillstudios/pokegoalshelper/ui/FloatingUIActivity.kt @@ -74,9 +74,6 @@ class FloatingUIActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - // Make activity transparent and overlay-capable - setupTransparentOverlay() - // Bind to the ScreenCaptureService bindToScreenCaptureService() @@ -92,6 +89,12 @@ class FloatingUIActivity : ComponentActivity() { } } + override fun onResume() { + super.onResume() + // Setup overlay after window is fully initialized + setupTransparentOverlay() + } + override fun onDestroy() { super.onDestroy() if (serviceBound) { @@ -101,16 +104,17 @@ class FloatingUIActivity : ComponentActivity() { } private fun setupTransparentOverlay() { - // Make the activity transparent and fullscreen - window.apply { - // Hide system UI (navigation bar, status bar) - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { - setDecorFitsSystemWindows(false) - insetsController?.let { controller -> - controller.hide(android.view.WindowInsets.Type.systemBars()) - controller.systemBarsBehavior = android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE - } - } else { + try { + // Make the activity transparent and fullscreen + window?.apply { + // Hide system UI (navigation bar, status bar) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { + setDecorFitsSystemWindows(false) + insetsController?.let { controller -> + controller.hide(android.view.WindowInsets.Type.systemBars()) + controller.systemBarsBehavior = android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + } else { @Suppress("DEPRECATION") decorView.systemUiVisibility = ( android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE @@ -138,6 +142,10 @@ class FloatingUIActivity : ComponentActivity() { @Suppress("DEPRECATION") setType(WindowManager.LayoutParams.TYPE_PHONE) } + } + } catch (e: Exception) { + Log.e(TAG, "Error setting up transparent overlay", e) + // Continue without overlay setup if it fails } }