Blackberry PopupScreen size limited by virtual keyboard - blackberry

I am trying to display a Custom PopupScreen and when the virtual keyboard is being displayed it reduces the size of the popup. I know when you for example, select new message you get a PopupScreen that allows you to select message type (sms, email, etc) and it shows on top of the virtual keyboard. Here is my code am I missing something? I can't find a z-index or something similar...
public class InsertApplicationMenuItem extends ApplicationMenuItem {
public Object run(Object context) {
InsertWhatScreen screen = new InsertWhatScreen();
UiApplication.getUiApplication().pushModalScreen(screen);
return context;
}
}
public class InsertWhatScreen extends PopupScreen {
public InsertWhatScreen() {
super(new VerticalFieldManager(), FOCUSABLE);
}
}
alt text http://dl.dropbox.com/u/2645315/2010-01-20%2015%2017%2023.png
Thanks for the help.

There's no way to put anything on top of the virtual keyboard from a third-party app. If you read the display height while the virtual keyboard is showing, you'll see that the device actually shrinks the "screen size" given to your app while the keyboard is showing.

Related

Expanding a component in a PopupView - Vaadin

I am using Vaadin 8.5.1 with the Vaading Desiin combination with Spring Boot 2.0.4.
Currently I am trying to add a PopupView at the bottom of the page which opens on button click. In the Popup there is a vertical layout including two components: a HorizontalSplitPanel and a Button. The PopupView should have the width of the current BrowserWindow and one third of the height.
The HorizontalSplitPanel should use all the space in the popup, which is not needed for the button.
What I did:
#SpringComponent
#UIScope
public class View extends VerticalLayout implements Observer {
private final PopupContentView popupContentView;
private PopupView popup;
#Autowired
public View(PopupContentView popupContentView) {
this.popupContentView = popupContentView;
}
#PostConstruct
void init() {
button.addClickListener(clickEvent -> openPopup());
}
private void openPopup() {
if (popup == null) {
setSizeOfPopUp();
// popup will adjust automatically to size of content
popup = new PopupView(null, popupContentView);
popup.addPopupVisibilityListener(event -> {
if (event.isPopupVisible()) {
popupContentView.build(this::submitted);
}
});
popup.setHideOnMouseOut(false);
this.addComponent(popup);
}
popup.setPopupVisible(true);
}
private void setSizeOfPopUp() {
if (popupContentView != null) {
popupContentView.setWidth(Page.getCurrent().getBrowserWindowWidth(), Unit.PIXELS);
popupContentView.setHeight(((float) Page.getCurrent().getBrowserWindowHeight()) / 3, Unit.PIXELS);
}
}
private void submitted() {
// do some stuff
}
#Override
public void update(Observable observable, Object o) {
if (observable instanceof BrowserWindowResizeListenerObservable) {
setSizeOfPopUp();
}
}
}
#Service
public class BrowserWindowResizeListenerObservable extends Observable implements Page.BrowserWindowResizeListener {
#Override
public void browserWindowResized(Page.BrowserWindowResizeEvent browserWindowResizeEvent) {
this.setChanged();
this.notifyObservers();
}
}
#SpringComponent
#UIScope
public class PopupContentView extends VerticalLayout {
private SubmitCallback submitCallback;
private Button submitBtn;
#PostConstruct
void init() {
super.init();
}
void build(#NotNull SubmitCallback) {
removeAllComponents();
this.addComponent(horizontalSplitPanel);
this.addComponent(submitBtn);
this.setExpandRatio(horizontalSplitPanel, 1.0f);
this.submitCallback = callback;
}
private void submit() {
submitCallback.submit(someContent);
}
#FunctionalInterface
public interface SubmitCallback {
void submit(SomeContent someContent);
}
}
As you can see, I have a main view, a view for the content and a listener class.
What I want to happen is that the popup is visible on button click and contains the content view with the panel and the submit button. The panel takes the rest of the space, which is not needed for the button. and the popup is fully filled with content.
What actually happens is that the panel takes the full space of the popup and the button will be shown below the popup.
However, when I resize the window and the resizing event gets fired, everything is fine and the button is no longer below the popup.
It seems to be that the padding and the margin (which are the HTML implementation of the expand ratio in Vaadin) are calculated at an earlier stage and get triggered again when resizing the window. However, I have no clue when and what I need to do, to trigger it.
Does anyone have an idea, how can fix this?
EDIT:
When I have a Tree component or a DateField component in the PopupView and then expand a tree element or change the value of the DateField by selecting a value from the Date popup, the resizing is done correctly and everything is fine.
I think in your case the method of checking Browser window size and calculating target pixel size is too complex for your case. I would recommend just to set the width of the popup to be 100% and height to be 33%, like component.setHeight("33%"), yes you can use percentages for width and height instead of pixels. Then sizing is done by CSS, and it will react faster to browser window sizing without server round trip.

