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
dkonigs
Posts: 256
Registered: ‎07-25-2008
My Device: Bold 9900
Accepted Solution

Differentiating between trackwheel and trackball clicks on OS v4.1

I'd like my app to conveniently handle the trackball clicks on capable devices, which provide a separate key for accessing the menu.  However, I'd still like to work on older trackwheel devices, which don't have a separate menu key.

 

To this end, I've noticed that I can start by overriding the Screen.trackwheelClick() method.  However, I'd like to find a way to differentiate between trackwheel and trackball clicks, and not use any magic numbers in my code.

 

My own quick testing has found that the status parameter of trackwheelClick() is different on the two kinds of devices.  With a 7100t (wheel), its "17039360", and with an 8820 (ball), its "536870912".  If I convert to binary, both these numbers look quite clean.  However, I'd rather use official API constants for my checks in trackwheelClick().

 

Any recommendations?

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Differentiating between trackwheel and trackball clicks on OS v4.1

There isn't any built in method or constant to support this.  Trackball devices came out after BlackBerry handheld software version 4.1.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 14
Registered: ‎07-18-2008
My Device: Not Specified

Re: Differentiating between trackwheel and trackball clicks on OS v4.1

[ Edited ]

Hi,

 

Overriding Screen.trackwheelClick() isn't recommended for various reasons, including the fact that it may be called internally by other events such as the invocation of menu buttons, etc.

 

An elegant way to support/differentiate trackwheel vs. trackball usage with a single build is to check the instance parameter of the Screen.onMenu() event. On a trackball device this value will be 65536 when the trackball is clicked or 1073741824 when the main menu button is used (default = 0 for trackwheel devices). You can therefore implement your logic as below. This also has the desired effect that the menu will also be displayed in the correct screen location depending on whether the main menu button (menu bottom left) vs. trackball (context menu, bottom) or trackwheel menu (menu top right) is clicked. You can obviously override any of these to capture and action just the click (for trackwheel or trackball).

 

private final static int MENU_CONTEXT = 65536; private final static int MENU_MAIN = 1073741824; public boolean onMenu(int instance) { if (instance == MENU_MAIN) //main menu button pressed, display menu bottom left { super.onMenu(instance); return false; } else if (instance == MENU_CONTEXT) //trackball click (context menu, display bottom) - override here { return openItem(); } else //trackwheel click, display main menu top right (or override if required) { super.onMenu(instance); return false; } }

 

Hope that helps,

 

James

Message Edited by jshannon on 07-29-2008 09:07 AM
CTO | DevelopIQ
www.developiq.com
Developer
dkonigs
Posts: 256
Registered: ‎07-25-2008
My Device: Bold 9900

Re: Differentiating between trackwheel and trackball clicks on OS v4.1

James,

I was actually investigating that approach before I read up on trackwheelClick().  But again, I don't like the idea of magic numbers that aren't tied to constants provided by the API.  As such, I wonder if those values to come from constants defined in the API (some version of it).  However, for the time being, your solution probably is the best approach, so I'll go ahead and use it.  (and if anyone wonders, on my 7100t simulator, instance=0)

 

Thanks.

 

 

New Developer
New Developer
bb9
Posts: 29
Registered: ‎07-28-2008
My Device: Not Specified

Re: Differentiating between trackwheel and trackball clicks on OS v4.1

Wouldn't the following make more sense (and be easier to remember, and less error prone)?

 

 

private final static int MENU_CONTEXT = 0x10000; private final static int MENU_MAIN = 0x40000000;

 

 

 

New Developer
Posts: 14
Registered: ‎07-18-2008
My Device: Not Specified

Re: Differentiating between trackwheel and trackball clicks on OS v4.1

You'll find these constants in the JDE starting with 4.2 in the net.rim.device.api.ui.component.Menu class - see below - but these obviously aren't defined in JDE 4.1 since the menu key and the concept of a contextual menu didn't exist until OS 4.2.

 

public static final int INSTANCE_CONTEXT //Menu instance is the context one. public static final int INSTANCE_CONTEXT_SELECTION //Menu instance is during selection. public static final int INSTANCE_DEFAULT //Menu instance is the default one.

 

Kind regards,

 

James

CTO | DevelopIQ
www.developiq.com