显示钛的活动指标

shy*_*yam 1 titanium-mobile

我在android中使用进度条,但是在钛中它的活动指示器用于显示某些进展在android的背景上我通过制作异步任务但是在钛我应该编写用于处理背景任务的代码,意味着直到我的后台任务没有完成daisply指示器并在完成后自动隐藏...我的代码为activty indiator和我想在后台显示它的任务在下面..

     var ind = Titanium.UI.createActivityIndicator({
            location:Titanium.UI.ActivityIndicator.DIALOG,
            //type:Titanium.UI.ActivityIndicator.DETERMINANT,

           width:50,
height:50,
message: 'loading...',
color: 'FF0000'
    });
         curWin.add(ind);
         ind.show();



 and want to put below code which will be run on back ground.....





     var image = imgvwPlus.image; 
    var filename = new Date().getTime() + "-ea.jpg";
    bgImage =      Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,filename);
    // Write the image to the new file (image created from camera)
    bgImage.write(image);
    imageArray.length = imageArray.length + 1;
            //alert(bgImage);
     custom[j]={"hanger":btntext[0].title,
        "color": btntext[1].title,
        "size":  btntext[2].title,
        "text": btntext[3].title,

        "textStyle": btntext[3].font.fontFamily,
        "textSize": btntext[3].font.fontSize,
        "textColor": btntext[3].color,

        "textTop":textTop,
        "textLeft":textLeft,
        "quantity":quantity, 
        "price":price
    };
    imageArray[i]={"img_path":bgImage,
        "imgPrice":imgPrice,
        "customization":custom
    };
      index = i;
      i++;
      imgvwPlus.image = 'images/Plus.jpg';
      btntext[0].title = 'Select';
      btntext[1].title = 'Select';
      btntext[2].title= 'Select';
      btntext[3].title = 'Select';
      btntext[3].font.fontFamily="Helvetica Neue";
      btntext[3].font.fontSize="15";
      btntext[3].color="#000";
      var win = Ti.UI.createWindow({
      title:'Popmount',
      //url:'popmount.js',
      param:imageArray,
      index:index,

    });
    //alert("image path"+win.param[0].img_path);
    Ti.UI.currentTab.open(win);
Run Code Online (Sandbox Code Playgroud)

Sag*_* B. 18

这是更新的代码,它将与Alloy Frame工作一起使用,并在iOS和Android中都受支持.

indicator.xml

<Alloy>
    <Window class="container" >
        <View id='indicatorBack'/>
        <ActivityIndicator id='activityInd'/>
    </Window>
</Alloy>
Run Code Online (Sandbox Code Playgroud)

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 
}
Run Code Online (Sandbox Code Playgroud)

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();
Run Code Online (Sandbox Code Playgroud)

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");
        }

    };
Run Code Online (Sandbox Code Playgroud)

因此,您可以使用以下功能从任何控制器显示和隐藏它:

Alloy.Globals.showIndicator();

Alloy.Globals.hideIndicator();
Run Code Online (Sandbox Code Playgroud)

此外,对于自定义消息,您可以在指标控制器中传递参数.