Skip to content

Instantly share code, notes, and snippets.

@dasher
Created June 21, 2010 16:23
Show Gist options
  • Save dasher/447092 to your computer and use it in GitHub Desktop.
Save dasher/447092 to your computer and use it in GitHub Desktop.
var controlsAffectectedByOrientation = new Array();
Ti.Gesture.addEventListener('orientationchange',function(e){
for ( var i = 0; i < controlsAffectectedByOrientation.length; i++) {
var thisControl = controlsAffectectedByOrientation[i];
var width = thisControl.pWidth;
thisControl.width = percentageToPixels('width',width);
}
});
db.execute('CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, todo TEXT)');
// Workaround for problems using percentage widths and heights up to and including Ti 1.2.1
// @TODO Test suite - test for function being used without setting type argument
function percentageToPixels(type,percent,margins,length) {
if ( !(type == 'width') && !(type == 'height') )
{
var a = Ti.UI.createAlertDialog({
title: 'Error',
message: 'type argument (width/height) not set',
buttonNames:['OK']
});
a.show();
}
if (margins == null) {
margins = 0;
}
if (length == null) {
if(type == 'height') {
length = Ti.Platform.displayCaps.platformHeight-(margins*2);
} else {
length = Ti.Platform.displayCaps.platformWidth-(margins*2);
}
}
return new Number((length * (percent/100))).toFixed(0);
}
//create data entry view
var entryView = Ti.UI.createView({
height:'auto',
width:percentageToPixels('width',100),
pWidth: 100
});
controlsAffectectedByOrientation.push(entryView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment