Trackwheel Click Event Issue - blackberry

I am dealing with KeywordFilterField which is populated with the list of the countries. Now the problem i am facing is that when i click the particular country it should move to the next screen as I have written the pushScreen code in the trackwheelClick event after checking that _keywordFilterField is focusable or not, but this is not the case. The Menu opens when trackwheelClick event is fired, at the center of the screen, rather than moving onto the next screen.Can anybody have the idea why Menu dialog opens on the trackwheelclick event instead of going to the next screen.
See what i have done on trackwheel click event:
protected boolean trackwheelClick(int status, int time) {
if (_keywordFilterField.isFocus()) {
int index = _keywordFilterField.getSelectedIndex();
ReadableList readableList = _keywordFilterField.getResultList();
Object selectedCountry = readableList.getAt(index);
String countryName=selectedCountry.toString();
urlutf8Encoder=new URLUTF8Encoder();
String newCountry=urlutf8Encoder.encode(countryName);
pushToSearchResult(newCountry,countryName);//To Next SCreen
return true;
}
return false;
}
But it looks like:

The trackwheelClick event returns a boolean that indicates whether the event is consumed. Once an event is consumed, it stops propagating to other UI elements. If you return true, the menu will stop appearing.

Related

Double tap using Appium Java 2.0

I couldn't find an implementation of a double tap for Appium that was straightforward and allowed you to pass in the element locator strategy, so here goes:
public static void doubleTapElementBy(By by) {
WebElement el = getDriver().findElement(by);
MultiTouchAction multiTouch = new MultiTouchAction(getDriver());
TouchAction action0 = new TouchAction(getDriver()).tap(el).waitAction(50).tap(el);
try {
multiTouch.add(action0).perform();
} catch (WebDriverException e) {
logger.info("Unable to do second tap on element, probably because element requieres single tap on this Android version");
}
}
You can also try below approach using tap method in TouchAction class.
TouchAction taction = new TouchAction(driver);
taction.tap(tapOptions().withElement(ElementOption.element(YOUR_WebElement))
.withTapsCount(2)).perform();
You will need to add below static import as well:
import static io.appium.java_client.touch.TapOptions.tapOptions;
This is a workaround in pseudocode and possibly there's a more "official" way to do it, but it should do the work if no other solution is available:
Interpretmessages(){
switch(msg)
{
OnClick:
{ if (lastClicked - thisTime() < 0.2) //if it was clicked very recently
{doubleTapped()} //handle it as a double tap
else{lastClicked = thisTime()} //otherwise keep the time of the tap
} //end of OnClick
} //End of Message Handler
}//End of switch
}//End of messageHandler
If you have access to ready timer functions, you can set a function to be executed 0.2s after the click has gone off:
OnClick: if (!functionWaiting) // has the timer not been set?
{
enableTimer(); // set a function to go off in x time
clicks = 0; //we'll tell it that there's been one click in a couple of lines
} //set it for the first click
clicks++; //if it's already clicked, it'll become 2 (double tap) otherwise it's just one
So, the idea is that when you get a tap, you check if there's been another one recently (a. by checking the relative times, b. by checking if the function is still pending) and you handle it dependingly, only note that you will have to implement a timer so your function fires a bit later so you have time to get a second tap
The style draws upon the Win32's message handling, I'm pretty sure it works there, it should work for you too.
Double tap and hold -- Use below code:
new TouchAction(driver).press(112,567).release().perform().press(112,567).perform();
Double tap -- Use below code:
new TouchAction(driver).press(112,567).release().perform().press(112,567).release().perform();

Touch Event Blackberry Triggered Multiple Times

