Using SwipableContainer under Tabs - codenameone

This creates a SwipeableContainer inside a Tab, but the swipe gesture is always detected by both the SwipeableContainer and the Tab (i.e. It shows the button under SwipeableContainer and move the page back to the left tab simultaneously when my finger swipes from left to right), which makes it very difficult to press the button behind it.
Is there any way to detect the gesture on SwipeableContainer only?
Tabs main_tab = new Tabs();
Container query_container;
Container history_container;
history_container = new Container(new BoxLayout(BoxLayout.Y_AXIS));
MultiButton his_btn = new MultiButton("History");
Button delete_btn = new Button("delete");
SwipeableContainer his_list_container = new SwipeableContainer(delete_btn,his_btn);
history_container.add(his_list_container);
main_tab.addTab("query", query_icon, query_container);
main_tab.addTab("history", history_icon, history_container);

I think that you can just remove the Swipe Gesture for the Tabs using the following method:
main_tab_.setSwipeActivated(false);
From the codenameone documentation:
public void setSwipeActivated(boolean swipeActivated)
Setter method for swipe mode

Related

Why does my Side menu snaps back when i lift my finger, when swiping in my CN1 app?

In my Codenameone app i have built a side menu, but i have 2 cosmetic issues with it.
When i swipe from the left and i lift my finger in the screen space, slightly further than the menu finishes, the menu snaps back. It doesn't snap back if i lift my finger in the space the menu will expand to. Is there a way to make the side menu stay on the screen when i swipe?
My main page has a vertically scrollable container. When i open the side menu, it doesn't disable my main page so i am still able to scroll my main page container by moving my finger on the space to the right of the menu. Are we able to disable the main page content by default when the menu is open?
For ref, my menu is along the design of this tutorial, with a very simple example being:
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
hi.add(new Label("Hi World"));
Toolbar t = new Toolbar();
hi.setToolbar(t);
t.setTitle("Title");
Label logoLabel = new Label("");
logoLabel.setTextPosition(Label.BOTTOM);
logoLabel.setText("label text here");
t.addComponentToSideMenu(logoLabel);
hi.show();
}
Thanks
The point of closing back seems to be hardcoded to a quarter of the screen here: https://github.com/codenameone/CodenameOne/blob/master/CodenameOne/src/com/codename1/ui/Toolbar.java#L1380
There might be other points in the code that implement this logic. It might be possible to change that to make that logic configurable via theme constants. But right now this is hard coded.

Swiping form using SwipeBacksupport turns entire screen white

While swiping a form, the growing left part of the screen is just white until the swiping is done, when the "back-to" form finally is painted. Is this by design? I expected the "back-to" form either to be gradually revealed, or to slide in from the left.
On iOS and Android, the form being swiped also seems to turn white, so the whole screen is white until the swiping is over. This is not the case with the simulator, however, where you can see the form until it's swiped all the way out.
Code to reproduce the behaviour:
Form redForm = new Form("Red Form");
redForm.getAllStyles().setBgColor(0xff0000);
Button btnToBlueForm = new Button("Go to blue form");
redForm.add(btnToBlueForm);
Form blueForm = new Form("Blue Form");
blueForm.getAllStyles().setBgColor(0x0000ff);
LazyValue<Form> lazyRedForm = (Object... args) -> redForm;
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
btnToBlueForm.addActionListener((ActionListener<ActionEvent>) (ActionEvent evt) -> {
blueForm.show();
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
});
redForm.show();
Press the button in the red form. The blue form now appears. Swipe back and observe the effects.
That's because of the SlideFade mode in the transition. If you switch it to Slide it should work as expected with the background. Here's a version of your code that works as you would expect by applying the style to the content pane:
Form redForm = new Form("Red Form");
redForm.getContentPane().getAllStyles().setBgColor(0xff0000);
redForm.getContentPane().getAllStyles().setBgTransparency(255);
Button btnToBlueForm = new Button("Go to blue form");
redForm.add(btnToBlueForm);
Form blueForm = new Form("Blue Form");
blueForm.getContentPane().getAllStyles().setBgColor(0x0000ff);
blueForm.getContentPane().getAllStyles().setBgTransparency(255);
LazyValue<Form> lazyRedForm = (Object... args) -> redForm;
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
btnToBlueForm.addActionListener((ActionListener<ActionEvent>) (ActionEvent evt) -> {
blueForm.show();
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
});
redForm.show();
The reason this works as opposed to the original code is that SlideFade is two separate transitions one moving/fading the title and the other sliding the content pane alone. Since the content pane is transparent the background isn't painted as we assume it's the form background. By setting the content pane color/opacity we get the exact same effect at a layer the SlideFade will "see".

