Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T
Accepted Solution

TrackPad Navigation control

I have  widget application that displays a datatable in a div. I am using the Rim navigation and capturing the onLeft and onRight events when the Div containing the datatable is selected. I want to give my users the ability to swipe across their trackpad and be able to move to the next datatable, but currently on a swipe a user may scroll through 3 or 4 datasets. 

 

Any recommendations on how to deal with this? It reminds me of the issue of "button bounce" in an embedded development environment.  I have tried a setTimeout to delay the changing of the datasets, but with to no avail.

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: TrackPad Navigation control

Can you describe what actions you are performing in you trapped JavaScript function?  Like are you setting focus to some other elements on the screen, performing AJAX etc, or is the JavaScript function getting called multiple times?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: TrackPad Navigation control

The function changes the contents of a div to the next element in a global array. The array consists of HTML tables.

 

 

function nextButtonPushed() {
     if (currentStationData !== null) {
         document.getElementById("MidDiv").innerHTML = currentStationData[dataNumber];
dataNumber++;

}

 

Pretty simple. It is definitely getting called multiple times with 1 swipe. I've tried just adding a global boolean indicator to everything after the first call, but it didn't seem to help. Something like below...

 

var busy = false;

function nextButtonPushed() {
     if (!busy) {
         busy = true; 
         if (currentStationData !== null) {
              document.getElementById("MidDiv").innerHTML=currentStationData[dataNumber];
          dataNumber++;
          busy=false;
}
}

 

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: TrackPad Navigation control

Hmm.... interesting...

 

I can explain a little bit about how the navigation mode fires the events.  When a scroll in a direction is triggered the code checks to see if there is a JavaScript event assigned to that direction.  If there is, it will fire that event.  Pretty simple, but it can get complicated if scrolling detection is in fact being triggered multiple times.

 

What would be happening if there are multiple events getting fired is that the second event would wait for the first event thread to finish before running the second event since JavaScript is single threaded.  That would be why your boolean flag isn't working even though it is global.

 

Let me talk to the development team and see if there is a way where you could reduce the sensitivity of the triggering of the events.  All the code for the focus based navigation is included in the template source code distributed with the SDK.  So if there is a quick adjustment in code, we should be able to point you in the right direction for making a fix for your app.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: TrackPad Navigation control

After looking into the scenario, this is what our development team had for input:

 

 

In navigation mode, the “onRight” or “onXXX” direction event is fired based on the “navigationMovement” event fired based on trackball movement and in our handler we ignored the delta distance moved in that specific direction and only are interested in the direction value. 
Normally, a (big) swipe should still fire the “navigationMovement” event once with a big delta distance. However, probably in his case, his one swipe fired “navigationMovement” event multiple times, so our “onXXX” direction events were fired with same number of times. Yet, how many times of “navigationMovement” events will be fired in “one” swipe is unknown and unpredictable, which I guess is based on each user’s trackball condition and sensitivity settings.

 

In navigation mode, the “onRight” or “onXXX” direction event is fired based on the “navigationMovement” event fired based on trackball movement and in our handler we ignore the delta distance moved in that specific direction and only are interested in the direction value. 
Normally, a (big) swipe should still fire the “navigationMovement” event once with a big delta distance.


However, probably in this case, the one swipe fired “navigationMovement” event multiple times, so our “onXXX” direction events were fired the same number of times. Yet, how many times “navigationMovement” events will be fired in “one” swipe is unknown and unpredictable, which I guess is based on each user’s trackball condition and sensitivity settings.

 

What I would suggest is setting a time threshold in your JavaScript where you can have a global time stamp set on first scroll.  Subsequent scroll event would need to happen after that threshold or you would just exit the function.  You could do a quick time comparison to see if the time threshold was met.

 

I think a time stamp would work better than a boolean flag in this case.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: TrackPad Navigation control

Sounds like a good solution. I'll give it a run and let you know the results.

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
Developer
jmace
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: TrackPad Navigation control

A timestamp comparison works. For those interested, I was able to get by with a 1 second difference.

 

 

...
tempSwipe = new Date();
if (currentStationData !== null && lastSwipe < tempSwipe)
{
   tempSwipe.setSeconds(tempSwipe.getSeconds() + 1) //add 1 second
   lastSwipe = tempSwipe;
   ...
   //logic
   ...
}

 

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.