TransparentActivity.uts 2.0 KB
Newer Older
1 2 3 4 5 6
import Activity from "android.app.Activity";
import Bundle from 'android.os.Bundle';
import Build from 'android.os.Build';
import View from 'android.view.View';
import Color from 'android.graphics.Color';
import WindowManager from 'android.view.WindowManager';
7
import { globalNotificationProgressFinishCallBack, globalNotificationProgressCallBack } from './callbacks.uts';
8
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
9 10 11


export class TransparentActivity extends Activity {
12 13
	constructor() {
		super()
14
	}
15

16
  @Suppress("DEPRECATION")
17 18
	override onCreate(savedInstanceState : Bundle | null) {
		super.onCreate(savedInstanceState)
19
		this.fullScreen(this)
20 21 22 23 24 25 26 27
		const action = this.getIntent().getAction()
		if (action == ACTION_DOWNLOAD_FINISH) {
			setTimeout(() => {
				globalNotificationProgressFinishCallBack()
				globalNotificationProgressFinishCallBack = () => { }
			}, 100)
			this.overridePendingTransition(0, 0)
		}
28

29 30 31 32 33 34 35
		if (action == ACTION_DOWNLOAD_PROGRESS) {
			setTimeout(() => {
				globalNotificationProgressCallBack?.()
				globalNotificationProgressCallBack = () => { }
			}, 100)
			this.overridePendingTransition(0, 0)
		}
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
		setTimeout(() => {
			this.finish()
		}, 20)
	}


	@Suppress("DEPRECATION")
	private fullScreen(activity : Activity) {
		if (Build.VERSION.SDK_INT >= 19) {
			if (Build.VERSION.SDK_INT >= 21) {
				const window = activity.getWindow();
				const decorView = window.getDecorView();
				const option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
				decorView.setSystemUiVisibility(option);
				window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
				window.setStatusBarColor(Color.TRANSPARENT);
			} else {
				const window = activity.getWindow();
				const attributes = window.getAttributes();
				const flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
				attributes.flags |= flagTranslucentStatus;
				window.setAttributes(attributes);
			}
		}
	}
62
}