-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMainActivity.android.ts
64 lines (51 loc) · 2.28 KB
/
MainActivity.android.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
62
63
64
import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame";
@JavaProxy("org.myApp.MainActivity")
class Activity extends android.app.Activity {
private _callbacks: AndroidActivityCallbacks;
protected onCreate(savedInstanceState: android.os.Bundle): void {
if (!this._callbacks) {
setActivityCallbacks(this);
}
this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
}
protected onSaveInstanceState(outState: android.os.Bundle): void {
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
}
protected onStart(): void {
this._callbacks.onStart(this, super.onStart);
}
protected onStop(): void {
this._callbacks.onStop(this, super.onStop);
}
protected onDestroy(): void {
this._callbacks.onDestroy(this, super.onDestroy);
}
public onBackPressed(): void {
this._callbacks.onBackPressed(this, super.onBackPressed);
}
public onRequestPermissionsResult(requestCode: number, permissions: Array<String>, grantResults: Array<number>): void {
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
}
protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
}
public dispatchKeyEvent(event) {
// Which direction did the key move (up/down)
let action = event.getAction();
// What keywas pressed
let keyCode = event.getKeyCode();
switch (keyCode) {
case android.view.KeyEvent.KEYCODE_VOLUME_UP:
// Check your event code (KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP etc)
console.log("KEYCODE_VOLUME_UP");
return true;
case android.view.KeyEvent.KEYCODE_VOLUME_DOWN:
// Check your event code (KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP etc)
console.log("KEYCODE_VOLUME_DOWN");
return true;
default:
// Let the system do what it wanted to do
return super.dispatchKeyEvent(event);
}
}
}