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: 239
Registered: ‎07-26-2010
My Device: Z10
My Carrier: Telkomsel

Using deCarta API in Torch

I'm using deCarta in my app. In order to handle touch events (in Torch/Storm), I use this code:

 

 protected boolean touchEvent(TouchEvent te) {       

int x1=0, x2=0, y1=0, y2=0;   

int diffX=0, diffY=0;       

 

if (te.getEvent() == TouchEvent.CLICK){   

x1 = te.getGlobalX(1);   

y1 = te.getGlobalY(1);   

}       

else if (te.getEvent() == TouchEvent.MOVE) {           

try {           

x1 = te.getGlobalX(1);

y1 = te.getGlobalY(1);           

x2 = te.getGlobalX(2);           

y2 = te.getGlobalY(2);           

diffX = x2 - x1;           

diffY = y2 - y1;               

map.moveView(diffX, diffY);           

}            

catch (RuntimeException es) {           

}        }return true;}

 

map is a part of deCarta API.

Now every time I move the marker on the map (even it's only a slight one), the destination will shifted quite significant from the expected one.

 

For example: if my current position is on Detroit, and I move that marker very very slightly to the left, I'll reach Ann Arbor.

 

During debugging, I saw that x1 and y2 were always changed, but x2 and y2 were always -1 and -1. I guess I'm not understanding TouchEvent well here? 

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Using deCarta API in Torch

If getGlobalX/Y or getX/Y return -1 then no touch point exists at that point. It's not a history function.

 

When a "down" event occurs, set x1 and y1. Then when a move event occurs, get diffX and diffY by getting the same points as you did with the "down" event but subtract x1 and y1 with them as you do already.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 239
Registered: ‎07-26-2010
My Device: Z10
My Carrier: Telkomsel

Re: Using deCarta API in Torch

"Then when a move event occurs, get diffX and diffY by getting the same points as you did with the "down" event but subtract x1 and y1 with them as you do already." -> isn't this what I did already?
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Using deCarta API in Torch

I even say, "as you do already". To use your code:

 

protected boolean touchEvent(TouchEvent te) {

int x1=0, x2=0, y1=0, y2=0;

int diffX=0, diffY=0;

 

if (te.getEvent() == TouchEvent.CLICK || te.getEvent() == TouchEvent.DOWN){

x1 = te.getGlobalX(1);

y1 = te.getGlobalY(1);

}

else if (te.getEvent() == TouchEvent.MOVE) {

try {

x2 = te.getGlobalX(1);

y2 = te.getGlobalY(1);

diffX = x2 - x1;

diffY = y2 - y1;

map.moveView(diffX, diffY);

}

catch (RuntimeException es) {

} }return true;}

 

That's what I was trying to get across.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.