Files
2024-07-01 09:28:59 -07:00

50 lines
1.1 KiB
TypeScript

import { Application } from '../../application';
class MainScreen {
private _metrics: android.util.DisplayMetrics;
private initMetrics(): void {
const nativeApp = Application.android.getNativeApplication();
nativeApp.getSystemService(android.content.Context.WINDOW_SERVICE).getDefaultDisplay().getRealMetrics(this._metrics);
}
private get metrics(): android.util.DisplayMetrics {
if (!this._metrics) {
this._metrics = new android.util.DisplayMetrics();
this.initMetrics();
}
return this._metrics;
}
get widthPixels(): number {
return this.metrics.widthPixels;
}
get heightPixels(): number {
return this.metrics.heightPixels;
}
get scale(): number {
return this.metrics.density;
}
get widthDIPs(): number {
return this.metrics.widthPixels / this.metrics.density;
}
get heightDIPs(): number {
return this.metrics.heightPixels / this.metrics.density;
}
public _updateMetrics(): void {
if (!this._metrics) {
this._metrics = new android.util.DisplayMetrics();
}
this.initMetrics();
}
}
export class Screen {
static mainScreen = new MainScreen();
}
// This retains compatibility with NS6
export const screen = Screen;