-
Notifications
You must be signed in to change notification settings - Fork 1
/
API.UI.js
208 lines (185 loc) · 6.8 KB
/
API.UI.js
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* 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 UI = function (APIReferences) {
var Yaast = {
"API" : APIReferences
};
var viewsById = {};
var nextZindex = 100;
/** It provides several useful methods to get or create User Interface.
* @alias API.UI
* @namespace */
var _self = {};
/** Get Screen Type of Android Device
* @method
* @return {String} */
_self.getScreenDensity = function getScreenDensity() {
return Ti.Platform.displayCaps.getDensity();
};
_self.DEFAULT_FONT_SIZE = 20;
/** Set Font Size Constanst.
* @method
* @return {Number} */
_self.setFontSizes = function setFontSizes() {
if (Yaast.API.HW.System.isRetina()) {
//return 34;
_self.DEFAULT_FONT_SIZE = 34;
} else if(Yaast.API.HW.System.isApple()) {
//return 17;
_self.DEFAULT_FONT_SIZE = 17;
} else {
//return Ti.Platform.displayCaps.logicalDensityFactor * 20;
_self.DEFAULT_FONT_SIZE = Ti.Platform.displayCaps.logicalDensityFactor * 20;
}
};
_self.setFontSizes();
/** Get default font Size.
* @method
* @return {Number} */
_self.getDefaultFontSize = function getDefaultFontSize() {
return _self.DEFAULT_FONT_SIZE;
};
/** Get constant Row Height on Android or iOS Table.
* @method
* @return {Number} */
_self.getDefaultRowHeight = function getDefaultRowHeight() {
if (Yaast.API.HW.System.isRetina()) {
return 88;
} else if(Yaast.API.HW.System.isApple()) {
return 44;
} else {
return Ti.Platform.displayCaps.logicalDensityFactor * 44;
/*var density = _self.getScreenDensity();
if(density === 'low') return 33;
else if(density === 'medium') return 44;
else if(density === 'high') return 72;
else if(density === 'xhigh') return 96;
else if(density === 'xxhigh') return 144;
else if(density === 'xxxhigh') return 192;*/
}
};
/** Get constant Size Button (Square - width = height) on Android or iOS.
* @method
* @return {Number} */
_self.getDefaultSizeButton = function getDefaultSizeButton() {
if(Yaast.API.HW.System.isRetina()) {
return 60;
} else if(Yaast.API.HW.System.isApple()) {
return 30;
} else {
var density = _self.getScreenDensity();
if(density === 'low') return 33;
else if(density === 'medium') return 30;
else if(density === 'high') return 45;
else if(density === 'xhigh') return 60;
else if(density === 'xxhigh') return 90;
else if(density === 'xxxhigh') return 120;
}
};
/** Get constant Padding Button (Square - top = bottom) on Android or iOS.
* @method
* @return {Number} */
_self.getDefaultPaddingButton = function getDefaultPaddingButton() {
if(Yaast.API.HW.System.isRetina()) {
return 14;
} else if(Yaast.API.HW.System.isApple()) {
return 7;
} else {
var density = _self.getScreenDensity();
if(density === 'low') return 33;
else if(density === 'medium') return 7;
else if(density === 'high') return 10.5;
else if(density === 'xhigh') return 14;
else if(density === 'xxhigh') return 21;
else if(density === 'xxxhigh') return 28;
}
};
/** Get Padding Top of Application Window.
* @method
* @return {Number} */
_self.getDefaultStatusBar = function getDefaultStatusBar() {
var vers = parseFloat(Yaast.API.HW.System.getVersion(), 10);
var appleBool = Yaast.API.HW.System.isApple();
if(appleBool && vers < 7.0) return 0;
if(appleBool && vers >= 7.0) {
if(Yaast.API.HW.System.isRetina()) return 40;
else return 20;
}
else return 12;
};
/** Get Display Platform Width.
* @method
* @return {Number} */
_self.getPlatformWidth = function getPlatformWidth() {
return Ti.Platform.displayCaps.getPlatformWidth();
};
/** Get Display Platform Height.
* @method
* @return {Number} */
_self.getPlatformHeight = function getPlatformHeight() {
return Ti.Platform.displayCaps.getPlatformHeight();
};
/** Add new view into parentView
* @param options {'wView': theUpGraphView, 'type': 'widget', 'isNative': false, 'id':99}
* @return {Boolean} */
_self.addView = function addView(parentView, options) {
options.wView.zIndex = nextZindex;
parentView.add(options.wView);
var bound = {
'top': null,
'left': null,
'width': null,
'height': null,
'zindex': nextZindex
};
viewsById[options.id] = {'view': options.wView, 'defaultBound': bound, 'parentView': parentView};
Ti.API.info('[UI.addView]viewsById.defaultBound: ' + JSON.stringify(viewsById[options.id].defaultBound));
nextZindex ++;
return true;
};
/** Remove view from parentView
* @method
* @return {Boolean} */
_self.removeView = function removeView(id) {
viewsById[id].parentView.remove(viewsById[id].view);
delete viewsById[id];
return true;
};
/** Set the View asociated with viewId to fullScreen
* @method
* @return {Boolean} */
_self.setViewFullScreen = function setViewFullScreen(viewId) {
Ti.API.info('[UI.setViewFullScreen]viewId: ' + JSON.stringify(viewId));
viewsById[viewId].defaultBound.top = viewsById[viewId].view.rect.y;
viewsById[viewId].defaultBound.left = viewsById[viewId].view.rect.x;
viewsById[viewId].defaultBound.width = viewsById[viewId].view.rect.width;
viewsById[viewId].defaultBound.height = viewsById[viewId].view.rect.height;
Ti.API.info('[UI.setViewFullScreen]viewsById[viewId].view.rect: ' + JSON.stringify(viewsById[viewId].view.rect));
Ti.API.info('[UI.setViewFullScreen]viewsById[viewId].defaultBound: ' + JSON.stringify(viewsById[viewId].defaultBound));
viewsById[viewId].view.top = 0;
viewsById[viewId].view.left = 0;
viewsById[viewId].view.width = "100%";
viewsById[viewId].view.height = "100%";
viewsById[viewId].view.zIndex = 10000;
return true;
};
/** Restore the View asociated with viewId size
* @method
* @return {Boolean} */
_self.restoreViewSize = function restoreViewSize(viewId) {
Ti.API.info('[UI.restoreViewSize]theView: ' + JSON.stringify(viewId));
viewsById[viewId].view.top = viewsById[viewId].defaultBound.top;
viewsById[viewId].view.left = viewsById[viewId].defaultBound.left;
viewsById[viewId].view.width = viewsById[viewId].defaultBound.width;
viewsById[viewId].view.height = viewsById[viewId].defaultBound.height;
viewsById[viewId].view.zIndex = viewsById[viewId].defaultBound.zindex;
return true;
};
return _self;
};
module.exports = UI;