· 8 years ago · May 29, 2018, 06:44 AM
1
2var controlsAffectectedByOrientation = new Array();
3
4Ti.Gesture.addEventListener('orientationchange',function(e){
5
6 for ( var i = 0; i < controlsAffectectedByOrientation.length; i++) {
7 var thisControl = controlsAffectectedByOrientation[i];
8 var width = thisControl.pWidth;
9 thisControl.width = percentageToPixels('width',width);
10 }
11
12});
13
14db.execute('CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, todo TEXT)');
15
16// Workaround for problems using percentage widths and heights up to and including Ti 1.2.1
17// @TODO Test suite - test for function being used without setting type argument
18function percentageToPixels(type,percent,margins,length) {
19 if ( !(type == 'width') && !(type == 'height') )
20 {
21 var a = Ti.UI.createAlertDialog({
22 title: 'Error',
23 message: 'type argument (width/height) not set',
24 buttonNames:['OK']
25 });
26 a.show();
27 }
28
29 if (margins == null) {
30 margins = 0;
31 }
32 if (length == null) {
33 if(type == 'height') {
34 length = Ti.Platform.displayCaps.platformHeight-(margins*2);
35 } else {
36 length = Ti.Platform.displayCaps.platformWidth-(margins*2);
37 }
38 }
39
40 return new Number((length * (percent/100))).toFixed(0);
41}
42
43//create data entry view
44var entryView = Ti.UI.createView({
45 height:'auto',
46 width:percentageToPixels('width',100),
47 pWidth: 100
48});
49
50controlsAffectectedByOrientation.push(entryView);