1

I am using BrowserField to display some local HTML files in my application. It is displaying the HTML files properly. But while starting of the screen it is displaying some white screen (background). How can i get rid of this issue?

I am using the below code:

BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
_bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
_bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");

BrowserField myBrowserField = new BrowserField(_bfConfig);
add(myBrowserField);

BrowserFieldRequest request = new BrowserFieldRequest("local:///OTPhelp_en.html");
myBrowserField.requestContent(request);
Nate
  • 31,017
  • 13
  • 83
  • 207
Arindam Mukherjee
  • 2,255
  • 11
  • 48
  • 83

1 Answers1

2

I don't have a perfect answer for you. If you take a look at this question, so far, no answers have been given as to how to make the BrowserField background transparent, which would be one way to solve your problem.

Depending on how your OTPhelp_en.html page is written, how much control over it you have, and how often it changes, this may be a workaround that's acceptable:

If your html file has a solid background color, and you know what that color is (because it's your html content), then you could simply set the BrowserField background color to match. Then, you wouldn't see any white flash before the html content is rendered. Something like this:

public class MyBrowserScreen extends MainScreen {

    // this assumes the html file uses a red (#ff0000) background
    private int BG_COLOR = Color.RED;

    public MyBrowserScreen() {

        // set the screen manager's background
        getMainManager().setBackground(BackgroundFactory.createSolidBackground(BG_COLOR));

        BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
        _bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
        _bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
        _bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");

        BrowserField myBrowserField = new BrowserField(_bfConfig);

        // set the browser field background to match the HTML background, and
        //  the containing screen's background
        _myBrowserField.setBackground(getMainManager().getBackground());
        add(myBrowserField);

        BrowserFieldRequest request = new BrowserFieldRequest("local:///OTPhelp_en.html");
        myBrowserField.requestContent(request);

Of course, hardcoding it in this way means that if the HTML file changes its background color, you'll need to change it in the Java code, too.

If you wanted to avoid that, and you knew the HTML file would always use a solid background color, you could first open the html file as a resource stream

getClass().getResourceAsStream("/OTPhelp_en.html");

and then parse it, searching for the background color (e.g. <body bgcolor= or <body style="background-color:). That would at least allow the browser field to look right if a simple background color change is made in the HTML file.

If the HTML file uses a gradient background, or an image background, the above code will have to be changed. But, without more information, that's my suggestion for a workaround.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • But that is not a perfect solution. Even for my case, it will make things more harder. Because in future, the html files may come from server and i am displaying this pages for different languages. So it means i have different html files for different languages. So in this way, things will become tougher for me. But thanks for your answer. – Arindam Mukherjee Mar 02 '13 at 04:28
  • @Arindam, Yes, that's correct. Of course, HTML content on the server is a different problem. If the HTML file is being retrieved from a server, the user probably expects a small delay in rendering it. I usually worry more about BrowserFields loading smoothly if I'm trying to show **local** content, where I don't want the user to even think that there's a network delay. – Nate Mar 02 '13 at 09:57