Text overlaps the hint in textArea - cn1 - codenameone

There are 2 textArea in my screen with necessary hint texts. If the last textArea is focused, the keyboard appears but instead of typing in it, if the other textArea is focused, the new text overlaps the text hints. I've tested in the textFields also, but here the hint disppears as soon as it is focused. However it is not the case in textArea. P.S I've tested the app in android devices.
Have a look at the video here.
Code:
Label reasonLabel = new Label("Reason* ");
TextArea reasonData = new TextArea();
Container reasonContainer = common.Inputs.inputTextArea(reasonData, "Reason For Ownership Transfer", reasonLabel);
Label remarksLabel = new Label("Remarks ");
TextArea remarksData = new TextArea();
Container remarksContainer = common.Inputs.inputTextArea(remarksData, "Additional Info If Any", remarksLabel);
Container mainContainer = BoxLayout.encloseY(phnNoContainer, emailContainer, BoxLayout.encloseY(reasonContainer), BoxLayout.encloseY(remarksContainer));
add(BorderLayout.CENTER, BoxLayout.encloseY(mainContainer, submitButton));
common.Inputs.inputTextArea method:
public static Container inputTextArea(TextArea textArea, String hint, Label textAreaLabel) {
textArea.setHint(hint);
textArea.setRows(2);
textArea.setGrowByContent(false);
textArea.getHintLabel().setUIID("TextField");
Container remarksContainer = BoxLayout.encloseY(textAreaLabel, textArea);
return remarksContainer;
}

Related

Focus behaviour in textArea in cn1

I have a textArea which works alright. I've a minor issue here. As soon as there is focus in the textArea, there is no text cursor blinking. It seems like the app hangs here. I've to touch the outside of the textArea and click it again to make it work. And when the other component is touched the keypad stays as before. In the second try only does the textArea has blinking text cursor.
Have a look at the video here.
public Booking(Resources res) {
super(new BorderLayout());
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.setScrollableY(true);
Label datePickerIconLabel = new Label(addIcon);
Picker datePicker = new Picker();
datePicker.setUIID("small");
datePicker.setType(Display.PICKER_TYPE_DATE);
Container datePickerContainer = BoxLayout.encloseX(datePickerIconLabel, datePicker);
mainContainer.add(datePickerContainer);
TextArea remarksArea = new TextArea();
remarksArea.setUIID("TextField");
remarksArea.setConstraint(TextField.NON_PREDICTIVE);
remarksArea.setRows(4);
remarksArea.getAllStyles().setAlignment(Label.TOP);
remarksArea.setHint(" Remarks");
remarksArea.getHintLabel().setUIID("TextField");
remarksArea.getAllStyles().setPadding(2, 2, 2, 2);
remarksArea.getHintLabel().getAllStyles().setPadding(2, 2, 2, 2);
mainContainer.add(remarksArea);
add(BorderLayout.CENTER, mainContainer);
}

How to make a SpanButton work when made Lead?

