Skip to content

Instantly share code, notes, and snippets.

@mcongrove
Created April 6, 2011 17:12
Show Gist options
  • Save mcongrove/906068 to your computer and use it in GitHub Desktop.
Save mcongrove/906068 to your computer and use it in GitHub Desktop.
A loading screen that can be shown and hidden from anywhere within an application
// Include TiLoad library
Ti.include("TiLoad.js");
// Initialize TiLoad (param specifics if window rotates with device)
TiLoad.init({ rotate: false });
// Create a quick test application
var window = Ti.UI.createWindow({
title: "Loading Screen",
layout: "vertical",
backgroundColor: "#FFF"
});
var tab = Ti.UI.createTab({
title: "Loading Screen",
window: window
});
var button = Ti.UI.createButton({
width: 280,
height: 44,
title: "Show Loading Screen",
top: 20,
left: 20
});
button.addEventListener("click", function(e) {
// Show the TiLoad screen
TiLoad.show();
});
window.add(button);
var tabGroup = Ti.UI.createTabGroup();
tabGroup.addTab(tab);
tabGroup.open();
var TiLoad = {
visible: false,
init: function(_properties) {
var options;
if(_properties && _properties.rotate) {
options = {
orientationModes: [
Titanium.UI.LANDSCAPE_LEFT,
Titanium.UI.LANDSCAPE_RIGHT,
Titanium.UI.PORTRAIT,
Titanium.UI.UPSIDE_PORTRAIT
]
};
} else {
options = {};
}
TiLoad.window = Ti.UI.createWindow(options);
TiLoad.view = Ti.UI.createView({
width: "100%",
height: "100%",
top: 0,
left: 0,
backgroundColor: "transparent"
});
TiLoad.background = Ti.UI.createView({
width: "100%",
height: "100%",
top: 0,
left: 0,
backgroundColor: "#000",
opacity: 0.8
});
TiLoad.spinner = Ti.UI.createActivityIndicator({
width: "100%",
height: "100%",
top: 0,
left: 0
});
if(Ti.Platform.osname == "iphone") {
TiLoad.spinner.style = Titanium.UI.iPhone.ActivityIndicatorStyle.BIG;
}
TiLoad.view.addEventListener("click", TiLoad.hide, false);
TiLoad.background.addEventListener("click", TiLoad.hide, false);
TiLoad.spinner.addEventListener("click", TiLoad.hide, false);
Ti.Gesture.addEventListener("orientationchange", TiLoad.size, false);
TiLoad.spinner.show();
TiLoad.view.add(TiLoad.background);
TiLoad.view.add(TiLoad.spinner);
TiLoad.window.add(TiLoad.view);
},
show: function() {
TiLoad.size();
if(!TiLoad.visible) {
TiLoad.window.open();
}
TiLoad.visible = true;
},
hide: function() {
if(TiLoad.visible) {
TiLoad.window.close();
}
TiLoad.visible = false;
},
size: function(_event) {
TiLoad.window.width = Titanium.Platform.displayCaps.platformWidth;
TiLoad.window.height = Titanium.Platform.displayCaps.platformHeight;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment