definitions fixed

This commit is contained in:
Erjan Gavalji
2015-03-03 10:34:40 +02:00
parent a03ce4ca1d
commit cc829e0152
705 changed files with 321431 additions and 148812 deletions

2
platform/package.json Normal file
View File

@ -0,0 +1,2 @@
{ "name" : "platform",
"main" : "platform.js" }

View 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
View 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
View 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;
}
}