If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel
Accepted Solution

Touch event is working outside the buttons

[ Edited ]

Hi,

 

I am developng one app for touch and type phone. Now in one screen of the application, there is 3 buttons. Below is the screen snap shot:

 

9790-03.png

 

 

Here if i touch in the three buttons, it is working. But if i touch outside the buttons, means in the top bar or in the bottom bar, then also touch event is working. Suppose in the below, Add More button is focused. So if i am touching in the bottom bar, then also button touch is working. To resolve this problem, i wrote the below code:

 

try {
			int touchXPos = event.getX(1);
			int touchYPos = event.getY(1);
			int addBtnXPos = btnAddMore.getLeft();
			int saveBtnXPos = btnSave.getLeft();
			int helpBtnXpos = btnHelp.getLeft();
			
			int vfmTitleTouch = m_vfmTitle.getHeight();

if ((touchXPos >= addBtnXPos + 40) && (touchXPos <= (addBtnXPos + btnAddMore.getWidth() + 40)) && (touchYPos <= screenHeight -10) && (touchYPos >= (screenHeight -10 - btnAddMore.getHeight()))  /*&& (touchYPos < (screenHeight-gmYPos)) */) 
			{
				Logger.out("touchEvent", "------------------------------1");
				showPopUp();
				return true;
			}
			
			else if ((touchXPos >= saveBtnXPos + 40) && (touchXPos <= (saveBtnXPos + 40 + btnSave.getWidth())) && (touchYPos <= screenHeight -10) && (touchYPos >= (screenHeight -10 - btnSave.getHeight()))/* && (touchYPos < (screenHeight-gmYPos))*/ ) 
			{
				Logger.out("touchEvent", "------------------------------2");
				saveToDb();
				return true;
			}
			
			else if ((touchXPos >= helpBtnXpos) && (touchXPos <= (helpBtnXpos + btnHelp.getWidth())) && (touchYPos <= (btnHelp.getTop() + btnHelp.getHeight())) && (touchYPos >= btnHelp.getTop())/* && (touchYPos < (screenHeight-gmYPos))*/ ) 
			{
				Logger.out("touchEvent", "------------------------------3");
				UiApplication.getUiApplication().pushScreen(new HelpScreen());
				return true;
			}
			else if ((touchYPos <= screenHeight - hfmBtn.getHeight()) && (touchYPos >= (vfmTitleTouch)))
			{
				Logger.out("touchEvent", "------------------------------4");
//				Logger.out("touchEvent", "touchY::::" +touchYPos  + "Vfm Title::::" +vfmTitleTouch  + "  "+"GM Y Pos"+  gmYPos);
				return true;
			}
			else
			{
				Logger.out("touchEvent", "------------------------------5");
				return false;
			}
		}
		catch (Exception e) 
		{
		}
		
		return super.touchEvent(event);
	}

 But it is not working..Can any one help me out??

And touch event should work in the middle of the screens like for check boxes also..

 

Thanks..

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Touch event is working outside the buttons

Should the "return false;" here:

 

Logger.out("touchEvent", "------------------------------5");
return false;

 

be

Logger.out("touchEvent", "------------------------------5");

return super.touchEvent(event);

 

 

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Touch event is working outside the buttons

I tried in this way..But it is not working. Same problem. Touching outside the button, it is working the button functionality.

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Touch event is working outside the buttons

Where are you overriding touchEvent? Is it on the Screen, Manager or Field level?

getX and getY return distance from the upper left corner of the field overriding touchEvent. getLeft returns the horizontal offset of the field within its immediate manager. Thus you should be careful where exactly you override it and how you further calculate whether the touch is inside the field.

 

For example, if you override touchEvent within the Field, this would be one of the correct ways to determine whether the touch was "inside":

int xPos = message.getX(1);
int yPos = message.getY(1);

if (xPos >= 0 &&  xPos < getWidth() && yPos >= 0 && yPos < getHeight()) {
  ...
}

 If you override it on the level of the manager containing the field, it becomes more like

int xPos = message.getX(1);
int yPos = message.getY(1);
XYRect myFieldExtent = myField.getExtent();
if (myFieldExtent.contains(xPos, yPos)) {
  ...
}

If you override it on the screen level, you might have to make some calculations to find out the exact position of the Manager and the Field, but I hope you're getting the idea by now.  Ask again if you need any more help.

 

Oh, and just making sure - you do check the event type such as CLICK etc.?

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.