A ButtonField to be displayed on all the screens of blackberry

I am working on a blackberry app where one of the requirements is that a ButtonField has to be displayed on all the screens of the app? How can this be accomplished, since the ButtonField has to be added after 2-3 controls?
Toolbar
Logo
ButtonField (All the screens should have this button)
There are many, many ways to solve this problem. Without seeing a visual description of all your screens, it's a little difficult to know exactly which one will work best for you. But, here's one option:
Create a base class that extends MainScreen, and have that base class add the ButtonField, and make sure that all other fields are added above the buttonfield. You can do this by adding the button field in a footer, that is then aligned with the screen's bottom edge using MainScreen#setStatus(Field).
public class BaseScreen extends MainScreen {
private ButtonField _bottomButton;
/** Can only be called by screen subclasses */
protected BaseScreen() {
// call BaseScreen(long)
this(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
}
protected BaseScreen(long style) {
super(style);
_bottomButton = new ButtonField("Press Me!", ButtonField.CONSUME_CLICK | Field.FIELD_HCENTER);
// TODO: customize your button here ...
Manager footer = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
// just use a vertical field manager to center the bottom button horizontally
Manager spacerVfm = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_HCENTER);
spacerVfm.add(_bottomButton);
footer.add(spacerVfm);
setStatus(footer);
}
/** #return the bottom button, if any subclasses need to access it */
protected ButtonField getBottomButton() {
return _bottomButton;
}
}
Here is then an example of how you'll build all your other screens:
public class BaseTestScreen extends BaseScreen implements FieldChangeListener {
public BaseTestScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
HorizontalFieldManager toolbar = new HorizontalFieldManager();
toolbar.add(new ButtonField("One", ButtonField.CONSUME_CLICK));
toolbar.add(new ButtonField("Two", ButtonField.CONSUME_CLICK));
toolbar.add(new ButtonField("Three", ButtonField.CONSUME_CLICK));
add(toolbar);
BitmapField logo = new BitmapField(Bitmap.getBitmapResource("icon.png"));
add(logo);
// do this if you want each different screen to be able to handle the
// bottom button click event. not necessary ... you can choose to
// handle the click in the BaseScreen class itself.
getBottomButton().setChangeListener(this);
}
public void fieldChanged(Field field, int context) {
if (field == getBottomButton()) {
Dialog.alert("Button Clicked!");
}
}
}
As you can see, this makes it possible to handle the button click (differently) in each screen class you create. Or, you can choose to handle the clicks in the base class (BaseScreen). You'll have to decide which makes sense for you. If the same action is always taken when clicking the button, and the base screen doesn't need additional information to handle the click, then just handle the click in BaseScreen. If not, handle in the subclasses as I show.
P.S. One disadvantage of this approach is that it forces all your screen classes to extend a common base class (BaseScreen). In some situations, this can be limiting. However, on BlackBerry, it's not uncommon to have all your screens extend MainScreen anyway. That said, such an architectural decision is impossible for me to comment on without understanding more about your app.

BlackBerry java detecting screen foreground event

