Skip to content

Instantly share code, notes, and snippets.

@donayama
Forked from donayama/app.js
Created February 27, 2011 11:06
Show Gist options
  • Save donayama/846092 to your computer and use it in GitHub Desktop.
Save donayama/846092 to your computer and use it in GitHub Desktop.
// Test Runner - Online Code Debuging Framework for Titanium Mobile(iOS)
var tabGroup = Titanium.UI.createTabGroup();
tabGroup.addTab(Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Test Runner',
window: Titanium.UI.createWindow({
title:'Test Runner',
backgroundColor:'#fff',
url: 'testrunner.js'
})
}));
tabGroup.open();
var button = Ti.UI.createButton({title: 'hoge', top:150, width:100, height:50});
Ti.UI.currentWindow.add(button);
button.addEventListener('click', function(){
if(Titanium.Geolocation.hasCompass){
Titanium.Geolocation.addEventListener("heading", function(e){
if(e.error){
Titanium.API.error(e.error);
return;
}
button.title = e.heading.trueHeading;
});
}
else{
alert('not supported.');
}
});
var button = Ti.UI.createButton({title: 'hoge', top:150, width:100, height:50});
Ti.UI.currentWindow.add(button);
button.addEventListener('click', function(){
Ti.Media.showCamera({
success:function(e){
var f = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
f.write(e.media);
Titanium.UI.currentWindow.backgroundImage = f.nativePath;
}
});
});
{
"data":[
{"title":"buttons", "url":"buttons.js"},
{"title":"fork test", "url":"camera.js"}
]
}
var baseURL = 'https://gist.github.com/raw/846009/';
var tv = Ti.UI.createTableView();
tv.addEventListener('click', function(e){
if(e.rowData && e.rowData.url){
var xhr = Titanium.Network.createHTTPClient({
onload: function(){
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'test.js');
f.write(this.responseData);
var w = Ti.UI.createWindow({title: e.rowData.title, url:f.resolve()});
Ti.UI.currentTab.open(w);
}
});
xhr.open('GET', baseURL + e.rowData.url);
xhr.send();
}
});
Ti.UI.currentWindow.add(tv);
var loadJson = function(){
var xhr = Titanium.Network.createHTTPClient({
onload: function(){
var json = JSON.parse(xhr.responseText);
tv.data = json.data;
}
});
xhr.open('GET', baseURL + 'test.json');
xhr.send();
};
Ti.UI.currentWindow.rightNavButton = ((function(){
var b = Titanium.UI.createButton({systemButton: Titanium.UI.iPhone.SystemButton.REFRESH});
b.addEventListener('click', function(){
loadJson();
});
return b;
})());
loadJson();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment