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: 100
Registered: ‎04-07-2009
My Device: Not Specified
Accepted Solution

TouchEvent won't work properly with two fingers moving

Hello,

 

I'm not quite sure, where the problem is. Running my code it happens, that moving finger 1 causes actions that just could be triggered by moving finger 2. When moving finger 2 then, still actions are triggered, that could only be triggered by finger 2, so it seems to be strange a little bit. This also is a little bit messy to debug. Anyone ideas? Is it a case for the Issue Tracker?

 

	
	private int lastX1;
	private int lastY1;
	private int lastX2;
	private int lastY2;
	private int lastAngle;
	private boolean fingerOne = false;
	private boolean fingerTwo = false;

	boolean touchEvent(TouchEvent message) {
		
		switch(message.getEvent()) {
		
		case TouchEvent.DOWN:
			if(message.getX(1) > -1) {
				lastX1 = message.getX(1);
				lastY1 = message.getY(1);
				fingerOne = true;
			}
			if(message.getX(2) > -1) {
				lastX2 = message.getX(2);
				lastY2 = message.getY(2);
				lastAngle = Fixed32.atand2(lastX1 - lastX2, lastY1 - lastY2);
				fingerTwo = true;
			}
			return false;
			
		case TouchEvent.MOVE:
			if(message.getX(1) > -1 &&
					(lastX1 != message.getX(1) || lastY1 != message.getY(1))) {
				//do some action here
				lastX1 = message.getX(1);
				lastY1 = message.getY(1);
				if(fingerTwo) {
					lastAngle = Fixed32.atand2(lastX1 - lastX2, lastY1 - lastY2);
				}
			}
			if(message.getX(2) > -1 &&
					(lastX2 != message.getX(2) || lastY2 != message.getY(2))) {
				lastX2 = message.getX(2);
				lastY2 = message.getY(2);
				final int lastAngle = this.lastAngle;
				this.lastAngle = Fixed32.atand2(lastX1 - lastX2, lastY1 - lastY2);
				final int rotation = Fixed32.toRoundedInt(this.lastAngle - lastAngle);
				//do other action with rotation here
			}
			return false;
			
		case TouchEvent.UP:
			if(message.getX(1) > -1)fingerOne = false;
			if(message.getX(2) > -1)fingerTwo = false;
		}
		
		return false;
	}

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: TouchEvent won't work properly with two fingers moving

I'm not sure what the problem is that you are having, but there is an issue with the TouchEvent returning wrong values if the two touch points cross each other (ie if you touch the left and right sides of the screen then move your fingers together, once they cross the X1 value will now follow finger 2 instead of finger 1).

Developer
Posts: 100
Registered: ‎04-07-2009
My Device: Not Specified

Re: TouchEvent won't work properly with two fingers moving

Thank you that matches exactly. And if you lift finger two then it jumps back. But I hadn't found it in the Issue Tracker.

Developer
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: TouchEvent won't work properly with two fingers moving

Then report it.

---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.