CF.setJoin with a callback function

128 views
Skip to first unread message

Clayton Vicente

unread,
Mar 14, 2013, 7:35:55 AM3/14/13
to comman...@googlegroups.com
There is a way to use CF.setJoin with a callback function ? something like this:
   self.hideListWindow = function(){
      CF.setJoin("d"+self.joinSubXBMC+2,0,function(){
         CF.log("callback function");
      })
   }
I need to be sure that the subpage its hidden, before use setProperties.
Thanks

Jarrod Bell

unread,
Mar 14, 2013, 10:04:38 AM3/14/13
to comman...@googlegroups.com
No, but you can do a tiny setTimeout, and use the setTimeout function to perform your code that must be delayed:

CF.setJoin("d"+self.joinSubXBMC+2,0);
setTimeout(function() {
    // perform your CF.setProperties in here
}, 50);

The actual delay time could be shorter, so test with your setup if you need to perform it faster than 50ms.

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

JohanJ

unread,
Mar 14, 2013, 10:25:23 AM3/14/13
to comman...@googlegroups.com, jar...@commandfusion.com
I would say that a callback feature would be a most welcome thing to add to upcoming releases. I have missed this quite a few times. Timers should be seen as a workaround. Subpages e.g. display them-self much slower the first time they are read from memory, I assume that the delay time also could be dependent on a lot of things like platform and OS. 

Clayton Vicente

unread,
Mar 14, 2013, 1:34:16 PM3/14/13
to comman...@googlegroups.com
I agree with Jorran, will be nice have a callback with CF.setJoin. I am already using setTimeout, but sometimes dont work.
Use CF.setProperties some times its not a easy thing. Every time that i make a setProperties i test using the debug, but the animation with the debug on its one thing and with the debug off its another thing.
See this simple function to set the properties of a list, when the subpage hide (without the setTimeout for now, just for example):
   self.hideListWindow = function(){
      var listShow= "l"+self.joinSubXBMC+4; 
      CF.setJoin("d"+self.joinSubXBMC+2,0);
      CF.setProperties([{join:listShow,h:1,opacity:0}]);
   }
This will make the list has the opacity 0 and a small size (1).
Now see the CF.setProperties to show the list (i have several lists, this function take care of all, i am only showing the CF.setProperties)
      CF.setProperties([{join:imageShow,x:imageX,y:imageY}],0.0,0.5,CF.AnimationCurveEaseInOut,function(){
            CF.setProperties([{join:listShow,x:listX,y:listY}],0.0,0.1,CF.AnimationCurveEaseInOut,function(){
               CF.setProperties([{join:listShow,h:listH,opacity:1.0}],0.0,0.5,CF.AnimationCurveEaseInOut)
            });
       })
This will set the image background to be placed before display the list, its only one image background for the lists, the position of the image depend of the position of the button that call the function. After the image is in the right place, the list will be displayed.
Now, if the image its not in the right place, this function works fine with the debug on or off. The image will move for the right place and then the list will be displayed. But if the image its already in the right place (called with the same button) and the debug its off i cant see the animation of the list. When the subpage display, the list is almost in the right place.
If the debug is on i can see the list animation, when the subpage show, i see the image in the right place, then i see the animation of the list.
Its hard to explain. In resume, if the debug is on, everything works fine. If the debug is off and we have items that already have the same properties that we want to set, the animation of the items with different properties will run first, in the exemple :
With the debug on, the list will start to move after 0.5 seconds.
With the debug off, the list will start to move in 0.0 seconds, sometimes the list move before the subpage displayed, i have to use a delay to avoid this.
Clayton


Date: Thu, 14 Mar 2013 07:25:23 -0700
From: johanje...@gmail.com
To: comman...@googlegroups.com
CC: jar...@commandfusion.com
Subject: Re: CF.setJoin with a callback function


I would say that a callback feature would be a most welcome thing to add to upcoming releases. I have missed this quite a few times. Timers should be seen as a workaround. Subpages e.g. display them-self much slower the first time they are read from memory, I assume that the delay time also could be dependent on a lot of things like platform and OS. 

JohanJ

unread,
Mar 14, 2013, 2:39:25 PM3/14/13
to comman...@googlegroups.com
I have sometimes used this uggly method for doing things when a list has been added, can not be used in your case but could be useful in some other situation.

/**
    *Calls the callback function when the list has been added
    *It stops trying after 50 iterations
    *@param listNumber    the number of the list to check
    *@param listLength    the callback is called when the elements in the list is longer than this value
    *@param callback      the callback function that will be called when the list is added  
    */
   self.callbackWhenListAdded = function(listNumber, listLength, callback) {
      self.Log("length:" + listLength);
      var iterations =0;
      var callbackSend = false;
      var id = setInterval( function() {
         if (iterations>50) {
            clearInterval(id);
         }
         CF.listInfo(listNumber, function(list, count, first, numVisible, scrollPosition) {
               //self.Log("Iter:" + iterations + " List " + list + " has " + count + " items, showing " + numVisible + " items starting from " + first + " (scroll position: " + scrollPosition + "px)");
               if (listLength<=count && callbackSend == false) {
                  callbackSend = true;
                  clearInterval(id);
                  //self.Log("Item count equals list length, select item");
                  setTimeout(function() {
                     callback();
                  }, 200);
               }
         })
      },200);
   }

Clayton Vicente

unread,
Mar 14, 2013, 3:10:05 PM3/14/13
to comman...@googlegroups.com
Ok, this is a good idea, i understand and you help me to solve another problem that i get sometime ago when i was trying to use CF.setProperties with a CF.listAdd. With your function will be easy, since i always will know the length of my list, i can just use your function to see  when the CF.listAdd finished and then call the CF.setProperties.
Very thanks for your help.
Clayton 



Date: Thu, 14 Mar 2013 11:39:25 -0700
From: johanje...@gmail.com
To: comman...@googlegroups.com

Subject: Re: CF.setJoin with a callback function

Jarrod Bell

unread,
Mar 14, 2013, 9:33:00 PM3/14/13
to comman...@googlegroups.com
I don't follow you, but if you could create a very simple (or as simple as possible) GUI to reproduce the issue (and nothing else) then it would really help.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Clayton Vicente

unread,
Mar 14, 2013, 9:38:23 PM3/14/13
to comman...@googlegroups.com
I cant do this right now, but i will do soon.
Thanks for your help.
Clayton


Date: Fri, 15 Mar 2013 12:33:00 +1100
From: jar...@commandfusion.com
To: comman...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages