A progress dialog or a horizontal progress bar in the title of the window.
A progress indicator can be used to show the progress of an operation in the UI to let the user know that some action is taking place. It is used to indicate an ongoing activity of determinate or indeterminate length.
Use the Titanium.UI.Android.createProgressIndicator method to create a progress indicator.
A progress indicator can be either a progress dialog or a horizontal progress bar in the title of the window. The progress dialog is a modal dialog that blocks the UI. See also: Titanium.UI.Android.PROGRESS_INDICATOR_DIALOG, Titanium.UI.Android.PROGRESS_INDICATOR_STATUS_BAR.
Calling show displays the indicator, and calling hide removes it.
To display a horizontal progress bar in the title of a heavyweight window, wait for the window to open before creating the progress bar. For example, in the sample code below, for it to work in the status bar, create the progress bar inside the event listener, which waits for the open event.
Click the button to show a progress indicator while some code executes and hide it on completion.
Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
backgroundColor: 'blue'
});
var button = Ti.UI.createButton({
title: 'Show Progress Dialog'
});
var progressIndicator = Ti.UI.Android.createProgressIndicator({
message: 'Loading...',
location: Ti.UI.Android.PROGRESS_INDICATOR_DIALOG,
type: Ti.UI.Android.PROGRESS_INDICATOR_DETERMINANT,
cancelable: true,
min: 0,
max: 10
});
button.addEventListener('click', function (e) {
progressIndicator.show();
var value = 0;
setInterval(function(){
if (value > 10) {
return;
}
progressIndicator.value = value;
value ++;
}, 200);
// do some work that takes 3 seconds
// ie. replace the following setTimeout block with your code
setTimeout(function(){
progressIndicator.hide();
}, 3000);
});
win.add(button);
win.open();
Previous example as an Alloy view-controller.
index.xml:
<Alloy>
<Window backgroundColor="blue">
<Button id="button" onClick="showIndicator">Show Progress Dialog</Button>
<ProgressIndicator ns="Ti.UI.Android" platform="android" id="progressIndicator"
message="Loading..." min="0" max="10" cancelable="true"
location="Ti.UI.Android.PROGRESS_INDICATOR_DIALOG"
type="Ti.UI.Android.PROGRESS_INDICATOR_DETERMINANT" />
</Window>
</Alloy>
index.js:
function showIndicator(e) {
$.progressIndicator.show();
var value = 0;
setInterval(function(){
if (value > 10) {
return;
}
$.progressIndicator.value = value;
value ++;
}, 200);
// do some work that takes 3 seconds
// ie. replace the following setTimeout block with your code
setTimeout(function(){
$.progressIndicator.hide();
}, 3000);
}
$.index.open();
Indicates if the proxy will bubble an event to its parent.
Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.
Default: true
When true allows the user to cancel the progress dialog by pressing the BACK button.
When true allows the user to cancel the progress dialog by pressing the BACK button.
Location for the progress indicator.
One of the constants: Titanium.UI.Android.PROGRESS_INDICATOR_DIALOG, Titanium.UI.Android.PROGRESS_INDICATOR_STATUS_BAR.
Default: Titanium.UI.Android.PROGRESS_INDICATOR_DIALOG
Key identifying a string in the locale file to use for the message text.
Key identifying a string in the locale file to use for the message text.
Only one of message or messageid should be specified.
Type for the progress indicator.
One of the constants: Titanium.UI.Android.PROGRESS_INDICATOR_INDETERMINANT, Titanium.UI.Android.PROGRESS_INDICATOR_DETERMINANT.
Default: Titanium.UI.Android.PROGRESS_INDICATOR_INDETERMINANT
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
Applies the properties to the proxy.
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.
A dictionary of properties to apply.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
Hides the progress indicator and stops the animation.
Removes the specified callback as an event listener for the named event.
Multiple listeners can be registered for the same event, so the
callback parameter is used to determine which listener to remove.
When adding a listener, you must save a reference to the callback function in order to remove the listener later:
var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);
To remove the listener, pass in a reference to the callback function:
window.removeEventListener('click', listener);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener.
Sets the value of the bubbleParent property.
New value for the property.
Sets the value of the cancelable property.
New value for the property.
Sets the value of the location property.
New value for the property.
Sets the value of the max property.
New value for the property.
Sets the value of the message property.
New value for the property.
Sets the value of the messageid property.
New value for the property.
Sets the value of the min property.
New value for the property.
Sets the value of the type property.
New value for the property.
Shows the progress indicator and starts the animation.
Fired when the user has canceled the progress indicator dialog.
The user triggers this event by pressing the BACK button when the dialog is visible. The dialog will be hidden and this event dispatched.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Source object that fired the event.
Name of the event fired.