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
New Developer
Posts: 20
Registered: ‎01-05-2009
My Device: Not Specified

Injecting Key Strokes to parent Screen

I have a custom MainScreen which has a VerticalFieldManager and a bunch of custom fields that are focusable. When the user trackball clicks on of the field I want to be able to inject a key stroke to the application that launched my custom main screen. I have this "almost" working, but the application is capturing the trackball click and then my injected key strokes.

 

I have the application setup so that the MainScreen overrides the TrackBallClick event and injects the key strokes and returns true to stop the trackballclick event from going any further.

 

Why is the trackball click event being passed to the calling application?

 

 

Thanks

Greg

Developer
Posts: 238
Registered: ‎08-26-2008
My Device: Not Specified

Re: Injecting Key Strokes to parent Screen

Hi,

 

does it depend on which application has focus? Just set your application to keystroke-manipulate into foreground

and try again.

 

Regards,

Jochen

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Injecting Key Strokes to parent Screen

I think we need to careful that we understand which Objects are involved. For example, when you say the keystrokes are being passed to your application, which Object is that.  Is it your UiApplication?  Can you explain the problem again, but carefully explaining which Objects are involved and their relationships?

 

One thing though, you need to watch carefully if you have set up appropriate Listeners.  Have you used these in your processing, or are you just using the MainScreen methods which do this for you.

New Developer
Posts: 20
Registered: ‎01-05-2009
My Device: Not Specified

Re: Injecting Key Strokes to parent Screen

Here is the Hierarchy

 

 - Base App (not my app)

     - MainScreen (mine)

           -VerticalFieldManager (mine)

               -CustomField (mine - generating the Trackball Click)

 

I want to be able to inject a keystroke to the Base App. Right now there are no event handlers in either the CustomField or the VerticalFieldManager. The MainScreen has:

 

protected boolean trackwheelClick(int status, int time)
{        
        KeyCodeEvent keyCode = new EventInjector.KeyCodeEvent(KeyCodeEvent.KEY_DOWN, 'V', KeyListener.STATUS_ALT);
        KeyCodeEvent keyCode2 = new EventInjector.KeyCodeEvent(KeyCodeEvent.KEY_UP, 'V', KeyListener.STATUS_ALT);
        EventInjector.invokeEvent(keyCode);
        EventInjector.invokeEvent(keyCode2);
       
        this.close();
              
        return true;

}

 

As I stated above, what happens is that the Base App registers a Trackball Click before it gets my injected keycode. I thought returning true would have prevented this. Do I need to implement additional handlers in the VerticalFieldManager of CustomField?

 

 

Thanks

Greg

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Injecting Key Strokes to parent Screen

Thanks for this information.  It might be useful to know what classes are involved in the Base App.  When it pushes you Screen, is there a chance that it registers a TrackwheelListener against your Screen? 

 

In general al however, what you are suggesting should not happen.  The UI events should be directed to the active Screen. 

 

I've a few other questions prompted by your response

 

1) "Base App registers a Trackball Click before it gets my injected keycode."

 

How do you know that it does this?

 

2) What device and level of OS are you running this on?  Is this consistent and obeys the forward compatibility rule for both your and the Base App?

 

3) If you are running on trackball devices (as opposed to scrollwheel devices like the 8700), you can use navigationClick to trap the 'click'.  From memory, this gets fired before the trackwheelClick, and trackwheelclick (that is there for compatibility) only gets fired if navigationClick  doesn't return true.  Can you confirm that navigationClick is not being used anywhere?

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Injecting Key Strokes to parent Screen

if i understand the szenario correctly the problem is more on the design side.
a background application does not recieve navigation events (except the 4 magic keys).

why don't you notifiy your application and do stuff programatically instead of going via navigation events?
you can use global events, the runtime store or the applicationmanager to communicate with your application.
----------------------------------------------------------
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
New Developer
Posts: 20
Registered: ‎01-05-2009
My Device: Not Specified

Re: Injecting Key Strokes to parent Screen

Peter,

 

To answer your questions:

 

1) I know that the Base App is getting a trackball/wheel click event because the Base App's menu pops up. After that it responds to the KeyCode event. The Simulator seems to work correctly, the Base App's menu never pops up...it only happens on my physical device.

 

2) I am using an 8310 with OS 4.5.0.81 (same device/os simulator)

 

I changed to a navigationClick instead of using the trackwheel click for better compatibility; menu in Base App still pops up. I have yet to try the application on other devices.

 

I would have thought that returning false would prevent this. Is it because I am calling this.close() on the MainScreen before it returns true? Why does it work on the Sim but not my device :s

 

 

Thanks for all your help.

Greg

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Injecting Key Strokes to parent Screen

Could you further elaborate on the following:

 

a) what classes are involved in the Base App?

 

b) how does the Base App interact with your Screen - does it push your Screen?

 

c) Does the Base App register any listeners against your screen?

 

As I said in my previous post, n general, what you are suggesting should not happen.

 

Could you attach the device, debug it, and put a break point in the makeMenu of the base App.  I would be interested to know how it was invoked.  I wonder if some event on your screen has decided that it needs to get the menu from the Base App.

 

I am surprised that you see a difference between the Simulator and the OS in this regard, if they are the same Level.  Can I suggest you have a look in the Simulator downloads to see if you find the exact match for your device?.  And you are using JDE/plug-in that is 4.5 or earlier aren't you. 

 

Regarding your returning false, can you confirm that your code is actually invoked and invoked before the menu is displayed.  There are issues is actually being able to do this.  Here is grubby suggestion, that might work.  In your navigationClick method, do an invokeAndWait on a Runnable that displays a Dialog.alert().  This needs to be an invoke and wait, so that any other screen events are scheduled and run before the Dialog appears.  Now when the Dialog appears, because it does not cover the whole screen, if the menu appears underneath it, then you know it was invoked before you got called.  Alternatively, once you click the Dialog, the menu might appear, This is not conclusive, I can see holes in this, however it is an interesting experiment.