CrownActivity.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2012-2023 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: MIT
  4. */
  5. package com.example.myapplication;
  6. import android.app.NativeActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. public class CrownActivity extends NativeActivity
  10. {
  11. static
  12. {
  13. System.loadLibrary("crown");
  14. }
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. // Init additional stuff here (ads, etc.)
  19. }
  20. @Override
  21. public void onDestroy() {
  22. // Destroy additional stuff here (ads, etc)
  23. super.onDestroy();
  24. }
  25. @Override
  26. public void onWindowFocusChanged(boolean hasFocus) {
  27. super.onWindowFocusChanged(hasFocus);
  28. if (hasFocus) {
  29. hideSystemUI();
  30. }
  31. }
  32. private void hideSystemUI() {
  33. // Enables regular immersive mode.
  34. // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
  35. // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  36. View decorView = getWindow().getDecorView();
  37. decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
  38. // Set the content to appear under the system bars so that the
  39. // content doesn't resize when the system bars hide and show.
  40. | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  41. | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  42. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  43. // Hide the nav bar and status bar
  44. | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  45. | View.SYSTEM_UI_FLAG_FULLSCREEN
  46. );
  47. }
  48. private void showSystemUI() {
  49. // Shows the system bars by removing all the flags
  50. // except for the ones that make the content appear under the system bars.
  51. View decorView = getWindow().getDecorView();
  52. decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  53. | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  54. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  55. );
  56. }
  57. }