mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 03:01:51 +08:00
definitions fixed
This commit is contained in:
2
platform/package.json
Normal file
2
platform/package.json
Normal file
@ -0,0 +1,2 @@
|
||||
{ "name" : "platform",
|
||||
"main" : "platform.js" }
|
81
platform/platform.android.ts
Normal file
81
platform/platform.android.ts
Normal file
@ -0,0 +1,81 @@
|
||||
/* tslint:disable:class-name */
|
||||
import definition = require("platform");
|
||||
import enums = require("ui/enums");
|
||||
import application = require("application");
|
||||
|
||||
export module platformNames {
|
||||
export var android = "Android";
|
||||
export var ios = "iOS";
|
||||
}
|
||||
|
||||
// This is a "static" class and it is used like a name-space.
|
||||
// It is not meant to be initialized - thus it is not capitalized
|
||||
export class device implements definition.device {
|
||||
private static MIN_TABLET_PIXELS = 600;
|
||||
private static _model: string;
|
||||
private static _osVersion: string;
|
||||
private static _sdkVersion: string;
|
||||
private static _deviceType: string;
|
||||
|
||||
static get os(): string {
|
||||
return platformNames.android;
|
||||
}
|
||||
|
||||
static get osVersion(): string {
|
||||
if (!device._osVersion) {
|
||||
device._osVersion = android.os.Build.VERSION.RELEASE;
|
||||
}
|
||||
|
||||
return device._osVersion;
|
||||
}
|
||||
|
||||
static get model(): string {
|
||||
if (!device._model) {
|
||||
device._model = android.os.Build.MODEL;
|
||||
}
|
||||
|
||||
return device._model;
|
||||
}
|
||||
|
||||
static get sdkVersion(): string {
|
||||
if (!device._sdkVersion) {
|
||||
device._sdkVersion = android.os.Build.VERSION.SDK;
|
||||
}
|
||||
|
||||
return device._sdkVersion;
|
||||
}
|
||||
|
||||
static get deviceType(): string {
|
||||
if (!device._deviceType) {
|
||||
var dips = Math.min(screen.mainScreen.widthPixels, screen.mainScreen.heightPixels) / screen.mainScreen.scale;
|
||||
|
||||
// If the device has more than 600 dips it is considered to be a tablet.
|
||||
if (dips >= device.MIN_TABLET_PIXELS) {
|
||||
device._deviceType = enums.DeviceType.Tablet;
|
||||
}
|
||||
else {
|
||||
device._deviceType = enums.DeviceType.Phone;
|
||||
}
|
||||
}
|
||||
|
||||
return device._deviceType;
|
||||
}
|
||||
}
|
||||
|
||||
var mainScreenInfo: definition.ScreenMetrics;
|
||||
|
||||
// This is a "static" class and it is used like a name-space.
|
||||
// It is not meant to be initialized - thus it is not capitalized
|
||||
export class screen implements definition.screen {
|
||||
static get mainScreen(): definition.ScreenMetrics {
|
||||
if (!mainScreenInfo) {
|
||||
var metrics = application.android.context.getResources().getDisplayMetrics();
|
||||
mainScreenInfo = {
|
||||
widthPixels: metrics.widthPixels,
|
||||
heightPixels: metrics.heightPixels,
|
||||
scale: metrics.density
|
||||
}
|
||||
}
|
||||
return mainScreenInfo;
|
||||
}
|
||||
}
|
79
platform/platform.d.ts
vendored
Normal file
79
platform/platform.d.ts
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/* tslint:disable:class-name */
|
||||
/**
|
||||
* Contains all kinds of information about the device, its operating system and software.
|
||||
*/
|
||||
declare module "platform" {
|
||||
|
||||
/*
|
||||
* Enum holding platform names.
|
||||
*/
|
||||
export module platformNames {
|
||||
export var android: string;
|
||||
export var ios: string;
|
||||
}
|
||||
|
||||
/*
|
||||
* An object containing device specific information.
|
||||
*/
|
||||
export class device {
|
||||
/**
|
||||
* Gets the model of the device.
|
||||
* For example: "Nexus 5" or "iPhone.
|
||||
*/
|
||||
static model: string;
|
||||
|
||||
/**
|
||||
* Gets the model of the device.
|
||||
* For example: "Android" or "iOS".
|
||||
*/
|
||||
static os: string;
|
||||
|
||||
/**
|
||||
* Gets the OS version.
|
||||
* For example: 4.4.4(android), 8.1(ios)
|
||||
*/
|
||||
static osVersion: string;
|
||||
|
||||
/**
|
||||
* Gets the OS version.
|
||||
* For example: 19(android), 8.1(ios).
|
||||
*/
|
||||
static sdkVersion: string;
|
||||
|
||||
/**
|
||||
* Gets the type current device.
|
||||
* Available values: "phone", "tablet".
|
||||
*/
|
||||
static deviceType: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object containing screen information.
|
||||
*/
|
||||
export interface ScreenMetrics {
|
||||
/**
|
||||
* Gets the absolute width of the screen in pixels.
|
||||
*/
|
||||
widthPixels: number;
|
||||
|
||||
/**
|
||||
* Gets the absolute height of the screen in pixels.
|
||||
*/
|
||||
heightPixels: number;
|
||||
|
||||
/**
|
||||
* The logical density of the display. This is a scaling factor for the Density Independent Pixel unit.
|
||||
*/
|
||||
scale: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object describing general information about a display.
|
||||
*/
|
||||
export class screen {
|
||||
/**
|
||||
* Gets information about the main screen of the current device.
|
||||
*/
|
||||
static mainScreen: ScreenMetrics;
|
||||
}
|
||||
}
|
80
platform/platform.ios.ts
Normal file
80
platform/platform.ios.ts
Normal file
@ -0,0 +1,80 @@
|
||||
/* tslint:disable:class-name */
|
||||
import definition = require("platform");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
export module platformNames {
|
||||
export var android = "Android";
|
||||
export var ios = "iOS";
|
||||
}
|
||||
|
||||
// This is a "static" class and it is used like a name-space.
|
||||
// It is not meant to be initialized - thus it is not capitalized
|
||||
export class device implements definition.device {
|
||||
private static _model: string;
|
||||
private static _osVersion: string;
|
||||
private static _sdkVersion: string;
|
||||
private static _deviceType: string;
|
||||
|
||||
static get os(): string {
|
||||
return platformNames.ios;
|
||||
}
|
||||
|
||||
static get osVersion(): string {
|
||||
if (!device._osVersion) {
|
||||
device._osVersion = UIDevice.currentDevice().systemVersion;
|
||||
}
|
||||
|
||||
return device._osVersion;
|
||||
}
|
||||
|
||||
static get model(): string {
|
||||
if (!device._model) {
|
||||
device._model = UIDevice.currentDevice().model;
|
||||
}
|
||||
|
||||
return device._model;
|
||||
}
|
||||
|
||||
static get sdkVersion(): string {
|
||||
if (!device._sdkVersion) {
|
||||
device._sdkVersion = UIDevice.currentDevice().systemVersion;
|
||||
}
|
||||
|
||||
return device._sdkVersion;
|
||||
}
|
||||
|
||||
static get deviceType(): string {
|
||||
if (!device._deviceType) {
|
||||
if (UIDevice.currentDevice().userInterfaceIdiom === UIUserInterfaceIdiom.UIUserInterfaceIdiomPhone) {
|
||||
device._deviceType = enums.DeviceType.Phone;
|
||||
}
|
||||
else {
|
||||
device._deviceType = enums.DeviceType.Tablet;
|
||||
}
|
||||
}
|
||||
|
||||
return device._deviceType;
|
||||
}
|
||||
}
|
||||
|
||||
var mainScreenInfo: definition.ScreenMetrics = null;
|
||||
|
||||
// This is a "static" class and it is used like a name-space.
|
||||
// It is not meant to be initialized - thus it is not capitalized
|
||||
export class screen implements definition.screen {
|
||||
static get mainScreen(): definition.ScreenMetrics {
|
||||
if (!mainScreenInfo) {
|
||||
var mainScreen = UIScreen.mainScreen();
|
||||
if (mainScreen) {
|
||||
var size = mainScreen.bounds.size;
|
||||
var scale = mainScreen.scale;
|
||||
mainScreenInfo = {
|
||||
widthPixels: size.width * scale,
|
||||
heightPixels: size.height * scale,
|
||||
scale: scale
|
||||
}
|
||||
}
|
||||
}
|
||||
return mainScreenInfo;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user