Connect Blackberry menuitem to onscreen buttons - blackberry

I have requirement for having onscreen navigation buttons along with menu items on blackberry. I need to generate menu item commands as onscreen buttons. Is there a way to generate onscreen menu item buttons in Blackberry? i.e On each screen of my application the menu items should be populated as onscreen buttons both having same functionality?
Thank you

The easiest way to accomplish what you're trying to do is write one function then have both the button and the menu item use the same function.
For example:
function doSomething() {
// Your Code Here
}
// In the function building your screen
MenuItem somethingMi = new MenuItem() {
private MenuItem() { super("Do Something",100001, 5); }
public void run() { doSomething() };
}
Button somethingBtn = new ButtonField("Do Something");
somethingBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context){
doSomething();
}
}
addMenuItem(somethingMI);
add(somethingBtn);

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.

Hide Keyboard in iOS by using Tabris

is there an option to remove the keyboard from screen on iOS ? I use Tabris (http://developer.eclipsesource.com/tabris/) and Java in this context.
My problem is that i use two textfields to enter a user/passwort combination. After I filled these textfields and press a button to continue the keyboard from iOS is always shown but I want that the keyboard no longer appears. Only after I click somewhere then the keyboard disappears.
On Tabris, you can "open" the keyboard programmatically by setting the Focus on a Control which uses the keyboard (like org.eclipse.swt.widgets.Text ).
To hide the keyboard, just set the Focus to a Control which does not require a keyboard, like the parent composite of your Textfield.
In your case I would add al line to the SelectionListener of your Button to set Focus on the Parent of your Textfields, then start the Login procedure.
Here is some code to play and understand the Focus mechanism:
public class FocusTest implements EntryPoint {
public int createUI() {
Display display = new Display();
Shell shell = new Shell(display, SWT.NO_TRIM);
shell.setMaximized(true);
GridLayoutFactory.fillDefaults().applyTo(shell);
createContent(shell);
shell.open();
//while (!shell.isDisposed()) {
// if (!display.readAndDispatch()) {
// display.sleep();
// }
//}
return 0;
}
private void createContent(final Composite parent) {
Button buttonSingleText = new Button(parent, SWT.PUSH);
buttonSingleText.setText("Focus on SingleText");
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(buttonSingleText);
Button buttonMultiText = new Button(parent, SWT.PUSH);
buttonMultiText.setText("Focus on MultiText");
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(buttonMultiText);
Button buttonNoFocus = new Button(parent, SWT.PUSH);
buttonNoFocus.setText("Loose Focus");
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(buttonNoFocus);
final Text singleText = new Text(parent, SWT.SINGLE);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(singleText);
final Text multiText = new Text(parent, SWT.MULTI);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(multiText);
buttonSingleText.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
singleText.setFocus();
}
});
buttonMultiText.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
multiText.setFocus();
}
});
buttonNoFocus.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
parent.setFocus();
}
});
}
}
Did you set UITextField delegate and add the following method there?
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}

Add field manager to application Main screen in BlackBerry

I am working with a BlackBerry application for OS 5.0 and later. The application has one screen which displays at the top of screen a Next and a Previous button. and list field also display in this screen at bottom of these both button
When i click on NEXT Button and Previous Button my List will be updated display data..
When i click on NEXT/PREVIOUS Button i have to display small VerticalfieldManager at the center of the screen with Label "Please wait ..." so after design this screen how can we add more field manager in over the another manager ?
Is there any way to display that Field at the application MainScreen like iPhone AppDelegate screen?
btnState.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{ vfm_Middle.add(lblPleasewait);
popup = new PopupScreen(manager);
Thread thread = new Thread()
{
public void run()
{
try
{
Updatelistfield();
stop();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
super.run();
}
public synchronized void stop()
{
// TODO Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// TODO Auto-generated method stub
//popup.delete(vfm_Main);
//popup.deleteAll();
//vfm_Main.delete(lblPleasewait);
//lblPleasewait.setText(null);
}
});
}
};
thread.start();
}
});
The proper way of doing that is with a blocking dialog. In BB API this can be done as follows:
VerticalFieldManager manager = new VerticalFieldManager();
manager.add(new LabelField("Please Wait..."));
Screen popup = new PopupScreen(manager);
//Show the pop-up the same way you push a regular screen
This has the advantage of blocking the GUI: if the user pushes the menu or esc key it doesn't have any effect.
If you want to do it in your screen without dialogs, then you can add an empty VerticalFieldManager which you can fill with a label when the message has to be shown. This way, instead of updating the entire screen, only the Manager is refreshed. But then you should write the logic to not letting the user push any button or menu key (or ignoring key press).

blackberry react to menuitem

I started writing a bb app with a menu.
My problem is I don't know how to react if the selected item is clicked. The menu contains some fields in a VerticalFieldManager that is added in a class that extends MainScreen.
I'm sorry for asking such basic stuff, but i googled 1.5 hours now and didnt find a solution or example, Its my very first blackberry app.
Here you go.
This snippet of code defines a new menu item, with a constructor where you specify the label of the menu item and its position on the menu, and a run method which is called when the user clicks on your menu item.
The run method is called on the UI (event) thread, so you are free to update your user interface components from here, or do whatever else you need to do.
I also included a snippet of a screen class that adds the menu item to its menu.
final class MyMenuItem extends MenuItem
{
MyMenuItem()
{
super("Menu item text", 100000, 0);
}
public void run()
{
// The user has clicked on the menu item, and
// this method was called. Do what you need to do.
}
}
final class MyScreen extends MainScreen
{
// ...
protected void makeMenu ( Menu menu, int instance )
{
// let the system build a default menu first
super.makeMenu(menu, instance);
// add your menu item to the screen
menu.add ( new MyMenuItem() );
}
// ...
}

Blackberry screen navigation

I want to know how to go from one screen to another by clicking a button that I have added to a MainScreen. I mean just like we do in the Android onClick event for a button - start another startActivity.
In the event handler for the button click, just "push" the screen that you want to appear next, and it will be pushed to the top of the screen stack. For example:
UiApplication.getUiApplication().pushScreen(nextScreen);
This will be better, using FieldChangeListener
button.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
UiApplication.getUiApplication().pushScreen(new NextScreen());
}
});
This is the alternative way than using,
UiApplication.getUiApplication.involeLater()
{};

Resources