BlackBerry: define direction of Scroll or Focus change - blackberry

Does BlackBerry provide any functionality to track focus or scroll change direction?
On our UI we have a horizontal tab bar, and under that a list.
If the user has navigated far down the list and decides to click another tab, it is difficult to get the focus back on the Tab control. The user must scroll up to the first list item and then the focus will move to the tab.
Since the list has no left-right component, can I catch horizontal scroll events to change the currently focused tab?
Similarly, I would like to catch vertical scroll events to go back to the list.

For navigation control you can override
protected boolean navigationMovement(int dx, int dy,
int status, int time) {
// TODO Auto-generated method stub
return super.navigationMovement(dx, dy, status, time);
}
here dx for horizontal navigation
and dy for vertical navigation.
if you want to listen focus change you can implement this method
public void focusChangeNotify(int arg0) {
// TODO Auto-generated method stub
super.focusChangeNotify(arg0);
}

Related

Unable to scroll Horizontally in Appium using UiScrollable and TouchActions

I am trying to scroll till the Gift Card option on Make My Trip Home Page and then Click it. So far I have tried below two approaches without success. I am also attaching the screenshot of the App Home Page for clear understanding.
Approach 1 : Using AndroidUIAutomator to scroll to particular element.
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()"
+ ".resourceId(\"com.makemytrip:id/rvHomePageIcon\"))"
+ ".scrollIntoView(new UiSelector().textMatches(\"Gift Cards\")"
+ ".instance(0));"));
Result : This does not scroll but clicks on Homestays option on the app.
Approach 2:
WebElement eleOne = driver.findElement(By.xpath("//*[#text='Flights']"));
WebElement eleTwo = driver.findElement(By.xpath("//*[#text='Gift Cards']"));
TouchAction t = new TouchAction(driver);
t.longPress(longPressOptions().withElement(element(eleOne))
.withDuration(ofSeconds(8))).moveTo(element(eleTwo))
.release().perform();
Result : This throws No Such Element Found exception as eleTwo is currently not in frame. I tried to tweak this approach and enter eleTwo as an element which is visible on screen just to see if the scrolling works and it did work.
But Somehow I am not sure on how to handle it for elements which are not visible on screen.
I would like to scroll the top options list and then click on GiftCard which is the last option on top widget menu.
I am using AppiumDriver with Java-Client 7.3.0.
You can try this, With uiAutomator2 (set scrollable as true):
public void scrollByID(String Id, int index) {
try {
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\""+Id+"\").instance("+index+"));"));
} catch (Exception e) {
e.printStackTrace();
}
}
You can scroll Horizontal and vertical based on screen size with Touch Action. Here is sample code.
public void scrollHorizontally() {
int y = driver.manage().window().getSize().height / 2;
int start_x = (int) (driver.manage().window().getSize().width * 0.2);
int end_x = (int) (driver.manage().window().getSize().width * 0.8);
TouchAction dragNDrop = new TouchAction(driver)
.press(PointOption.point(start_x, y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))
.moveTo(PointOption.point(end_x, y))
.release();
dragNDrop.perform();
}
I have written one detailed answer to scroll with different approaches. You can check here:
How to reach the end of a scroll bar in appium?

Horizontally centering a popup window in Vaadin