When you make a SpanButton lead for a Container, it doesn't receive the events. I've tried debugging but haven't managed to understand why it doesn't work. It seems to be a CN1 error, but I may have misunderstood something.
Here's a test case to reproduce the issue:
Form hi = new Form("Welcome", BoxLayout.y());
//test case shows that when you make a normal Button lead for a Container,
//it works as expected.
//Doing the same with a SpanButton doesn't work.
//When you click button it correctly hides the Label.
//Clicking spanButton doesn't hide the label.
//
//Test also shows a second issue: when adding a Command to a SpanButton,
//the Command text is shown in parallel with the SpanButton's text
//edit Button works normal
Button button = new Button("Normal Button works");
Label hide2 = new Label("Now you see me, now you don't2");
Command cmd2 = Command.create("CmdTxt2", null, (ev) -> {
hide2.setHidden(!hide2.isHidden());
hi.revalidate();
});
button.setCommand(cmd2);
Label editButtonLabel2 = new Label();
FontImage.setMaterialIcon(editButtonLabel2, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont2 = BorderLayout.centerEastWest(button, editButtonLabel2, null);
cont2.setLeadComponent(button); //for a normal button, the lead works correctly
hi.add(cont2);
hi.add(hide2);
//with SpanButton it doesn't work:
SpanButton spanButton = new SpanButton("SpanButton does not work");
Label hide = new Label("Now you see me, now you don't");
Command cmd = Command.create("CmdText", null, (ev) -> {
hide.setHidden(!hide.isHidden());
hi.revalidate();
});
spanButton.setCommand(cmd);
Label editButtonLabel = new Label();
FontImage.setMaterialIcon(editButtonLabel, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont = BorderLayout.centerEastWest(spanButton, editButtonLabel, null);
cont.setLeadComponent(spanButton); //spanButton made lead for cont, so should receive all events for cont, but doesn't
hi.add(cont);
hi.add(hide);
hi.show();
Could this be due to SpanButton being a container itself and also having a Lead component which is a Button?
You could create a normal Button and apply that command to it, then set the container's lead component to this Button. You don't have to add this Button to the container, add your SpanButton and the container will still receive all the events.
Form hi = new Form("Welcome", BoxLayout.y());
/*test case shows that when you make a normal Button lead for a Container,
it works as expected.
Doing the same with a SpanButton doesn't work.
When you click the button, it correctly hides the Label.
Clicking spanButton doesn't hide the label.
Test also shows a second issue: when adding a Command to a SpanButton,
the Command text is shown in parallel with the SpanButton's text*/
//edit Button works normal
Button button = new Button("Normal Button works");
Label hide2 = new Label("Now you see me, now you don't2");
Command cmd2 = Command.create("CmdTxt2", null, (ev) -> {
hide2.setHidden(!hide2.isHidden());
hi.revalidate();
});
button.setCommand(cmd2);
Label editButtonLabel2 = new Label();
FontImage.setMaterialIcon(editButtonLabel2, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont2 = BorderLayout.centerEastWest(button, editButtonLabel2, null);
cont2.setLeadComponent(button); //for a normal button, the lead works correctly
hi.add(cont2);
hi.add(hide2);
//with SpanButton it doesn't work:
SpanButton spanButton = new SpanButton("SpanButton does not work");
Label hide = new Label("Now you see me, now you don't");
Command cmd = Command.create("CmdText", null, (ev) -> {
hide.setHidden(!hide.isHidden());
hi.revalidate();
});
Button btnHidden = new Button(cmd);
Label editButtonLabel = new Label();
FontImage.setMaterialIcon(editButtonLabel, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont = BorderLayout.centerEastWest(spanButton, editButtonLabel, null);
cont.setLeadComponent(btnHidden); //spanButton made lead for cont, so should receive all events for cont, but doesn't
hi.add(cont);
hi.add(hide);
hi.show();

keyboard issue in iOS - codenameone

I have a addEvent form. Here there are a no. of fields to be filled by user. There are textfields, pickers, textArea etc. When i have focus on the textfield in the top of the form, the keyboard works good. I notice the done button in the keypad is at the bottom of keyboard. But as soon as the textfield or textArea at the bottom of the form get focused, the keyboard with the done button at the top of keyboard is shown. After the done botton is clicked, there is the white blank space at the top of form that i think the height keyboard occupies before.
update 1: descriptionTextArea gives the issue.
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Label eventImage = new Label();
TextField eventNameTextField = new TextField();
Button uploadImg = new Button(theme.getImage("uploadImg.png"));
//uploadImg actionListener code is skipped here
Container eventNameContainer = new Container(new BorderLayout());
Label maxSizeLabel = new Label("Max size 1mb");
Container wrapUploadIconAndMsg = new Container(new BorderLayout());
wrapUploadIconAndMsg.add(BorderLayout.WEST, uploadImg);
wrapUploadIconAndMsg.add(BorderLayout.CENTER, maxSizeLabel);
eventNameContainer.add(BorderLayout.NORTH, (BoxLayout.encloseY(eventImage, wrapUploadIconAndMsg)));
eventNameContainer.add(BorderLayout.CENTER, (eventNameTextField));
Picker startDate = new Picker();
Picker startTime = new Picker();
Container startContainer = GridLayout.encloseIn(2, startDate, startTime);
Label timeIcon = new Label(iconEvent);
Container wrapStartContainer = BoxLayout.encloseX(FlowLayout.encloseCenter(timeIcon), (startContainer));
Label timeIconInvisible = new Label(iconEvent);
timeIconInvisible.setVisible(false);
Picker endDate = new Picker();
Picker endTime = new Picker();
Container endContainer = GridLayout.encloseIn(2, endDate, endTime);
Container wrapEndContainer = BoxLayout.encloseX((timeIconInvisible), FlowLayout.encloseCenterBottom(endContainer));
Label descriptionIcon = new Label();
descriptionIcon.setIcon(iconDescription);
TextArea descriptionTextArea = new TextArea();
descriptionTextArea.setRows(4);
descriptionTextArea.setMaxSize(240);
descriptionTextArea.setVerticalAlignment(Label.TOP);
Container descriptionContainer = new Container(new BorderLayout());
descriptionContainer.add(BorderLayout.WEST, descriptionIcon);
descriptionContainer.add(BorderLayout.CENTER, descriptionTextArea);
Container wrapEventContainer = BoxLayout.encloseY(eventNameContainer, wrapStartContainer, wrapEndContainer, descriptionContainer);
f.add(wrapEventContainer);
f.revalidate();
1)initial form:
2)keyboard with done button at the bottom of keyboard (works fine here) -textfield at top of the form is used.
3)keyboard with done button at the top of keyboard(problem arise after done is touched)
4)the issue after done is pressed. (blank white area is seen) I think its height equals to the height of keyboard

Codenameone validator not highlighting required fields

