# Titanium.UI.ActivityIndicator
An activity indicator that lets the user know an action is taking place.
# Overview
Android | iOS |
---|---|
An activity 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. An activity indicator consists of a spinning animation and an optional text message, and is used to indicate an ongoing activity of indeterminate length. To show progress, use Titanium.UI.ProgressBar instead.
Use the Titanium.UI.createActivityIndicator method or <ActivityIndicator>
Alloy element to
create an ActivityIndicator
object.
ActivityIndicator
is a view and, like any view, must be added to a window or other top-level
view before it can be shown. Unlike most views, ActivityIndicator
is hidden by
default and must be shown explicitly by calling its Titanium.UI.ActivityIndicator.show method.
# Examples
# Simple Activity Indicator
Open a yellow window immediately after a blue window. Show an activity indicator while some code executes and hide it on completion. Then close the yellow window.
Ti.UI.backgroundColor = 'white';
var win1 = Ti.UI.createWindow({
backgroundColor: 'blue'
});
var win2 = Ti.UI.createWindow({
backgroundColor: 'yellow'
});
var activityIndicator = Ti.UI.createActivityIndicator({
color: 'green',
message: 'Loading ...',
style: Ti.UI.ActivityIndicatorStyle.DARK,
top: 10,
left: 10,
height: Ti.UI.SIZE,
width: Ti.UI.SIZE
});
// The activity indicator must be added to a window or view for it to appear
win2.add(activityIndicator);
// eventListeners must always be loaded before the event is likely to fire
// hence, the open() method must be positioned before the window is opened
win2.addEventListener('open', function (e) {
activityIndicator.show();
// do some work that takes 6 seconds
// ie. replace the following setTimeout block with your code
setTimeout(function() {
e.source.close();
activityIndicator.hide();
}, 6000);
});
win1.open();
win2.open();
# Alloy XML Markup
Previous example as two Alloy views.
win1.xml:
<Alloy>
<Window onOpen="openWin2" backgroundColor="blue" />
</Alloy>
win1.js:
function openWin2 () {
var win2 = Alloy.createController('win2').getView();
win2.open();
}
win2.xml:
<Alloy>
<Window onOpen="showIndicator" backgroundColor="yellow">
<!-- Define the styling properties in the TSS file -->
<ActivityIndicator id="activityIndicator" message="Loading..."/>
</Window>
</Alloy>
win2.js:
function showIndicator(e) {
$.activityIndicator.show();
// do some work that takes 6 seconds
// ie. replace the following setTimeout block with your code
setTimeout(function() {
e.source.close();
$.activityIndicator.hide();
}, 6000);
}
# Properties
# accessibilityDisableLongPress CREATION ONLY
Boolean value to remove the long press notification for the device's accessibility service.
Will disable the "double tap and hold for long press" message when selecting an item.
Default: true
# apiName READONLY
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Titanium.UI.Button
returns Ti.UI.Button
.
# bottom
Bottom position of the view.
Determines the absolute position of the view relative to its parent.
Can be either a float value or a dimension string (for example 100
or '50%'
.)
# bubbleParent
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
# color
Color of the message text, as a color name or hex triplet.
For information about color values, see the "Colors" section of Titanium.UI.
# elevation
Base elevation of the view relative to its parent in pixels.
The elevation of a view determines the appearance of its shadow. Higher elevations produce larger and softer shadows.
Note: The elevation
property only works on Titanium.UI.View
objects.
Many Android components have a default elevation that cannot be modified.
For more information, see
Google design guidelines: Elevation and shadows.
# filterTouchesWhenObscured
Discards touch related events if another app's system overlay covers the view.
This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.
Setting this property to true
causes touch related events (including "click") to not be fired
if a system overlay overlaps the view.
Default: false
# height
Width of the view. Only accepts value of SIZE, which must be explicitly set in order to display the message and to position the view correctly.
Defaults to: If undefined, defaults to either FILL or SIZE depending on the view. See "View Types and Default Layout Behavior" in Transitioning to the New UI Layout System.
Can be either a float value or a dimension string (for example, '50%' or '40dp'). Can also be one of the following special values:
- SIZE. The view should size itself to fit its contents.
- FILL. The view should size itself to fill its parent.
- 'auto'. Represents the default sizing behavior for a given type of
view. The use of 'auto' is deprecated, and should be replaced with the
SIZE
orFILL
constants if it is necessary to set the view's behavior explicitly.
This is an input property for specifying the view's height dimension. To determine the view's size once rendered, use the rect or size properties.
Sets the behavior when hiding an object to release or keep the free space
If setting hiddenBehavior
to HIDDEN_BEHAVIOR_GONE it will automatically release the space the view occupied.
For example: in a vertical layout the views below the object will move up when you hide
an object with hiddenBehavior:Titanium.UI.HIDDEN_BEHAVIOR_GONE
.
- HIDDEN_BEHAVIOR_INVISIBLE. Keeps the space and just hides the object (default).
- HIDDEN_BEHAVIOR_GONE. Releases the space and hides the object.
Defaults to Titanium.UI.HIDDEN_BEHAVIOR_INVISIBLE.
# horizontalMotionEffect
Adds a horizontal parallax effect to the view
Note that the parallax effect only happens by tilting the device so results can not be seen on Simulator. To clear all motion effects, use the <Titanium.UI.clearMotionEffects> method.
# id
View's identifier.
The id
property of the Ti.UI.View represents the view's identifier. The identifier string does
not have to be unique. You can use this property with getViewById method.
# indicatorColor
Color of the animated indicator.
For information about color values, see the "Colors" section of Titanium.UI.
Default: white
# left
Left position of the view.
Determines the absolute position of the view relative to its parent.
Can be either a float value or a dimension string (for example 100
or '50%'
.)
# lifecycleContainer
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.
# messageid
Key identifying a string in the locale file to use for the message text.
Only one of message
or messageid
should be specified.
# previewContext
The preview context used in the 3D-Touch feature "Peek and Pop".
Preview context to present the "Peek and Pop" of a view. Use an configured instance of Titanium.UI.iOS.PreviewContext here.
Note: This property can only be used on devices running iOS9 or later and supporting 3D-Touch. It is ignored on older devices and can manually be checked using forceTouchSupported.
# right
Right position of the view.
Determines the absolute position of the view relative to its parent.
Can be either a float value or a dimension string (for example 100
or '50%'
.)
# rotation
Clockwise 2D rotation of the view in degrees.
Translation values are applied to the static post layout value.
# rotationX
Clockwise rotation of the view in degrees (x-axis).
Translation values are applied to the static post layout value.
# rotationY
Clockwise rotation of the view in degrees (y-axis).
Translation values are applied to the static post layout value.
# scaleX
Scaling of the view in x-axis in pixels.
Translation values are applied to the static post layout value.
# scaleY
Scaling of the view in y-axis in pixels.
Translation values are applied to the static post layout value.
# style
The style for the activity indicator.
One of the activity indicator style constants.
See also: indicatorColor
Default: Titanium.UI.ActivityIndicatorStyle.PLAIN
# tooltip
The default text to display in the control's tooltip.
Assigning a value to this property causes the tool tip to be displayed for the view.
Setting the property to null
cancels the display of the tool tip for the view.
Note: This property is only used for apps targeting macOS Catalyst.
# top
Top position of the view.
Determines the absolute position of the view relative to its parent.
Can be either a float value or a dimension string (for example 100
or'50%'
.)
# touchFeedback
A material design visual construct that provides an instantaneous visual confirmation of touch point.
Touch feedback is only applied to a view's background. It is never applied to the view's foreground content such as a Titanium.UI.ImageView's image.
For Titanium versions older than 9.1.0, touch feedback only works if you set the backgroundColor property to a non-transparent color.
Default: false
# touchFeedbackColor
Optional touch feedback ripple color. This has no effect unless touchFeedback
is true.
Defaults to provided theme color.
# transitionName
A name to identify this view in activity transition.
Name should be unique in the View hierarchy.
# translationX
Horizontal location of the view relative to its left position in pixels.
Translation values are applied to the static post layout value.
# translationY
Vertical location of the view relative to its top position in pixels.
Translation values are applied to the static post layout value.
# translationZ
Depth of the view relative to its elevation in pixels.
Translation values are applied to the static post layout value.
# verticalMotionEffect
Adds a vertical parallax effect to the view
Note that the parallax effect only happens by tilting the device so results can not be seen on Simulator. To clear all motion effects, use the <Titanium.UI.clearMotionEffects> method.
# width
Width of the view. Only accepts value of SIZE, which must be explicitly set in order to display the message and to position the view correctly.
Defaults to: If undefined, defaults to either FILL or SIZE depending on the view. See "View Types and Default Layout Behavior" in Transitioning to the New UI Layout System.
Can be either a float value or a dimension string (for example, '50%' or '40dp'). Can also be one of the following special values:
- SIZE. The view should size itself to fit its contents.
- FILL. The view should size itself to fill its parent.
- 'auto'. Represents the default sizing behavior for a given type of
view. The use of 'auto' is deprecated, and should be replaced with the
SIZE
orFILL
constants if it is necessary to set the view's behavior explicitly.
This is an input property for specifying the view's width dimension. To determine the view's size once rendered, use the rect or size properties.
# Methods
# addEventListener
Adds the specified callback as an event listener for the named event.
Parameters
Name | Type | Description |
---|---|---|
name | String | Name of the event. |
callback | Callback<Titanium.Event> | Callback function to invoke when the event is fired. |
Returns
- Type
- void
# applyProperties
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.
Parameters
Name | Type | Description |
---|---|---|
props | Dictionary | A dictionary of properties to apply. |
Returns
- Type
- void
# clearMotionEffects
Removes all previously added motion effects.
Use this method together with <Titanium.UI.horizontalMotionEffect> and <Titanium.UI.verticalMotionEffect>.
Returns
- Type
- void
# fireEvent
Fires a synthesized event to any registered listeners.
Parameters
Name | Type | Description |
---|---|---|
name | String | Name of the event. |
event | Dictionary | A dictionary of keys and values to add to the Titanium.Event object sent to the listeners. |
Returns
- Type
- void
# getViewById
Returns the matching view of a given view ID.
Parameters
Name | Type | Description |
---|---|---|
id | String | The ID of the view that should be returned. Use the |
Returns
- Type
- Titanium.UI.View
# hide
Hides the activity indicator and stops the animation.
Parameters
Name | Type | Description |
---|---|---|
options | AnimatedOptions | Animation options for Android only. Since SDK 5.1.0 and used only on Android 5.0+ Determines whether to enable a circular reveal animation.
Note that the default here is equivalent to passing in |
Returns
- Type
- void
# insertAt
Inserts a view at the specified position in the children array.
Useful if the layout
property is set to horizontal
or vertical
.
Parameters
Name | Type | Description |
---|---|---|
params | ViewPositionOptions | Pass an object that specifies the view to insert and optionally at which position (defaults to end) |
Returns
- Type
- void
# removeEventListener
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);
Parameters
Name | Type | Description |
---|---|---|
name | String | Name of the event. |
callback | Callback<Titanium.Event> | Callback function to remove. Must be the same function passed to |
Returns
- Type
- void
# show
Shows the activity indicator and starts the animation.
Remember to add the activity indicator to a parent view first, so it centers properly. This is optional for Android and required for iOS.
Parameters
Name | Type | Description |
---|---|---|
options | AnimatedOptions | Animation options for Android only. Since SDK 5.1.0 and only used on Android 5.0+ Determines whether to enable a circular reveal animation.
Note that the default here is equivalent to passing in |
Returns
- Type
- void
# stopAnimation
Stops a running animation.
Stops a running view Titanium.UI.Animation.
Returns
- Type
- void