In my BlackBerry application, I have a home screen. The user can then navigate to a settings screen. When the user goes back to the home screen, is there no method that is called on the home screen indicating that the screen has come to the foreground?
I have tried onFocus() with no avail.
Thanks!
Unfortunately, hooking on the onExposed is not enough. I found that in Blackberry dialogs are also screens and even context menus are screens too. They are pushed on top of your screen so you receive onExposed callback when they are dismissed.
Though it's OK in many cases, in other cases it poses a problem - e.g. if I must refresh the screen's content only when the user returns to it, but not after menus/dialogs, then how do I do that? My case is, unfortunately, one of those.
I found no documented way of detecting "covered"/"uncovered" events. Here is my approach. onCovered/onUncovered callbacks are called when the current screen is covered/uncovered by another screen of the app, but not by dialogs/menus/virtual keyboard:
public class MyAppScreen extends MainScreen {
private boolean isCovered;
protected void onExposed() {
Log.d("onExposed");
super.onExposed();
if (isCovered) {
onUncovered();
isCovered = false;
}
}
protected void onObscured() {
Log.d("onObscured");
super.onObscured();
final Screen above = getScreenAbove();
if (above != null) {
if (isMyAppScreen(above)) {
isCovered = true;
onCovered();
}
}
}
private boolean isMyAppScreen(final Screen above) {
return (above instanceof MyAppScreen);
}
protected void onUncovered() {
Log.d("onUncovered");
}
protected void onCovered() {
Log.d("onCovered");
}
protected void onUiEngineAttached(final boolean attached) {
if (attached) {
Log.d("UI Engine ATTACHED");
} else {
Log.d("UI Engine DETACHED");
}
super.onUiEngineAttached(attached);
}
protected void onFocusNotify(final boolean focus) {
if(focus){
Log.d("focus GAINED");
} else {
Log.d("focus LOST");
}
super.onFocusNotify(focus);
}
}
And a test. Try various combinations and see what events you receive in the log.
public class TestLifecycle extends MyAppScreen implements FieldChangeListener {
private final ABNTextEdit txt1;
private final ButtonField btn1;
private final ButtonField btn2;
public TestLifecycle() {
final Manager manager = getMainManager();
txt1 = new ABNTextEdit();
manager.add(txt1);
btn1 = new ButtonField("Dialog", ButtonField.CONSUME_CLICK);
btn1.setChangeListener(this);
manager.add(btn1);
btn2 = new ButtonField("Screen", ButtonField.CONSUME_CLICK);
btn2.setChangeListener(this);
manager.add(btn2);
}
public void fieldChanged(final Field field, final int context) {
if (field == btn1) {
Dialog.alert("Example alert");
} else if (field == btn2) {
UiApplication.getUiApplication().pushScreen(new TestLifecycle());
}
}
}
Update:
This method has a limitation: if a new screen is pushed when a dialog or the soft keyboard has focus your current screen will not receive onCovered/onUncovered notification.
Example A: if you have an input field of fixed size and you push a new screen when the user completes it, your current screen will not receive the notification if the user types very quickly. This happens because in the moment between you call push(newScreen) and it is actually pushed the user clicks on a letter on soft KB and it grabs the focus. So only onObscured is called, but not onCovered.
Solution: explicitly hide the soft keyboard before the push(newScreen).
Example B: if you have a customized dialog which pushes new screen and then dismisses itself, your current screen will not receive the notification. This happens because your customized dialog is not recognized as a screen, so only onObscured is called, but not onCovered.
Solution: dismiss the dialog in the first place returning a result value, and let your screen push the new screen based on that value. -OR- override isMyAppScreen() to return true also for your customized dialog.
You should be able to use protected void onExposed() to detect when it is displayed again.

How to add Click Event to BitmapField (fieldchangeListener)?

I'm working on adding a BitmapField to my Blackberry project.
I implemented my class with a FieldChangeListener and added the FieldChangeListener method to my class. I even added a setChangeListener to that particular Bitmap Field, but it's not responding to click events.
How do I fix this?
First, BitmapField is not focusable by default, so you'll need to subclass and override isFocusable to fix that. Then override navigationclick to fire a fieldChanged event. Code snippet for a minimum field:
import net.rim.device.api.ui.component.BitmapField;
public class ClickableBitmapField extends BitmapField {
public boolean isFocusable() {
return true;
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
}
In addition to this, you may want to provide some indication of when your field is in focus (unless you only care about touch-screen devices). The default implementation will just draw a highlight on any transparent areas of your bitmap. You can change this by overriding drawFocus, and maybe onFocus and onUnfocus to change the bitmap you display when the focus state changes.

Consuming all touchEvents not preventing scrolling on the blackberry storm

I am trying to make a custom control for the BlackBerry Storm using SDK v5.0.
This control needs to disable scrolling while the user is dragging elements within a field. The problem is that even if I my control consumes every single touch event send to it, when the user lifts their finger off the screen it still flings up or down as if its finishing a scroll action.
Does anyone know of a way to prevent this from happening or what I might be doing wrong ?
Thank you.
I guess I should have posted this earlier.
There seems to be a bug in the MainScreen class which prevents setScrollingInertial(false) from having any effect. To get around this issue and solve the problem I did the folloing:
public static void main(String[] args)
{
MainScreen ms = new MainScreen(NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL);
VerticalFieldManager vfm = VerticalFieldManager()
{
public VerticalFieldManager()
{
super(HORIZONTAL_SCROLL | VERTICAL_SCROLL);
setScrollingInertial(true);
}
protected boolean touchEvent(TouchEvent message)
{
int code = message.getEvent();
boolean result = super.touchEvent(message);
if(code == TouchEvent.DOWN)
{
setScrollingInertial(!result);
}
return result;
}
};
ms.add(vfm);
}
I have had problem with moving the finger off the screen and I can't say I found a solution for that. On the other hand, have you tried changing the scrolling property of the manager or the screen (or the screen itself) with NO_SCROLL?

Resources