Skip to content

Instantly share code, notes, and snippets.

@jonalter
Last active December 30, 2015 09:19
Show Gist options
  • Save jonalter/7808649 to your computer and use it in GitHub Desktop.
Save jonalter/7808649 to your computer and use it in GitHub Desktop.
Basic Titanium Testing app w/ in app log
////////////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////////////
function isIOS7Plus() {
if (Titanium.Platform.name == 'iPhone OS')
{
var version = Titanium.Platform.version.split(".");
var major = parseInt(version[0],10);
if (major >= 7)
{
return true;
}
}
return false;
}
var osname = Ti.Platform.osname,
ANDROID = (osname === 'android'),
IOS = (osname === 'iphone' || osname === 'ipad'),
IOS7PLUS = isIOS7Plus(),
defaultFontSize = ANDROID ? '16dp' : 14;
////////////////////////////////////////////////////////
// Tests as Table View Rows
////////////////////////////////////////////////////////
var rows = [
{
title: 'Test 1',
onClick: function(){
logInApp('Test 1');
}
},
{
title: 'Test 2',
onClick: function(){
logInApp('Test 2');
}
}
];
////////////////////////////////////////////////////////
// UI
////////////////////////////////////////////////////////
var win = Ti.UI.createWindow({
backgroundColor: 'white'
});
win.open();
var textLog = Ti.UI.createTextArea({
top: IOS7PLUS ? 20 : 0,
height: '40%',
width: '100%',
borderWidth: '2',
borderColor: '#000',
color: '#000',
backgroundColor: '#FFF',
focusable: false,
font: {
fontSize: defaultFontSize
},
value: 'AppLog: this log scrolls backwards (newest === top)'
});
win.add(textLog);
if (ANDROID) {
for (var i = 0, j = rows.length; i < j; i++) {
rows[i].font = {fontSize: defaultFontSize};
rows[i].height = '50dp';
rows[i].color = '#000';
}
}
var tableView = Ti.UI.createTableView({
top: '40%',
data: rows
});
tableView.addEventListener('click', function(e){
rows[e.index].onClick && rows[e.index].onClick();
});
win.add(tableView);
// Util - Logs in app and console
function logInApp(text) {
textLog.value = text + '\n' + textLog.value;
Ti.API.info(text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment