forked from bangslosan/YaaST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.System.js
More file actions
155 lines (134 loc) · 4.96 KB
/
API.System.js
File metadata and controls
155 lines (134 loc) · 4.96 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Copyright (c) 2014 by Center Open Middleware. All Rights Reserved.
* Titanium Appcelerator 3.3.0GA
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
'use strict';
var System = (function() {
/** It provides several useful methods to collect information about current device.
* @alias API.System
* @namespace */
var _self = {};
/** Check Apple platform.
* @method
* @return {Boolean} */
_self.isApple = function isApple(){
return (Ti.Platform.getOsname() === 'ipad' || Ti.Platform.getOsname() === 'iphone');
};
/** Check Apple Retina Display.
* @method
* @return {Boolean} */
_self.isRetina = function isRetina(){
if(_self.isApple()){
if(_self.isTablet()) return Ti.Platform.displayCaps.getDpi() === 260;
else return Ti.Platform.displayCaps.getDpi() === 320;
}
else return false;
};
/** Check Tablet Display
* @method
* @return {Boolean} */
_self.isTablet = function isTablet() {
return (Ti.Platform.getOsname() === 'ipad') || (Ti.Platform.getOsname() === 'android' && (
(Ti.Platform.Android.getPhysicalSizeCategory() === Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_LARGE) ||
(Ti.Platform.Android.getPhysicalSizeCategory() === Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_XLARGE))
) || Math.min(Ti.Platform.displayCaps.getPlatformHeight(), Ti.Platform.displayCaps.getPlatformWidth()) >= 400;
};
/** Get device platform.
* @method
* @return {String} It should return 'iOS' or 'Android' */
_self.getDeviceOs = function getDeviceOs() {
if (_self.isApple()) return 'iOS';
else return 'Android';
};
/** Get System's OS version.
* @method
* @return {String} */
_self.getVersion = function getVersion() {
return Ti.Platform.getVersion();
};
/** Get System's OS version String.
* @method
* @return {String} Android => Version Name. iOS = Version Number */
_self.getVersionString = function getVersionString() {
var splited = _self.getVersion().split('.');
if(splited[0] === '2' && splited[1] === '2') return "Froyo";
else if(splited[0] === '2' && splited[1] !== '2') return "Gingerbread";
else if(splited[0] === '3') return "Honeycomb";
else if(splited[0] === '4' && splited[1] === '0') return "Ice Cream Sandwich";
else if(splited[0] === '4' && splited[1] !== '0') return "Jelly Bean";
else return splited[0]+"."+splited[1];
};
/** Get device's Model.
* @method
* @return {String} */
_self.getModel = function getModel() {
return Ti.Platform.getModel();
};
/** Get System's processor architecture.
* @method
* @return {String} */
_self.getArchitecture = function getArchitecture() {
return Ti.Platform.getArchitecture();
};
/** Get available memory
* @method
* @return {Number} an integer (Bytes) */
_self.getAvailableMemory = function getAvailableMemory() {
var mem = Ti.Platform.getAvailableMemory();
if (_self.isApple()) {
mem = mem * 1024; // Megabytes to bytes
}
return mem;
};
/** Get short name of the JavaScript runtime in use.
* @method
* @return {String} */
_self.getJsRuntime = function getJsRuntime() {
return Ti.Platform.getRuntime();
};
/** Get the manufacturer of the device.
* @method
* @return {String} */
_self.getManufacturer = function getManufacturer() {
return Ti.Platform.getManufacturer();
};
/** Get the number of processing cores.
* @method
* @return {Number} */
_self.getProcessorCount = function getProcessorCount() {
return Ti.Platform.getProcessorCount();
};
/** Get system name
* @method
* @return {String} */
_self.getUsername = function getUsername() {
return Ti.Platform.getUsername();
};
/** Get system's default language.
* @method
* @return {String} ISO639-1 or ISO3166-1Alpha2 */
_self.getLocale = function getLocale() {
return Ti.Platform.getLocale();
};
/** Get app ID.
* @method
* @return {String} Applications's globally-unique ID (UUID).
* On Android, this may be the UDID (unique device ID). For iOS,
* this is a unique identifier for this install of the application.*/
_self.getAppId = function getAppId() {
return Ti.Platform.getId();
};
/** Get Mac Adress.
* @method
* @return {String} Applications's globally-unique ID (UUID).
* On iOS, this value is the app's UUID. Apple does not allow
* access to any hardware identifier information as it can be
* used for unique device identification, which they have prohibited.*/
_self.getMacAddress = function getMacAddress() {
return Ti.Platform.getMacaddress();
};
return _self;
}());
module.exports = System;