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

Java Development

Reply
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Diagonal movement with navigationMovement (or anything else)

I've done a good bit of looking around about how to implement diagonal movement using navigationMovement() and so far the only thing I've found has been other people having the same problem with no real resolution. I have a MapField in my app and am allowing the user to pan, but everything is obviously in an up/down or left/right motion because dx and dy aren't set at the same time. Has anyone found another way to get around this, or am I just out of luck? Thanks in advance!

 

Using Eclipse with a BB 9330 simulator on JRE 5.0.0.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Diagonal movement with navigationMovement (or anything else)

Welcome to the forums!

This is not easy, but can be done. Here is an idea:

 

1) Create and scheduleAtFixedRate a TimerTask running every fraction of a second (whichever you feel comformable - say, 20 frames per second).

2) Create a navigation object (state machine) accepting (at least) 3 events: verticalMovement(amount), horizontalMovement(amount), nextFrame(). The first two are called from navigationMovement (if (dx != 0) horizontalMovement(dx); else verticalMovement(dy); return true;) and simply accumulate the movements (might also be used for "mouse acceleration", so to speak); the third one is called on each run() of the TimerTask() (public void run() { _navigationObject(nextFrame()) }).

 

This nextFrame() is the heart of your panning engine. It might get the accumulated dx, dy and set the map in motion using mapField.move() of moveTo(). if you want smooth panning, don't jump to your new position immediately - cap the change, move up to that maximum in the necessary direction and subtract the executed movement from the total you have accumulated rather than resetting that total to (0, 0).

 

The same object might accept zoomIn() and zoomOut() events, called, say, from keyChar() or navigationClick() (check the status parameter to distinguish between, say, click and Alt-click). Or you might want to designate navigationMovement with Alt to zoom the map. Those zooms might happen immediately or accumulated to happen during nextFrame() as well.

 

I hope this answers your question (and maybe more Smiley Happy ).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Diagonal movement with navigationMovement (or anything else)

Thanks for the quick reply. Since posting I've tried something (that I think is) similar. I have it buffering the dx and dy and every 50 ms goes ahead and moves it then resets the buffers. The problem here is that I'm still getting the movements weighted heavily either horizontally or veritcally. Put it to 1 second and even still would have it sometimes scrolling completely in one direction even though the simulator clearly indicated I was moving diagonally. I did notice if I moved slowly it would behave a little better as far as sending (1,0) (0,1) (1,0) (0,1) etc. but haven't figured out a way to capitalize on that yet. Smiley Indifferent

Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Diagonal movement with navigationMovement (or anything else)

I've started looking for other ways to capture the trackpad but so far I haven't ran across anything that looks like it will let me get input from it other than navigationMovement(). I was hoping that I'd find some magic with the Trackball class but that turned out to be a letdown. Anyone know of any other classes/methods/whatever that will let me get input from the trackpad?

Developer
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: Diagonal movement with navigationMovement (or anything else)

Hey, 

 

I am having the same problem even I removed the Trackball.FILTER_XY_SNAP still I dont get the simultaneous non-zero dx, dy in navigationMovement function call. Its weird that such a simple thing is nearly impossible to achieve.

 

Have you found any solution to this problem?

 

Thanks in advance.

 

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Diagonal movement with navigationMovement (or anything else)

Unfortunately I never found a solution to getting both non-zero dx and dy at the same time.

Highlighted
Developer
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: Diagonal movement with navigationMovement (or anything else)

Irony is that blackberry browser is able to do the same very smoothly. I think some apis are hidden from us and browser is leveraging those to achieve the same functionality. I am **bleep** sure that blackberry browser is using something else than navigationMovement to achieve this smooth accelerated movement in all directions.

Somebody from the RIM should comment on this.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Diagonal movement with navigationMovement (or anything else)

 


jprofitt wrote:

Unfortunately I never found a solution to getting both non-zero dx and dy at the same time.


 

Moreover: I almost never get dx or dy greater (in absolute value) than 1. You really have to swipe the touchpad in order to generate a navigationMovement with either dx or dy of just 2!


The pace is OK, though - and that's why I suggested using a state machine and updating the screen at some fixed rate. This way you can easily get two or more navigationMovement invocations between your screen refreshes.

 

I have done that in my project (using this approach mostly for accelerated scroll similar to the swipe-scroll on touchscreen phones) and I can easily get diagonal movements. The downside is that all movements and navigation clicks will have to go through some separate Thread/TimerTask. But that's how you create smooth scrolling, screen transitions and so on anyway (all this working on 4.2.1 phones for me).

 

P.S.: Wow, was it only 4 months ago when you joined the forums? You've become a great resource here since then. Way to go!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Diagonal movement with navigationMovement (or anything else)

[ Edited ]

I had a problem where long swipes would only generate a dx or dy, so I would end up accumulating like a dx=40, dy=0. I tried about any sort of buffering that I could to smooth it out and nothing would work consistently. I did find, however, that slowly moving over the trackpad would respond better.

 

And thanks, appreciate that comment! I've learned a ton along the way from everyone, yourself included Smiley Happy