Вот обновленный код, который будет работать с Alloy Frame и поддерживаться в iOS и Android.
indicator.xml
<Alloy>
<Window class="container" >
<View id='indicatorBack'/>
<ActivityIndicator id='activityInd'/>
</Window>
</Alloy>
indicator.tss
".container" : {
backgroundColor : 'transparent',
zIndex : 5000
},
"#indicatorBack[formFactor=handheld]" :{
opacity : 0.8,
height : '50dp',
width : '150dp',
borderRadius : 10,
backgroundColor : 'black'
},
"#indicatorBack[formFactor=tablet]" :{
opacity :0.8,
height : '70dp',
width : '170dp',
borderRadius : 10,
backgroundColor : 'black'
},
"#activityInd":{
color : 'white',
font : Alloy.Globals.fontLargeBold,
message : ' Loading...',
zIndex : 10,
opacity : 1
}
indicator.js
if (Ti.Platform.osname === 'ipad')
$.activityInd.style = Titanium.UI.iPhone.ActivityIndicatorStyle.BIG;
$.indicator.showIndicator = function() {
try {
$.indicator.open();
$.activityInd.show();
} catch(e) {
Ti.API.info("Exception in opening indicator");
}
};
// Function to hide Indicator
$.indicator.hideIndicator = function() {
try {
$.activityInd.hide();
$.indicator.close();
} catch(e) {
Ti.API.info("Exception in hiding indicator");
}
};
$.activityInd.show();
Alloy.js
//Activity Indicator.
var indWin = null;
Alloy.Globals.showIndicator = function() {
try {
if (indWin == null)
indWin = Alloy.createController('indicator').getView();
indWin.showIndicator();
} catch(e) {
Ti.API.info("Exception in opening indicator");
}
};
// Function to hide Indicator
Alloy.Globals.hideIndicator = function() {
try {
if (indWin != null) {
indWin.hideIndicator();
indWin = null;
}
} catch(e) {
Ti.API.info("Exception in hiding indicator");
}
};
Таким образом, вы можете показать и скрыть его от любого контроллера, используя следующие функции:
Alloy.Globals.showIndicator();
Alloy.Globals.hideIndicator();
Также для пользовательских сообщений вы можете передавать аргумент в контроллере индикатора.