forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.android.ts
More file actions
135 lines (109 loc) · 3.44 KB
/
platform.android.ts
File metadata and controls
135 lines (109 loc) · 3.44 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* tslint:disable:class-name */
import definition = require("platform");
import utils = require("utils/utils");
import * as enumsModule from "ui/enums";
const MIN_TABLET_PIXELS = 600;
export module platformNames {
export var android = "Android";
export var ios = "iOS";
}
class Device implements definition.Device {
private _manufacturer: string;
private _model: string;
private _osVersion: string;
private _sdkVersion: string;
private _deviceType: string;
private _uuid: string;
private _language: string;
private _region: string;
get os(): string {
return platformNames.android;
}
get manufacturer(): string {
if (!this._manufacturer) {
this._manufacturer = android.os.Build.MANUFACTURER;
}
return this._manufacturer;
}
get osVersion(): string {
if (!this._osVersion) {
this._osVersion = android.os.Build.VERSION.RELEASE;
}
return this._osVersion;
}
get model(): string {
if (!this._model) {
this._model = android.os.Build.MODEL;
}
return this._model;
}
get sdkVersion(): string {
if (!this._sdkVersion) {
this._sdkVersion = android.os.Build.VERSION.SDK;
}
return this._sdkVersion;
}
get deviceType(): string {
if (!this._deviceType) {
var dips = Math.min(screen.mainScreen.widthPixels, screen.mainScreen.heightPixels) / screen.mainScreen.scale;
var enums: typeof enumsModule = require("ui/enums");
// If the device has more than 600 dips it is considered to be a tablet.
if (dips >= MIN_TABLET_PIXELS) {
this._deviceType = enums.DeviceType.Tablet;
}
else {
this._deviceType = enums.DeviceType.Phone;
}
}
return this._deviceType;
}
get uuid(): string {
if (!this._uuid) {
this._uuid = android.provider.Settings.Secure.getString(
utils.ad.getApplicationContext().getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID
);
}
return this._uuid;
}
get language(): string {
if (!this._language) {
this._language = java.util.Locale.getDefault().getLanguage().replace("_", "-");
}
return this._language;
}
get region(): string {
if(!this._region) {
this._region = java.util.Locale.getDefault().getCountry();
}
return this._region;
}
}
class MainScreen implements definition.ScreenMetrics {
private _metrics: android.util.DisplayMetrics;
private get metrics(): android.util.DisplayMetrics {
if (!this._metrics) {
this._metrics = utils.ad.getApplicationContext().getResources().getDisplayMetrics();
}
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;
}
}
export var device: definition.Device = new Device();
export module screen {
export var mainScreen = new MainScreen();
}