Search code examples
codenameone

Infinite progress hide complety the screen on android


on Android in a Form with a browserComponent the Infinite progress hide complety the screen and can't see the content, on IOS works fine.

If the form has no a BrowserComponent works fine in Android and IOS and the screen goes to dark but we can see the content.

I attach a sample code (only the start method)

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

    Form hi2 = new Form("No browser Form", BoxLayout.y());

    hi2.add(new Button(new Command("Show Infinite Progress") {
         @Override
         public void actionPerformed(ActionEvent evt) {
             try {
               Dialog ip = new InfiniteProgress().showInfiniteBlocking();
                    new Thread(new Runnable() {
                    @Override
                    public void run() {
                            try {
                                Thread.sleep(2000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                       ip.dispose();
                    }
                }).start();

             } catch (Exception ex) {
                 ex.printStackTrace();
             }
      }
     }));   
    
    hi2.add(new Label("No browser Form"));
    hi2.add(new Button(new Command("show browser Form") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                Form hi = new Form("browser Form");
                hi.setLayout(new BorderLayout());
                
                BrowserComponent browserComponent = new BrowserComponent();
                browserComponent.setURL("https://www.codenameone.com/");

                hi.add(BorderLayout.CENTER, browserComponent);

            
                hi.add(BorderLayout.SOUTH, new Button(new Command("Show Infinite Progress") {
                     @Override
                       public void actionPerformed(ActionEvent evt) {
                           try {
                               Dialog ip = new InfiniteProgress().showInfiniteBlocking();
                                new Thread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            Thread.sleep(2000);
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        }
                                       ip.dispose();
                                    }
                                }).start();
 
                           } catch (Exception ex) {
                               ex.printStackTrace();
                           }
                    }
                   }));

            
                hi.show();
            } catch (Exception ex) {
                Dialog.show("Error", ex.getMessage(), "OK", null);
                ex.printStackTrace();
            }
        }
    }));
    hi2.show();
}

Solution

  • InfiniteProgress creates a Dialog which shows it in the center but effectively blocks input all around. BrowserComponent doesn't work well with dialogs because the background of a dialog needs to be "painted" and isn't the real underlying Form.

    Normally the workaround is to use an InteractionDialog. You can also use the LayeredPane to place the InfiniteProgress and even color it appropriately so it will "look" the same. Reproducing the blocking behavior is harder though. I'm not sure if you'll be able to do that since native widgets handle their own events. It's pretty easy to block input from Codename One components but by the time you get the event it might have been processed by the native widget.

    The only workaround for that aspect I can think of is doing that part in JavaScript.