package com.projectsacrifice.game; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.WindowInsets; import android.view.WindowInsetsController; import android.view.WindowManager; public final class MainActivity extends Activity { private static final String ACTIVE_SESSION_STATE = "active_session_v2"; private GameView gameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); gameView = new GameView(this); if (savedInstanceState != null) { byte[] encoded = savedInstanceState.getByteArray(ACTIVE_SESSION_STATE); if (encoded != null) gameView.restoreSessionFromActivityState(encoded); } setContentView(gameView); hideSystemUi(); } @Override protected void onSaveInstanceState(Bundle outState) { if (gameView != null) { byte[] encoded = gameView.saveSessionForActivityState(); if (encoded != null) outState.putByteArray(ACTIVE_SESSION_STATE, encoded); } super.onSaveInstanceState(outState); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) hideSystemUi(); } @Override protected void onPause() { super.onPause(); if (gameView != null) gameView.setPaused(true); } @Override protected void onResume() { super.onResume(); if (gameView != null) gameView.setPaused(false); hideSystemUi(); } @Override public void onBackPressed() { if (gameView != null && gameView.handleBack()) return; super.onBackPressed(); } private void hideSystemUi() { if (android.os.Build.VERSION.SDK_INT >= 30) { WindowInsetsController controller = getWindow().getInsetsController(); if (controller != null) { controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars()); controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); } } else { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE ); } } public GameView gameViewForAutomation() { return gameView; } }