TransparentActivity.uts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Activity from "android.app.Activity";
  2. import Bundle from 'android.os.Bundle';
  3. import Build from 'android.os.Build';
  4. import View from 'android.view.View';
  5. import Color from 'android.graphics.Color';
  6. import WindowManager from 'android.view.WindowManager';
  7. import { getGlobalNotificationProgressCallBack, getGlobalNotificationProgressFinishCallBack, setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack} from './callbacks.uts';
  8. import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
  9. export class TransparentActivity extends Activity {
  10. constructor() {
  11. super()
  12. }
  13. @Suppress("DEPRECATION")
  14. override onCreate(savedInstanceState : Bundle | null) {
  15. super.onCreate(savedInstanceState)
  16. this.fullScreen(this)
  17. const action = this.getIntent().getAction()
  18. if (action == ACTION_DOWNLOAD_FINISH) {
  19. setTimeout(() => {
  20. getGlobalNotificationProgressFinishCallBack()?.()
  21. setGlobalNotificationProgressFinishCallBack(() => { })
  22. }, 100)
  23. this.overridePendingTransition(0, 0)
  24. }
  25. if (action == ACTION_DOWNLOAD_PROGRESS) {
  26. setTimeout(() => {
  27. getGlobalNotificationProgressCallBack()?.()
  28. setGlobalNotificationProgressCallBack(() => { })
  29. }, 100)
  30. this.overridePendingTransition(0, 0)
  31. }
  32. setTimeout(() => {
  33. this.finish()
  34. }, 20)
  35. }
  36. @Suppress("DEPRECATION")
  37. private fullScreen(activity : Activity) {
  38. if (Build.VERSION.SDK_INT >= 19) {
  39. if (Build.VERSION.SDK_INT >= 21) {
  40. const window = activity.getWindow();
  41. const decorView = window.getDecorView();
  42. const option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
  43. decorView.setSystemUiVisibility(option);
  44. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
  45. window.setStatusBarColor(Color.TRANSPARENT);
  46. } else {
  47. const window = activity.getWindow();
  48. const attributes = window.getAttributes();
  49. const flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
  50. attributes.flags |= flagTranslucentStatus;
  51. window.setAttributes(attributes);
  52. }
  53. }
  54. }
  55. }