I have added a popup window to my main UI as follows:
Window component = new Window();
UI.getCurrent().addWindow(component);
Now, I want my popup to be centered horizontally and e.g. 40 pixels from the top of the screen. As far as I can see Vaadin has 4 methods for positioning my window.
component.center()
component.setPosition(x, y)
component.setPositionX(x)
component.setPositionY(y)
None of these are really what I want. I was hoping at first that setPositionY might help me. This does allow me to get the right distance from the top, but the x-position is now set to 0, where I wanted it to be centered.
The setPosition might have helped if I was able to calculate what the x-position should be, but this would require me to know the width of the component in pixels, but component.getWidth just tells me 100%.
Next I tried to use CSS styling on the component, writing and explicit css rule and adding it to the component with addStyleName. It seems though that Vaadin overrides whatever I wrote in my css with its own defaults...
Any ideas how to get my Window component positioned correctly?
I used the methods getBrowserWindowWidth() and getBrowserWindowHeight() from the com.vaadin.server.Page class for this.
I centered my "log" window horizontally in the lower part of the browser window with
myWindow.setHeight("30%");
myWindow.setWidth("96%");
myWindow.setPosition(
(int) (Page.getCurrent().getBrowserWindowWidth() * 0.02),
(int) (Page.getCurrent().getBrowserWindowHeight() * 0.65)
);
Solution 1: Use SizeReporter
Indeed, setPositionY() will reset the window's centered property to false. As the width of your pop-up and that of your browser window are not know before they appear on the screen, the only way I know to get those values is to use the SizeReporter add-on. Its use is quite straightforward:
public class MyUI extends UI {
private Window popUp;
private SizeReporter popUpSizeReporter;
private SizeReporter windowSizeReporter;
#Override
protected void init(VaadinRequest request) {
Button button = new Button("Content button");
VerticalLayout layout = new VerticalLayout(button);
layout.setMargin(true);
popUp = new Window("Pop-up", layout);
popUp.setPositionY(40);
addWindow(popUp);
popUpSizeReporter = new SizeReporter(popUp);
popUpSizeReporter.addResizeListenerOnce(this::centerPopUp);
windowSizeReporter = new SizeReporter(this);
windowSizeReporter.addResizeListenerOnce(this::centerPopUp);
}
private void centerPopUp(ComponentResizeEvent event) {
int popUpWidth = popUpSizeReporter.getWidth();
int windowWidth = windowSizeReporter.getWidth();
if (popUpWidth == -1 || windowWidth == -1) {
return;
}
popUp.setPositionX((windowWidth - popUpWidth) / 2);
}
}
This piece of code will be okay as long as you don't resize the pop-up. If you do, it will not be automatically recentered. If you replace addResizeListenerOnce() by addResizeListener() then it will automatically recenter the pop-up but you'll get some "UI glitches" as the add-on sends resize events almost continually while you're resizing your pop-up...
You could try to do it using CSS, but I personally avoid CSS as much as I can with Vaadin :).
You'll need to recompile the widgetset after you've added the add-on as a dependency.
Solution 2: Use com.vaadin.ui.JavaScript
I won't vouch for the portability of this solution but I guess it will work on most modern browsers.
public class MyUI extends UI {
private Window popUp;
#Override
protected void init(VaadinRequest request) {
Button button = new Button("Content button");
VerticalLayout layout = new VerticalLayout(button);
layout.setMargin(true);
popUp = new Window("Pop-up", layout);
popUp.setPositionY(40);
popUp.addStyleName("window-center");
addWindow(popUp);
// Add a JS function that can be called from the client.
JavaScript.getCurrent().addFunction("centerWindow", args -> {
popUp.setPositionX((int) ((args.getNumber(1) - args.getNumber(0)) / 2));
});
// Execute the function now. In real code you might want to execute the function just after the window is displayed, probably in your enter() method.
JavaScript.getCurrent().execute("centerWindow(document.getElementsByClassName('window-center')[0].offsetWidth, window.innerWidth)");
}
}

Disable scroll to focused button

Hi a have two buttons at the bottom of the screen and each time I open this screen, view is scrolled to the bottom to show those focused buttons, is there any method to disable this behaviour and firstly display top of the screen?
You have to add a focusable field to the top of your screen. Its up to you how you want to achieve this, but generally you can put a NullField as the first view of your screen.
The NullField should receive the initial focus for you, but note a user can still scroll back to it as with any other view. So it might look like your focus is "lost" depending on how your design looks.
public class MyScreen extends MainScreen
{
public MyScreen()
{
super(VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
add(new NullField()); // Nullfield to be initially focused
// Screen content with focusable button at the bottom
add(new LabelField("Label"));
ButtonField button = new ButtonField("Button");
button.setMargin(1000, 0, 0, 0);
add(button);
}
}

Bitmap field taking focus on whole screen

I have added 2 BitmapFields(left and right arrow) on one HorizontalFieldManager, but when I click anywhere on HFM, BitmapFields taking focus and shows that it is selected.
I want not to show focus anywhere until it doesn't click on BitmapFields.
Following is the code for it:
bmfBottomRight = new BitmapField(bmpBottomRightFocused, FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
int fieldIndex = getCurrentFieldIndex();
if (fieldIndex < (surveyList.size() - 1))
updateIncrField(fieldIndex);
return super.navigationClick(status, time);
}
};
bmfBottomLeft.setPadding(5, 0, 5, ((Display.getWidth() - bmfBottomRight.getPreferredWidth()) >> 1) - bmfBottomRight.getPreferredWidth());
I am setting Padding for it..
Have added null fields new NullField(Field.NON_FOCUSABLE). And added two different null fields at left and right of bitmap field. SO I am able to getting the focus on bitmapfield, when only tapping on it.

Container is taking event of Button in blackberry

I have a grid container wchich consist two button.and i add this container in the form.
When i click on the button it is working fine but when i click outside the buttons then the event fired by those button which have the focus at that time.
GridFieldManager startStopButtonContainer = new GridFieldManager(2,Field.FIELD_HCENTER);
startStopButtonContainer.add(slideRestart);
startStopButtonContainer.add(slideStop);
add(startStopButtonContainer);
now i click on the slideRestart it works fine but when i click outside the button then also it is taking event.
Please help me out...:)
Add nullfield at starting & ending at each row of the gridfieldManager.And set style Field.Non_FOCASABLE to that nullfields.And set the default focus at buttonfield.
Note: nullfields must cover the remaining part of gridfieldManager.
you can use
LabelField field = new LabelField(" ",Field.NON_FOCUSABLE)
{
protected void layout(int width, int height)
{
// TODO Auto-generated method stub
super.layout(width, height);
setExtent((Display.getWidth()-(buttonField.getPreferredWidth()+buttonField.getPreferredWidth())/2, height);
}
};
as nullfield.

Resources