Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to check if a window exists and is visible

I used the Kitchen Sink example to show an activity indicator. But if the user clicks another tab, I would like to check if indWin exists, and if it is, call hideIndicator(). But not sure how to do it. If I just call hideIndicator and indWin doesnt exist, I get a warning.

Here's the code I'm using. Any help is appreciated:

var indWin = null;
var actInd = null;
function showIndicator()
{
    // window container
    indWin = Titanium.UI.createWindow({
        height:150,
        width:150
    });

    // black view
    var indView = Titanium.UI.createView({
        height:150,
        width:150,
        backgroundColor:'#000',
        borderRadius:10,
        opacity:0.8
    });
    indWin.add(indView);

    // loading indicator
    actInd = Titanium.UI.createActivityIndicator({
        style:Titanium.UI.iPhone.ActivityIndicatorStyle.BIG,
        height:30,
        width:30
    });
    indWin.add(actInd);

    // message
    var message = Titanium.UI.createLabel({
        text:'Loading',
        color:'#fff',
        width:'auto',
        height:'auto',
        font:{fontSize:20,fontWeight:'bold'},
        bottom:20
    });
    indWin.add(message);
    indWin.open();
    actInd.show();

};

function hideIndicator()
{
        actInd.hide();
        indWin.close({opacity:0,duration:500});
};

//
// Add global event handlers to hide/show custom indicator
//
Titanium.App.addEventListener('show_indicator', function(e)
{
    //Ti.API.info("IN SHOW INDICATOR");
    showIndicator();
});
Titanium.App.addEventListener('hide_indicator', function(e)
{
    //Ti.API.info("IN HIDE INDICATOR");
    hideIndicator();
});
— asked September 24th 2010 by Dave F
  • hide
  • indicator
  • window
0 Comments

2 Answers

  • I may have an answer from some tom-foolery based needs between iOS and Droid.

    The premise is that I need to know if a Window is established and if so, nuke it (or do whatever you'd like, really).

    Give this a whirl to check the existence of a Window in iOS or Droid:

    
        if ( typeof win1 == 'undefined' ) {    // Where win1 = Window Object
            alert('win1 does NOT exist');
            // Do nothing or do something here
        } else {
            // win1 is not undefined, so let's nuke it
            win1.close();
            // ... or do what you would like here
        }
    

    HTH

    //Jesse

    — answered August 16th 2011 by Jesse Benedict
    permalink
    0 Comments
  • Just create a boolean variable which is set to true when the window is opened and set to false when it is closed.

    — answered September 25th 2010 by James K
    permalink
    1 Comment
    • Hey. Thanks for this tip. Sorry for the delayed response. I thought I tried that but I'll try again tonight.

      I think the issue I'm having is that the indicator window is created in app.js and is called from other files in my app. Maybe they were out of scope or something. Hmmm.. Anyway. Appreciate it. I'll post back when I have a second to try it.

      — commented September 26th 2010 by Dave F
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.