Component not showing when swipeable container is swiped using code - codenameone

I have a swipeable container with a button exposed when you swipe it.
It works when you use your mouse to swipe, but it doesnt seem to work when
you use code to perform the same action.
Form hi = new Form(new BoxLayout(BoxLayout.Y_AXIS));
Container multiButtonCont = new Container(new BoxLayout(BoxLayout.Y_AXIS));
MultiButton mButton = new MultiButton();
mButton.setTextLine1("mButton 1");
Button testB1 = new Button("TestButton1");
SwipeableContainer swipe = new SwipeableContainer(testB1,mButton);
multiButtonCont.addComponent(swipe);
Button openButton = new Button("Open");
openButton.addActionListener(e->{
for(int i=0;i<multiButtonCont.getComponentCount();i++){
((SwipeableContainer) (multiButtonCont.getComponentAt(i))).openToRight();
}
});
Button closeButton = new Button("Close");
closeButton.addActionListener(e->{
for(int i=0;i<multiButtonCont.getComponentCount();i++){
((SwipeableContainer) (multiButtonCont.getComponentAt(i))).close();
}
});
hi.addComponent(GridLayout.encloseIn(2, openButton, closeButton));
hi.addComponent(multiButtonCont);
hi.show();
Any ideas on how to implement opening a swipeable container using code?

Thanks for the code, it seems to be a regression in the component. I've fixed it and it should be available for the coming update which is on October 7th 2016

Related

I get an Exception when I try to open a side menu

I'm trying to develop a side menu with a sliding home screen.
This is what I did.
set hideLeftSideMenuBool to true in constants and using menuBtn to openSideMenu,
I get this:
java.lang.NullPointerException
at com.codename1.ui.Toolbar.showOnTopSidemenuImpl(Toolbar.java:1616)
at com.codename1.ui.Toolbar$12.run(Toolbar.java:1567)
at com.codename1.ui.AnimationManager.flushAnimation(AnimationManager.java:220)
at com.codename1.ui.Toolbar.showOnTopSidemenu(Toolbar.java:1563)
at com.codename1.ui.Toolbar.openSideMenu(Toolbar.java:343)
..................
Form hi = new Form("Hi World");
hi.setAllowEnableLayoutOnPaint(true);
Toolbar tb = new Toolbar(false);
final Container ToolbarCnt = new Container(new BorderLayout());
Container menuCnt = new Container(new FlowLayout(CENTER, CENTER));
Button menuBtn = new Button(theme.getImage("ToolbarSideMenuIcon.png"),"Container");
menuCnt.add(menuBtn);
ToolbarCnt.add(BorderLayout.WEST, menuCnt);
ToolbarCnt.getAllStyles().setMarginUnit(Style.UNIT_TYPE_SCREEN_PERCENTAGE);
ToolbarCnt.getAllStyles().setMargin(1, 1, 2, 2);
Command MenuCommand = new Command("");
Button HomeCommand= new Button("Home");
HomeCommand.getAllStyles().setFgColor(0xA6A6A6);
HomeCommand.addActionListener((evt) -> {
SideMenuBar.closeCurrentMenu();
});
Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
cnt.add(HomeCommand);
hi.setToolbar(tb);
tb.setTitleCentered(false);
tb.setTitleComponent(ToolbarCnt);
MenuCommand.putClientProperty("SideComponent", cnt);
hi.addCommand(MenuCommand);
menuBtn.addActionListener((evt) -> {
hi.getToolbar().openSideMenu();
});
Thanks in advance for the support.
The menu is constructed when things are added to it and since you didn't add anything into the menu it was never constructed. Just add items to the menu e.g.:
tb.addMaterialCommandToLeftSideMenu("Hello", materialIcon, e -> {});

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

setHidden is not working codenameone

I used setHidden(true) and it doesnt work. The container and its components are visible if setHidden is used instead of setVisible. Moreover the problem I am getting while using setVisible is that the background of the container just pop up after the components inside the container animates from top. How can I make the background of the container move frm top along with its components.
questionAnswerContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
titleDialog = new Label("Yuppie!");
titleDialog.setUIID("GameDialogLabelBold");
body1 = new Label("Let’s celebrate");
body2 = new Label("with another");
body3 = new Label("drink");
Button ok = new Button(theme.getImage("playIcon.png"));
dialogContainer = (BoxLayout.encloseY(titleDialog, body1, body2, body3, ok));
dialogContainer.getAllStyles().setBgImage(theme.getImage("yuppieDialog.png"));
dialogContainer.setPreferredW(screenWidth * 2 / 3);
dialogContainer.setPreferredH(screenWidth * 2 / 3);
add(BorderLayout.CENTER, LayeredLayout.encloseIn(questionAnswerContainer, FlowLayout.encloseCenterMiddle(dialogContainer)));
dialogContainer.getParent().setVisible(false);
// dialogContainer.setHidden(true); //it doesnot work, the container and its components are visible if setHidden is used instead of setVisible
f.revalidate();
public void checkIfCorrect(Button checkBtn, Form f) {
dialogContainer.getParent().setY(-Display.getInstance().getDisplayHeight());
dialogContainer.getParent().setVisible(true);
// dialogContainer.getParent().setHidden(false);
}
Give a try to f.invalidate(); as well.
For me, sometimes combination of both invalidate and revalidate works.

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

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