Asked  7 Months ago    Answers:  5   Viewed   49 times

I still have a problem with the splash screen. I don't want to use the property SC.TopMost=true.

Now my application scenario is as follows:

in progeram.cs:

[STAThread]
static void Main()
{
    new SplashScreen(_tempAL);// where _tempAL is an arrayList
    Application.Run(new Form1(_tempAL));
}

in SplashScreen class:

public SplashScreen(ArrayList _Data)
{
    DisplaySplash()
} 
private void DisplaySplash()
{
    this.Show();
    this.TopMost = true;
    this.CenterToScreen();
    this.SetTopLevel(true);

    _allServerNarrators = new string[10];
    for (int i = 0; i < _allServerNarrators.Length; i++)
        _allServerNarrators[i] = null;

    GetFromServer();

    this.Hide();
    _serverData = new ArrayList();
    _thisData.Add(_allServerNarrators);
    _thisData.Add(_serverNarrators);

}
private void GetFromServer()
{
    _serverNarrators = new ArrayList();
    string _file = "Suras.serverNar";

    if (!Directory.Exists("c:\ASGAQuraan"))
        Directory.CreateDirectory("c:\ASGAQuraan");

    while (counter < 4 && _serverFiles == null)
    {
        if (Download("c:\ASGAQuraan", _ftpServerIP, _file))
        {
            StreamReader _strReader = new StreamReader
                         ("c:\ASGAQuraan\"+_file,System.Text.Encoding.Default);
            string _line = _strReader.ReadLine();
            string _word;

            while (true)
            {
                while (_line != null)
                {
                    _word = _line.Substring(0, _line.IndexOf("*"));
                    int _narId = Convert.ToInt32(_word);
                    _line = _line.Substring(2);
                    int k = 0;
                    _serverNarratorNode = new ArrayList();
                    while (true)
                    {
                        int ind = _line.IndexOf("*");
                        if (ind > 0 && ind < _line.Length)
                        {
                            string str = _line.Substring(0, (ind));
                            if (k == 0)
                            {
                                _allServerNarrators[_narId] = str;
                                _serverNarratorNode.Add(str);
                            }
                            else
                            {
                                _serverNarratorNode.Add(str);
                            }
                            _line = _line.Substring(ind + 1);
                            k++;
                        }
                        else
                        {
                            _line = null;
                            break;
                        }
                    }
                    _serverNarrators.Add(_serverNarratorNode);
                    _serverFiles = "added";
                }
                _line = _strReader.ReadLine();
                if (_line == null)
                {
                    break;
                }
            }
        }
        else
            counter++;
    }
}

What I want is something in the splash screen class which waits until the thread finishes.

For more details, please tell me what I need to tell you.

 Answers

26

Following across 2 threads is a bit confusing, but I'm going to take a stab and say this...

I don't fully understand your design here, but if the issue is that when you launch a second application the splash screen form turns white... It's most likely due to the fact that splash screen is busy executing all of that code in GetFromServer(). So busy that it has no time to re-paint itself.

To remedy this problem I would suggest that you use the BackGroundWorker component to execute the GetFromServer method. This will run that method in a separate thread and leave the form's thread free to re-paint itself.

Tuesday, June 1, 2021
 
Saxophlutist
answered 7 Months ago
22

I do it by initially showing an ImageView and then once the WebView has loaded, swapping their visibility like this

        WebView wv = (WebView) findViewById(R.id.webView1);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.setWebViewClient(new WebViewClient() {

            ...

            @Override
            public void onPageFinished(WebView view, String url) {
                //hide loading image
                findViewById(R.id.imageLoading1).setVisibility(View.GONE);
                //show webview
                findViewById(R.id.webView1).setVisibility(View.VISIBLE);
            }


        });     
        wv.loadUrl("http://yoururlhere.com");

And my xml layout looks like this

    <ImageView android:id="@+id/imageLoading1"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:visibility="visible"
        android:src="@drawable/vert_loading"
        />
    <WebView android:id="@+id/webView1"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:visibility="gone"
        />
Monday, June 21, 2021
 
Saurabh
answered 6 Months ago
74

You should use SwingUtilities.invokeLater or SwingUtilities.invokeAndWait when updating the GUI from a different thread.

Please see the Chapter Concurrency in Swing which explains the reasons behind this.

The SplashScreen Example from the Tutorial does the Thread.sleep inside the Swing thread. This is fine, too if you do not need any other GUI refresh while the SplashScreen is showing. Your loading code however should happen in a different thread.

I would recommend adding a setPercent setter to your class which creates a Runnable to update the GUI via SwingUtilities.invokeLater. That way you do not even need to poll the percent variable and the SwingThread is free to render other UI stuff, too.

Thursday, July 8, 2021
 
Corne
answered 5 Months ago
93

I would suggest using the built in Splash Screen that is provided by Visual Studio:

Go to the "Projects" menu and select "Add Windows Form" and select the Splash Screen template:

enter image description here

Then in the Project's Application settings, select that form to be the Splash screen:

enter image description here

Your start up form should be your login form, not the splash screen form.

Update:

Click on the "View Application Events" button on the last image from your My Project's Application screen and add this code to set the MinimumSplashScreenDisplayTime value:

Imports System.Collections.ObjectModel

Namespace My
  Partial Friend Class MyApplication
    Protected Overrides Function OnInitialize(commandLineArgs As ReadOnlyCollection(Of String)) As Boolean
      Me.MinimumSplashScreenDisplayTime = 5000
      Return MyBase.OnInitialize(commandLineArgs)
    End Function
  End Class
End Namespace

Your splash screen will remain on the screen for 5000 milliseconds, or 5 seconds.

Saturday, August 14, 2021
 
Pete Gardner
answered 4 Months ago
66

The main part is, creating Startup Class which extends UiApplication.

This is the StartUp.java

public class StartUp extends UiApplication
{
public static void main(String[]args)
{
    StartUp start=new StartUp();
    start.enterEventDispatcher();
}
public StartUp() 
{
    this.pushScreen(new SplashScreen());
    invokeLater(new Runnable() 
    {
        public void run() 
        {
            try 
            {
                Thread.sleep(2000);// Sleeps it for few seconds
                UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
                pushScreen(new LoadingScreen());
            } 
            catch (Exception e) 
            {
                exceptionHandling(e.getMessage());
            }
        }
    });

}

public static void exceptionHandling(final String exception)
{
    UiApplication.getUiApplication().invokeLater(new Runnable() 
    {       
        public void run() 
        {
            Dialog.alert(exception);
        }
    });
}
}

and the SplashScreen.java

public class SplashScreen extends MainScreen
{
Bitmap bitmap=Bitmap.getBitmapResource("loading-screen.png");//This is my company logo;
BitmapField loadingImage=new BitmapField(bitmap);
public SplashScreen() 
{
    createGUI();
}

private void createGUI() 
{
    try 
    {
        VerticalFieldManager vertical=new VerticalFieldManager()
        {
            protected void paint(Graphics g) 
            {
                g.drawBitmap(0, 0,Display.getWidth(),Display.getHeight(), bitmap, 0, 0);
                super.paint(g);
            }
            protected void sublayout(int maxWidth, int maxHeight) 
            {
                super.sublayout(Display.getWidth(),Display.getHeight());
                setExtent(Display.getWidth(),Display.getHeight());
            }
        };

   //           Nothing to write;

        add(vertical);
    }
    catch (Exception e) 
    {
        StartUp.exceptionHandling(e.getMessage());
    }
}
}

and your FirstScreen.java

public class FirstScreen extends MainScreen
{
VerticalFieldManager vertical;  

public FirstScreen()
{               
    createGUI();
}

private void createGUI() 
{
    setTitle("Loading Screen");
    vertical=new VerticalFieldManager()
    {
        protected void sublayout(int maxWidth, int maxHeight) 
        {
            super.sublayout(Display.getWidth(),Display.getHeight());
            setExtent(Display.getWidth(),Display.getHeight());
        }
    };
    add(vertical);
}

public boolean onMenu(int instance) 
{
    return true;
}
}

Try this you can get.

Tuesday, November 23, 2021
 
Ewanziak
answered 2 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share