MainActivity.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //% IMPORTS
  2. import android.view.ViewGroup;
  3. import android.view.WindowInsets.Type;
  4. import java.util.HashMap;
  5. import videodecode.VideoDecoder;
  6. //% END
  7. //% RESIZING_LAYOUT_BODY
  8. native static void onApplyInsets(
  9. int sys_left, int sys_top, int sys_right, int sys_bottom,
  10. int ime_left, int ime_top, int ime_right, int ime_bottom
  11. );
  12. //% END
  13. //% RESIZING_LAYOUT_ON_APPLY_WINDOW_INSETS
  14. {
  15. Insets imeInsets = insets.getInsets(WindowInsets.Type.ime());
  16. Insets sysInsets = insets.getInsets(WindowInsets.Type.systemBars());
  17. // Screen: (1440, 3064)
  18. // IME height: 1056
  19. // Sys insets: (0, 152, 0, 135)
  20. onApplyInsets(
  21. sysInsets.left, sysInsets.top, sysInsets.right, sysInsets.bottom,
  22. imeInsets.left, imeInsets.top, imeInsets.right, imeInsets.bottom
  23. );
  24. }
  25. // Workaround for Java error due to remaining body.
  26. // We handle the insets in our app directly.
  27. if (true)
  28. return insets;
  29. //% END
  30. //% MAIN_ACTIVITY_BODY
  31. public String getAppDataPath() {
  32. return getApplicationContext().getDataDir().getAbsolutePath();
  33. }
  34. public String getExternalStoragePath() {
  35. return getApplicationContext().getExternalFilesDir(null).getAbsolutePath();
  36. }
  37. public int getKeyboardHeight() {
  38. WindowInsets windowInsets = view.getRootWindowInsets();
  39. if (windowInsets == null) {
  40. return 0;
  41. }
  42. Insets imeInsets = windowInsets.getInsets(WindowInsets.Type.ime());
  43. Insets navInsets = windowInsets.getInsets(WindowInsets.Type.navigationBars());
  44. return Math.max(0, imeInsets.bottom - navInsets.bottom);
  45. }
  46. public float getScreenDensity() {
  47. return getResources().getDisplayMetrics().density;
  48. }
  49. public boolean isImeVisible() {
  50. View decorView = getWindow().getDecorView();
  51. WindowInsets insets = decorView.getRootWindowInsets();
  52. Insets imeInsets = insets.getInsets(WindowInsets.Type.ime());
  53. if (imeInsets == null)
  54. return false;
  55. return insets.isVisible(Type.ime());
  56. }
  57. public VideoDecoder createVideoDecoder() {
  58. VideoDecoder decoder = new VideoDecoder();
  59. decoder.setContext(this);
  60. return decoder;
  61. }
  62. //% END
  63. //% MAIN_ACTIVITY_ON_CREATE
  64. view.setFocusable(false);
  65. view.setFocusableInTouchMode(false);
  66. view.clearFocus();
  67. // Start a foreground service so the app stays awake
  68. Intent serviceIntent = new Intent(this, ForegroundService.class);
  69. startForegroundService(serviceIntent);
  70. //% END