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: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Invoking PASTE menu action from a background thread

[ Edited ]
if (field == buttonField) {
	try {
	        Thread t = new Thread(new Runnable(){
		public void run() {
			synchronized (UiApplication.getUiApplication().getActiveScreen()) {
				Clipboard cb = Clipboard.getClipboard();
				cb.put("1");
				EventInjector.invokeEvent(new EventInjector.NavigationEvent(EventInjector.NavigationEvent.NAVIGATION_CLICK, 0, 0, KeypadListener.STATUS_SHIFT));
					}
				}
			});
				
				UiApplication.getUiApplication().requestBackground();
				
				synchronized (this) {
					wait(200);
				}
				t.start();
			} catch (Exception e) {
			}
}

 Here is the code that is working fine to insert from the clipboard when the field is empty or if the insertion is making a standalone item. Whenever I try to run this targeting a field containing half a word already (e.g. "holi" for "holiday"), the "1" won't be injected. But if I manually strike the PASTE manu option afterwards, everything goes as I want it to.

That is why I am looking for a way to invoke the PASTE menu item instead of navigation click insertion from within my app. How can I achieve this?

Thanks in advance.

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

Re: Invoking PASTE menu action from a background thread

Yes but it is a bit dubious.

 

The technique is that you get the context menu for the Field, by invoking the Field's getContextMenu().  Then you search through the list of Menus returned, looking for Paste.  This works fine in English, but might be a little more complicated in another locale.  Anyway, having found the menu item, then you just execute its run() method.

 

Give this a go, see if you can get it. 

Developer
Posts: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Invoking PASTE menu action from a background thread

After researching some info concerning this topic I found that the idex of the PASTE menu item is 3. That is it should be exacly the same throughout all the localizations, right? Maybe this could be used in a manner...

Another bug I noticed with the injection I described in the code above is that it makes one extra click of the trackpad when run against OS 6-7.1 - why would it?

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

Re: Invoking PASTE menu action from a background thread

Sorry can't help with either, never tried to do this myself, just understand the theory.......

 

If you can confirm that Paste is 3 in your current locale, then I would agree that it is likely to be 3 everywhere.  Let us know what you find. 

 

Just for the record, in case the link above fails at some stage, the reference to 3 is the Constant vaue for

MenuItem.PASTE. 

Developer
Posts: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Invoking PASTE menu action from a background thread

[ Edited ]

My curent locale is Russian. How can I find out what this would be for Russian? Any clue?

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

Re: Invoking PASTE menu action from a background thread

you can use the Locale class to change the locale.

When i manipulate the menu items of the native phone app i always set the locale to english before (and back after it).
----------------------------------------------------------
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
Developer
Posts: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Invoking PASTE menu action from a background thread

Maybe making my own menu item with the same functinality, but also having the same name in all the locale will be even better. What would you say, guru?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Invoking PASTE menu action from a background thread

Do you always know the screen that this is going to paste into?

Developer
Posts: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Invoking PASTE menu action from a background thread

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

Re: Invoking PASTE menu action from a background thread

OK, then how are you going to know that your menu item is there?