-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperformance-monitor.android.ts
54 lines (44 loc) · 1.4 KB
/
performance-monitor.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
import { PerformanceMonitorApi, PerformanceMonitorStartOptions } from "./performance-monitor.common";
import * as appModule from "tns-core-modules/application";
declare let jp: any;
/**
* See https://github.com/wasabeef/Takt
*/
export class PerformanceMonitor implements PerformanceMonitorApi {
public start(options?: PerformanceMonitorStartOptions): Promise<any> {
return new Promise((resolve, reject) => {
// needs a little delay on certain devices, otherwise it hides again almost instantly
setTimeout(() => {
let opts = options || {};
let monitor = jp.wasabeef.takt.Takt.stock(appModule.android.nativeApp);
// TODO add as option
monitor.seat(jp.wasabeef.takt.Seat.TOP_CENTER);
if (opts.textColor) {
monitor.color(opts.textColor.android);
}
monitor.size(15.0);
monitor.alpha(0.7);
if (opts.onSample) {
monitor.listener(new jp.wasabeef.takt.Audience({
heartbeat: function (fps: number) {
opts.onSample({
fps: Math.round(fps * 10) / 10
});
}
}))
}
if (opts.hide) {
monitor.hide();
}
monitor.play();
resolve();
}, 3000);
});
}
public stop(): Promise<any> {
return new Promise((resolve, reject) => {
jp.wasabeef.takt.Takt.finish();
resolve();
});
}
}