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
Contributor
kilia
Posts: 18
Registered: ‎10-11-2010
My Device: Not Specified
Accepted Solution

Prevent the popup menu (context menu) from displaying upon touch&hold

[ Edited ]

I want to prevent the popup menu (context menu) from displaying upon touch&hold on touch devices (not SurePress).

Currently, I am overriding the touchEvent() method and consuming it in case of TouchGesture.HOVER.

 

protected boolean touchEvent(TouchEvent message) {
	if ((TouchEvent.GESTURE == message.getEvent()) && (TouchGesture.HOVER == message.getGesture().getEvent())) {
		return true;
	}
	return super.touchEvent(message);
}

 

It work's but I'd like to know whether there is a better way of doing it for specific field.

Please use plain text.
Developer
Anand04
Posts: 95
Registered: ‎06-05-2012
My Device: Developer

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

Hi,

you have to override makeMenu method in your MainScreen using instance = Menu.instanceDefault

thanks,
Please use plain text.
Contributor
kilia
Posts: 18
Registered: ‎10-11-2010
My Device: Not Specified

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

Anand04,

 

Override makeMenu and do what exactly? I think you also meant Menu.INSTANCE_CONTEXT and not Menu.INSTANCE_DEFAULT.

 

In any case, this kind of approach involves overriding the MainScreen's makeMenu() method. I prefer something that is more surgical (field specific rather than screen specific).

 

Thanks for the answer.

 

Please use plain text.
Developer
Anand04
Posts: 95
Registered: ‎06-05-2012
My Device: Developer

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

[ Edited ]

use this code:

 

protected void makeMenu(Menu menu, int instance) {
        if(instance == Menu.INSTANCE_DEFAULT){
       // add your menu item here......    
        }
      
    }

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

I am not sure i understood your question correctly:

you can override touchEvent on a field as well, or you could overwrite it on the screen and check for the focused field using getLeafFieldWithFocus.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
kilia
Posts: 18
Registered: ‎10-11-2010
My Device: Not Specified

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

[ Edited ]

I just want to make sure that there is no way to prevent the popup menu from displaying other than overriding touchEvent() (either for the field or for the screen) and consuming the TouchGesture.Hover gesture.

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

there is http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/Field.html#makeContextMenu(... but i think this allows you only to clear or modify the menu, not to avoid it being shown.
others may be more knowledgeable on this area, but i think your approach is valid.
you could also check navigationclick maybe, not sure if the hover gesture is translated to a click, but usually a click opens the context menu.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
kilia
Posts: 18
Registered: ‎10-11-2010
My Device: Not Specified

Re: Prevent the popup menu (context menu) from displaying upon touch&hold

[ Edited ]

Alternatively, if one wants to prevent the context menu from showing no matter how it was invoked, then IMHO one of the most easiest solutions would be to override the Screen's makeMenu() method and super.makeMenu() called only in case the instance parameter == Menu.DEFAULT_INSTANCE. This code disables the context menu for all field on the screen.

 

 protected void makeMenu(Menu menu, int instance) {
    if (Menu.INSTANCE_DEFAULT == instance) {
        super.makeMenu(menu, instance);
    }
}

 

If one want to disable the context menu for some specific field, then the following code can be used.

 

 protected void makeMenu(Menu menu, int instance) {
    if ((Menu.INSTANCE_DEFAULT != instance) && (getLeafFieldWithFocus() == someSpecificField)) {
        return;
    }
    super.makeMenu(menu, instance);
}

 

 

Please use plain text.