2011-11-24 40 views
1

我在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); 
+0

沒有什麼特別的這一點。你必須自己顯示/隱藏指示器。 –

+0

在哪裏隱藏它?在哪塊我使用ind.hide();因爲當我在開始bckground任務之前編寫ind.show()並隱藏在結尾處時,這個我的指示器看起來像掛起... – shyam

+0

您需要在bg任務結束時隱藏它。但是,你的bg任務實際上做了什麼,它顯示任何視圖或什麼? –

回答

18

這裏是更新後的代碼,它將與合金框架一起工作,並在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(); 

而且你可以在指示器控制器傳遞參數的自定義消息。

1

在窗口中使用onOpen來顯示指標。

風格

"#activityIndicator": { 
    color: 'white', 
    font: Alloy.Globals.fontLargeBold, 
    message: 'Loading', 
    style: Titanium.UI.iPhone.ActivityIndicatorStyle.BIG 
} 

視圖

<Alloy> 
    <Window onOpen="showIndicator" fullscreen="true" backgroundColor="yellow"> 
     <ActivityIndicator id="activityIndicator"/> 
    </Window> 
</Alloy> 

控制器

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