codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.71k stars 405 forks source link

UWP setDoneListener does not work #2018

Closed mwarnett closed 7 years ago

mwarnett commented 7 years ago

Sample code provided.

Run on Android Focus text field Enter Text Hit Done button Keyboard closes Search is performed.

Expect same behavior on Windows, but nothing happens when done button hit

Run on Windows Focus text field Enter Text Hit Done button Nothing happens, keyboard still displayed, no search performed.

Sample code

`package com.mycompany.myapp;

import com.codename1.components.InfiniteProgress; import com.codename1.components.ToastBar; import com.codename1.components.WebBrowser; import com.codename1.ui.AutoCompleteTextField; import com.codename1.ui.Button; import com.codename1.ui.ComboBox; import com.codename1.ui.Display; import com.codename1.ui.Form; import com.codename1.ui.Dialog; import com.codename1.ui.FontImage; import com.codename1.ui.Label; import com.codename1.ui.spinner.Picker; import com.codename1.ui.plaf.UIManager; import com.codename1.ui.util.Resources; import com.codename1.io.Log; import com.codename1.ui.Command; import com.codename1.ui.Component; import com.codename1.ui.Container; import com.codename1.ui.TextField; import com.codename1.ui.Toolbar; import com.codename1.ui.events.ActionEvent; import com.codename1.ui.events.ActionListener; import com.codename1.ui.layouts.BorderLayout; import com.codename1.ui.layouts.FlowLayout; import com.codename1.ui.layouts.GridBagConstraints; import com.codename1.ui.layouts.GridBagLayout; import com.codename1.ui.layouts.Insets; import com.codename1.ui.plaf.Style; import java.io.IOException; import java.util.Vector;

/** This file was generated by Codename One for the purpose

of building native mobile applications using Java. */ public class MyApplication implements ActionListener {

private Form current;
private Resources theme;
private Command _backCommand;
private ComboBox _searchBy;
private TextField _searchFor;
private Button _searchForRedo;
private ComboBox _sortBy;
private InfiniteProgress _progress;
private Label _statusMessage;
private Command _searchCommand;
private Command _scanCommand;

public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");

 // Enable Toolbar on all Forms by default
 Toolbar.setGlobalToolbar(true);

 // Pro only feature, uncomment if you have a pro subscription
 // Log.bindCrashProtection(true);

}

public void start() {
if(current != null){
current.show();
return;
}

 Form searchForm = new Form("Sample App");

 // Allow scrolling if screen too small or rotated
 searchForm.setScrollableY(true);
 searchForm.setScrollVisible(true);

 searchForm.addCommandListener(this);

 _backCommand = new Command("Back");
 searchForm.setBackCommand(_backCommand);

 GridBagLayout gbl = new GridBagLayout();
 GridBagConstraints gbc = new GridBagConstraints();
 searchForm.setLayout(gbl);

 int y = 0;
 int x = 0;
 Label searchFor = new Label("Search For:");

 gbc.anchor        = GridBagConstraints.SOUTHWEST;
 gbc.gridx         = x;
 gbc.gridy         = y;
 gbc.gridwidth     = 1;
 gbc.gridheight    = 1;
 gbc.fill          = GridBagConstraints.BOTH;
 gbc.weightx       = 0.0;
 gbc.weighty       = 0.0;
 gbc.insets        = new Insets(0, 5, 10, 0);
 gbl.setConstraints(searchFor, gbc);
 searchForm.addComponent(searchFor);

 x++;
 _searchFor = new TextField();
 _searchFor.setColumns(8);
 _searchFor.setInputMode("abc");
 _searchFor.setConstraint(TextField.ANY | TextField.NON_PREDICTIVE);
 _searchFor.setDoneListener(this);
 _searchFor.putClientProperty("searchField", true);

 gbc.anchor        = GridBagConstraints.SOUTHWEST;
 gbc.gridx         = x;
 gbc.gridy         = y;
 gbc.gridwidth     = 1;
 gbc.gridheight    = 1;
 gbc.fill          = GridBagConstraints.HORIZONTAL;
 gbc.weightx       = 0.1;
 gbc.weighty       = 0.0;
 gbc.insets        = new Insets(0, 5, 10, 5);
 gbl.setConstraints(_searchFor, gbc);
 searchForm.addComponent(_searchFor);

 y++;
 x = 0;
 _statusMessage = new Label(" ");
 _statusMessage.setPreferredW(500);
 Style style = _statusMessage.getStyle();
 style.setAlignment(Component.CENTER);
 gbc.anchor        = GridBagConstraints.NORTHWEST;
 gbc.gridx         = x;
 gbc.gridy         = y;
 gbc.gridwidth     = GridBagConstraints.REMAINDER;
 gbc.gridheight    = 1;
 gbc.fill          = GridBagConstraints.HORIZONTAL;
 gbc.weightx       = 0.0;
 gbc.weighty       = 0.0;
 gbc.insets        = new Insets(0, 10, 0, 10);
 gbl.setConstraints(_statusMessage, gbc);
 searchForm.addComponent(_statusMessage);

 y++;
 x = 0;
 Container buttons = new Container();
 buttons.setLayout(new FlowLayout(Component.CENTER));
 _searchCommand = new Command("Search");
 Button searchButton = new Button(_searchCommand);
 buttons.addComponent(searchButton);

 gbc.anchor        = GridBagConstraints.NORTHWEST;
 gbc.gridx         = x;
 gbc.gridy         = y;
 gbc.gridwidth     = GridBagConstraints.REMAINDER;
 gbc.gridheight    = 1;
 gbc.fill          = GridBagConstraints.HORIZONTAL;
 gbc.weightx       = 0.0;
 gbc.weighty       = 0.0;
 gbc.insets        = new Insets(0, 10, 10, 10);
 gbl.setConstraints(buttons, gbc);
 searchForm.addComponent(buttons);

 y++;
 x = 0;
 Label filler = new Label();

 gbc.anchor        = GridBagConstraints.NORTHWEST;
 gbc.gridx         = x;
 gbc.gridy         = y;
 gbc.gridwidth     = 1;
 gbc.gridheight    = 1;
 gbc.fill          = GridBagConstraints.VERTICAL;
 gbc.weightx       = 0.0;
 gbc.weighty       = 0.1;
 gbc.insets        = new Insets(0, 0, 0, 0);
 gbl.setConstraints(filler, gbc);
 searchForm.addComponent(filler);

 searchForm.show();

}

public void stop() {
current = Display.getInstance().getCurrent();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = Display.getInstance().getCurrent();
}
}

public void destroy() {
}

public void actionPerformed(ActionEvent actionEvent) {
Command command = actionEvent.getCommand();

 if (command == _backCommand) {
     stop();
     Display.getInstance().exitApplication();
     return;
 }
 else if (command == _searchCommand) {
     _statusMessage.setText("Searched for: " + _searchFor.getText());
     return;
 }

    Object source = actionEvent.getSource();

    if (source == _searchFor) {
        _statusMessage.setText("Searched for: " + _searchFor.getText());
        return;
    }
}

} `

shannah commented 7 years ago

Fixed, but apparently now in some cases it sends 2 events: https://github.com/codenameone/CodenameOne/issues/2062