bungdito
bungdito

Reputation: 3620

how to make animated splash screen as my "web view pre loader" OR web view run as background while animated splash screen appear

several days ago I found very awesome tutorial:advance animated splash screen, i'm very newbie in android dev and this tutorial is very helpful to make awesome splashscreen..

but i need little more help to modifying that code, I need to load my webview activity after the splash screen,, if possible i want to make splash screen as my webview pre-loader or at least make the webview activity as background activity, so when the splashscreen apear then my webview is no need much time for loading anymore..

sequence I expected something like this:
1. user clicking/tapping an app icon
2. the animation_splashscreen to appear (but not only waiting for 5000 but also with loading my webview)
3. (no loading anymore... then...) my webview to appear

I have try it's work fine, but there is like i load twice,, after the splash screen gone, my web view appear with loading/progress bar..

My question is, can I apply the splash screen as my webview preloader? so the splash screen will be gone after the webview completely loaded on device,, then directly open the webview (no loading anymore on my webview)

may any body show to me step by step please, because I'm very very very newbie in android dev.. i try to learn Splash screen while loading a url in a webview in android app but i can't understand when I want to make animated splashscreen :(

here is my code:

on the SplashScreen.java

package com.yourname.main;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.ImageView;

public class SplashScreen extends Activity {

    /**
     * The thread to process splash screen events
     */
    private Thread mSplashThread;   

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Splash screen view
        setContentView(R.layout.splash);

        // Start animating the image
        final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
        splashImageView.setBackgroundResource(R.drawable.flag);
        final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
        splashImageView.post(new Runnable(){
            @Override
            public void run() {
                frameAnimation.start();             
            }           
        });


        final SplashScreen sPlashScreen = this;   

        // The thread to wait for splash screen events
        mSplashThread =  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        // Wait given period of time or exit on touch
                        wait(5000);
                    }
                } 
                catch(InterruptedException ex){                 
                }

                finish();

                // Run next activity
                Intent intent = new Intent();
                intent.setClass(sPlashScreen, WebViewActivity.class);
                startActivity(intent);
                //stop();                   
            }
        };

        mSplashThread.start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);
        return false;
    } 

    /**
     * Processes splash screen touch events
     */
    @Override
    public boolean onTouchEvent(MotionEvent evt)
    {
        if(evt.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(mSplashThread){
                mSplashThread.notifyAll();
            }
        }
        return true;
    }


}

and, on the WebViewActivity.java

package com.yourname.main;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...",true);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(true);  
                webView.getSettings().setBuiltInZoomControls(true);
                webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                if(pd.isShowing()&&pd!=null)
                {
                    pd.dismiss();
                }
            }
        });

        webView.loadUrl("http://google.com");
        setTitle("Google Search");
    }

}

Upvotes: 0

Views: 2446

Answers (1)

thiagolr
thiagolr

Reputation: 7027

From your question, you don't need a Splash Screen.

You can do the following:

  1. Forget about the SplashScreen activity
  2. Open WebViewActivity directly
  3. Add the splash ImageView to your webview.xml
  4. Set the splash ImageView image
  5. Set the webView visibility to INVISIBLE
  6. Set the webView visibility to VISIBLE and splash ImageView to GONE during onPageFinished

Basically you will show an image on top of the webview and once the page is loaded you will remove that image and display the webview.

Upvotes: 1

Related Questions