How to change the fontImage color while click on it in codename one?

We developed app using Codename one in that We have a requirement to change the color of the FontImage.Material_Icons while click on it.
Assuming you are using a Button e.g.
Button btn = new Button("My Button");
btn.setIcon(myFontIcon);
Then you can use the setPressedIcon() method to provide an alternate icon to be shown while the button is pressed. So you would have:
Button btn = new Button("My Button");
btn.setIcon(myFontIcon);
btn.setPressedIcon(myAlternateColorFontIcon);

Cannot handle action events on Labels?

I've dynamically created a horizontal scrolling list of labels (with icon and bottom text) within a container in a tab.
However, I cannot seem to bind any action to this Label - I want touch, long press, options(commands), drag, etc
If I use Button instead of Label, I cannot seem to use URLImage to grab the icon from a url and save it to storage and use that as the button icon. It always uses only the placeholder from:
Image img = URLImage.createToStorage(placeholder, counter+"_thumbnail", thumbnailURL, URLImage.RESIZE_SCALE);
How do I grab events on the Labels? Here is a snippet of how I'm adding the labels to the container:
Container c = StateMachine.instance.findFirstListContainer();
for(...){
Label l = new Label();
l.setText(title);
l.setIcon(img);
l.setUIID("listItem");
l.setTextPosition(2);
c.addComponent(l);
}
You should use a Button rather than a Label and invoke the setUIID("Label") method.
The reason why you didn't do this is a separate question/issue: https://groups.google.com/d/msg/codenameone-discussions/5HoDEFjB5II/5dc4iKuYNSYJ

wpf Popup Lightbox effect on window

I am using following code to set gray light effect on window when I open a popup. It works fine but it basically reloads all controls or refreshes the main window .
Especially this line: currentWindow.Content = lightboxGrid;
Window currentWindow = Application.Current.Windows.Cast<Window>()
.SingleOrDefault(x => x.Name.Equals(MAIN_WINDOW_NAME));
Grid lightboxGrid = new Grid();
object currentWindowContent = currentWindow.Content;
currentWindow.Content = null;
lightboxGrid.Children.Add(new ContentControl()
{
Content = currentWindowContent
});
// now add the grid that will "black out" the content
Grid blackoutGrid = new Grid();
blackoutGrid.Background = new SolidColorBrush(Colors.Black);
lightboxGrid.Children.Add(blackoutGrid);
blackoutGrid.Opacity = 0.0; // start fully transparent
blackoutGrid.Loaded += blackoutGrid_Loaded;
currentWindow.Content = lightboxGrid;
this._lightboxEffectApplied = true;
What could be the option to have the same effect without refreshing the main window or reloading the controls?
If your main window has a Grid as its layout root (even if all the content is in the first cell), then you could add this blackoutGrid as a child to that grid and it will display above the other elements without messing with the original visual tree structure.
In this case, the Content of your Window would be a Grid, and you would add your blackoutGrid to that Grid, and remove it when you are done.
The way you are writing this seems to be a little against object-oriented practice. Technically it should be your Main Window that has the ability to display a lightbox effect.

Resources