fix(android): add SplashActivity with video intro — fix NPE by moving insetsController after setContentView
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
|||||||
|
package com.sicherhaven.eventify
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.media.MediaPlayer
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.WindowInsets
|
||||||
|
import android.view.WindowInsetsController
|
||||||
|
import android.view.WindowManager
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.VideoView
|
||||||
|
|
||||||
|
class SplashActivity : Activity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
window.setFlags(
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
|
)
|
||||||
|
|
||||||
|
// White background matches splash logo/video content
|
||||||
|
val container = FrameLayout(this)
|
||||||
|
container.setBackgroundColor(Color.WHITE)
|
||||||
|
setContentView(container, ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
))
|
||||||
|
|
||||||
|
// Edge-to-edge: hide both status bar and navigation bar (after setContentView so DecorView exists)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
window.insetsController?.let {
|
||||||
|
it.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
|
||||||
|
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.decorView.systemUiVisibility = (
|
||||||
|
View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val videoView = VideoView(this)
|
||||||
|
container.addView(videoView, FrameLayout.LayoutParams(
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT
|
||||||
|
))
|
||||||
|
|
||||||
|
val uri = Uri.parse("android.resource://$packageName/${R.raw.splash_video}")
|
||||||
|
videoView.setVideoURI(uri)
|
||||||
|
|
||||||
|
videoView.setOnPreparedListener { mp ->
|
||||||
|
mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING)
|
||||||
|
mp.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
videoView.setOnCompletionListener {
|
||||||
|
startActivity(Intent(this, MainActivity::class.java))
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
videoView.setOnErrorListener { _, _, _ ->
|
||||||
|
startActivity(Intent(this, MainActivity::class.java))
|
||||||
|
finish()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
videoView.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
android/app/src/main/res/raw/splash_video.mp4
Normal file
BIN
android/app/src/main/res/raw/splash_video.mp4
Normal file
Binary file not shown.
Reference in New Issue
Block a user