I have a simple form that performs validation of each field. For some reason, I think related to the CodenameOne theme, I do not get a red outline or background for fields failing validation, and I do not see the error messages. The form will gray out the "Submit" button until all validations pass, so this part is working. I just can't see the errors on the screen. I have included my form code below. Is this happening because the default theme I am using does not have the required UUIDs to display the error styles?
Is there a way to debug when styles are being applied but are not available in the theme?
Form registrationForm = new Form("My Registration");
BorderLayout bl = new BorderLayout();
bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER);
registrationForm.setLayout(bl);
registrationForm.setFormBottomPaddingEditingMode(true);
ComponentGroup cg = new ComponentGroup();
final TextField nicknameField = new TextField("", "Screen name (publicly viewable)", 25, TextArea.ANY);
cg.addComponent(nicknameField);
final TextField emailField = new TextField("", "Email address", 40, TextArea.EMAILADDR);
cg.addComponent(emailField);
final TextField passwordField = new TextField("", "Password", 40, TextArea.PASSWORD);
cg.addComponent(passwordField);
final TextField passwordConfirmField = new TextField("", "Type your password again", 40, TextArea.PASSWORD);
cg.addComponent(passwordConfirmField);
final TextField sloganField = new TextField("", "Slogan (publicly viewable), ex: Go Hokies!", 30, TextArea.ANY);
cg.addComponent(sloganField);
Button submit = new Button("Submit");
Validator v = new Validator();
v.addConstraint(nicknameField, new LengthConstraint(3));
v.addConstraint(emailField, RegexConstraint.validEmail("You must enter a valid email address to receive confirmation"));
v.addConstraint(passwordField, new LengthConstraint(8));
v.addConstraint(passwordConfirmField, new LengthConstraint(8));
v.addSubmitButtons(submit);
submit.addActionListener((e) -> {
String password = passwordField.getText();
String passwordConfirm = passwordConfirmField.getText();
if (!password.equals(passwordConfirm)) {
Dialog.show("Password error", "The password and password confirmation did not match. Please retype them.", "OK", null);
} else {
showConfirmation();
}
});
cg.addComponent(submit);
registrationForm.addComponent(BorderLayout.CENTER, cg);
registrationForm.show();
The error mode sets the UIID to existing UIID with the word "Invalid" appended to it. So a TextField will become TextFieldInvalid.
In the simulator open the Component Inspector tool and traverse the components to see the UIID's that they have. This will allow you to customize the right UIID's in selected/unselected states.
To enable error message display use setShowErrorMessageForFocusedComponent(true).

Removing border from TextArea in CodenameOne causes the component to stop growing to fit text

I want to implement a TextArea in CodenameOne as follows:
private Container getMessageContainer(String message) {
Container con = new Container(new BorderLayout());
TextArea ta = new TextArea();
ta.setGrowByContent(true);
ta.setSingleLineTextArea(false);
ta.setScrollVisible(true);
ta.setUIID("DialogTextArea");
ta.setEditable(false);
ta.setFocusable(false);
ta.setText(message);
con.addComponent(BorderLayout.CENTER, ta);
return con;
}
I then have a Theme Component in the theme.res file called DialogTextArea deriving TextArea, as follows:
This TextArea is then put on a Dialog as follows:
public MessageDialog(NotificationType notificationType, String title, String message,
boolean fallback) {
this.notificationType = notificationType;
this.fallback = fallback;
this.buildTitle(title);
this.setLayout(new BorderLayout());
this.addComponent(BorderLayout.CENTER, getContentConainer(message));
this.addComponent(BorderLayout.SOUTH, getButtonContainer());
}
private Container getContentConainer(String message) {
Container con = new Container(new BorderLayout());
con.addComponent(BorderLayout.CENTER, getMessageContainer(message));
return con;
}
Where MessageDialog extends Dialog.
This does work well, and I get the following results:
And:
However, when I remove the border from the theme in the theme.res, turning it into an Empty border, I get this as a result:
As well as
This does mean there are some inconsistencies when I wish to remove the border.
Is there any way to get the text to always display when I do not want a border? I tried changing the padding and margin properties, but to no avail.
This is all using the Native theme.
Any help would be appreciated.
private Container getMessageContainer(String message) {
Container con = new Container(new BorderLayout());
TextArea ta = new TextArea();
ta.setGrowByContent(true);
ta.setSingleLineTextArea(false);
ta.setScrollVisible(true);
ta.setUIID("DialogTextArea");
ta.setEditable(false);
ta.setFocusable(false);
ta.setText(message);
con.addComponent(BorderLayout.CENTER, ta);
Label transparentLabel = new Label("");
transparentLabel.getAllStyle().setBgColor(0xffffffff);
con.addComponent(BorderLayout.SOUTH, transparentLabel);
return con;
}
This gives a temporary solution.
You need to remove the border from the selected, unselected states as well as the padding from both. If you don't do that we will pick the "most" option and go with that to prevent "jumping" on every focus change.
Note that selected state is still applicable even if you selected the component to not have focus or editability.

Resources