Hide Keyboard in iOS by using Tabris - ios

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;
}

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.

Click listener on image broken in Vaadin 7

I run this code to make a button then add it to a GridLayout.
private Image makeButton(String text) {
final Image imageButton = new Image(text);
imageButton.setIcon(new ExternalResource("https://cdn2.iconfinder.com/data/icons/ios7-inspired-mac-icon-set/128/_app_store_128.png"));
imageButton.addClickListener(new MouseEvents.ClickListener() {
#Override
public void click(MouseEvents.ClickEvent event) {
Notification.show("Hello World");
}
});
return imageButton;
}
However the click event is never called. Any idea how/why this could happen?
Use setSource() instead of setIcon().

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 change the picture of CustomButtonField on click event?

I have posted this question previously but the answer is not appropiate. The solution provided just change the picture when the custombutton has focus and unfocus. Suppose in my application I need to change the picture if the user clicks on the customButton, n i m doing this by calling the same screen (ie UiApplication.getUiApplication().pushScreen(new Screen2(b));) . Screen2 is the screen which holds the customButton. On the click evevt i m pushing the same screen by passing aint variable pic_status that determines which picture to be drawn in the CustomButton in the new screen. Is there any way to update the picture in the CustomButtonField on click event without pushing the same Screen again and again.
//code in Screen2
public void fieldChanged(Field field, int context)
{
if(field == bf1)
{
if(pic_status == 0)
{
pic_status=1;
}
UiApplication.getUiApplication().pushScreen(new Screen2(pic_status));
}
//code in CustomButtonField
CustomButtonField(String label,int pic_status,long style)
{
super(style);
this.label = label;
this.labelHeight = getFont().getHeight();
this.labelWidth = getFont().getAdvance(label);
this.notice = s;
if(pic_status ==0)
{
currentPicture1 = onPicture;
currentPicture2 = onPicture;
}
if(pic_status ==1)
{
currentPicture1 = clickPicture;
currentPicture2 = onPicture;
}
if( pic_status==2 )
{
currentPicture1 = onPicture;
currentPicture2 = clickPicture;
}
}
I need a way to update the customButtonField text and picture on the buttonClick event not on focus/unfocus event without pushing the same Screen again and again. If my above description of problem is not satisfactory, plz add a comment n i can give more details explanation of my problem?
We can override some methods of the CustomButtonField such as protected boolean keyChar(...), protected boolean navigationClick(...), protected boolean trackwheelClick(...), protected boolean touchEvent(...), etc and use them to change button image when click or select event occurred.
For example on protected boolean touchEvent(...) we can do following task..
Replace the image with desired ones when we get TouchEvent.ClICK.
Call invalidate().
On TouchEvent.UNCLICK restore original image.
Call invalidate().

Connect Blackberry menuitem to onscreen buttons

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);

Resources