I'm working with the Blackberry Touch Event and I need to process the TouchEvent.MOVE, TouchEvent.UP and TouchEvent.DOWN to move a carousel of images and the TouchEvent.CLICK to generate some specific action.
My problem is that the touchEvent() method is being called several times. How can I prevent this? Because the behaviour is getting all messed up.
For example: when I just want to capture the TouchEvent.CLICK event, the UP-DOWN-MOVE-CLICK are being triggered one after the next.
My code does the following:
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
//CHANGE THE CONTENT OF A FIELD
return true;
} else if ((message.getEvent() == TouchEvent.MOVE)
|| (message.getEvent() == TouchEvent.UP)
|| (message.getEvent() == TouchEvent.DOWN)) {
//DELETE THE FIELD
//MOVE A CAROUSEL OF IMAGES
} else {
return false;
}
}
public void moverTouch(int dx) {
//ADD THE FIELD PREVIOUSLY DELETED
}
As you can see, when the CLICK event is captured, I need to change the content of a field, but when the MOVE or UP or DOWN event is captured, I need to delete that Field from his manager, do some working with a carousel of images, and then re-add the field previously deleted.
The carousel moving part works fine, but when I try to capture JUST the CLICK event, and the others are being triggered as well, but the moverTouch() function doesn't get triggered because there is no actual movement on the carousel of images, I end up with a deleted field that I need to update its content.
At a glance:
I think you need to differentiate touch gestures (I believe you are "listening" for something like a swipe gesture to scroll the gallery image) from "normal" touch events (specifically you need to process TouchEvent.CLICK to apply "some specific action" to the clicked image).
To decide whether the TouchEvent represents a gesture there is a TouchEvent.GESTURE constant. Then it is possible to know what exactly TouchGesture it represents by calling TouchEvent.getGesture().
Some sample code for touch gestures can be viewed here.

Handling Touch EventListener in presence of navigationClick()

In application, Whenever i move bewteen tabs a full menu, copy, switch application pop up open.
To prevent this i override navigationClick method.
Now pop is not shown. In my second tab i have implemented drop down list. Because i have override navigationClick method when i click on drop down list it is not showing me list of items.
Any idea will be apperciated.
Update:
Here is navigationClick implementation:
public boolean navigationClick(int status, int time) {
return true;
}
Make sure while selecting a tab, no errors occur which probably could be the reason for the menu options to pop up. if this is fixed i guess the subsequent problem will be dissolved!
Out of my experience i have observed the menu pops up in blackberry when a NullPointerException event occurs.
Just check the logs or debug to make sure no exception occurs when you navigate between tabs
If you want to click the labelfield then:
LabelField labelField=new LabelField("Click")
{
protected boolean navigationClick(int status, int time)
{
doLabelFieldClicked();
return true;
}
}
and if Menu option is highlighted then override this:
public boolean onMenu(int instance)
{
return true; //It doesn't show the Menu option.
}
If I am thinking wrong let me know.
I solved this problem by implementing navigationClick() while creating lablelField
tab5 = new LabelField("News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
{
public boolean navigationClick(int status, int time)
{
return true;
}
};

Blackberry Button not working in HorizontalFieldManager

My workFlow is like this ... I have taken Three HoriZontalManager one for holding theBackgroundImage of the button and two HoriZontalManager to hold the CustomButton and i am adding the main hfm which hold the button and the background image at top and then i have added the list in a VerticalfieldManager but i dont get the button Working the focus always remains on the list Field. Now when I click on the Button the focus always resides on the First row of the list Field so it always show me the picker which is actually i have implemented on the first row of listfield. How can i Solve it ..
Thanks in Advanced..
Please help.
I have solved This issue ... I had to check that if the focus is on the button then do my work else the list field will be invoked and it solved the issue. And it works for touchScreen simulator as well as trackpad devices.
protected boolean navigationClick(int status, int time) {
// if the row select do something with it
// for first row which is time
if(backCustomButton.isFocus()) {
UiApplication.getUiApplication().pushScreen(new saveScreen());
}else if (saveCustomButton.isFocus()) {
Dialog.inform("Save Button on focus");
}else
if (_list.getSelectedIndex() == 0){
// Do the ListSpecific things
}

hiding menu on click

I am using NullField() in one of my screen so that the default focus should not be on any of the button . but when i am clicking on the screen where no field is there , menu screen is being displayed. i dont want that menu screen to be poped up tough it should open when i click menu button.
Thanks alot
override method.
protected boolean navigationClick(int status, int time) {
Field focus = UiApplication.getUiApplication().getActiveScreen()
.getLeafFieldWithFocus();
if (focus instanceof NullField) {
return true;
}
return super.navigationClick(status, time);
}
Note:This code is only for giving you hint.

Resources