Suraj Bahadur

Suraj Bahadur
  • Home
  • Features
  • _Multi DropDown
  • __DropDown 1
  • __DropDown 2
  • __DropDown 3
  • _ShortCodes
  • _Sitemap
  • _Error Page
  • Seo Services
  • Documentation
  • Download This Template

How To Make Android Web View Application With Splash Screen

September 22, 2016
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    WebView webView;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.wb);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl("http://surajbahadur.blogspot.in/");
        //web chrome client used for loading      
        webView.setWebChromeClient(new WebChromeClient() {
            final ProgressDialog pd = ProgressDialog.show(MainActivity.this,     
"Loading", "Please Wait....");
            @Override           \
       public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    pd.dismiss();
                }
                super.onProgressChanged(view, newProgress);
            }
        });
    }

    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                    } else {
                        exitDialog(MainActivity.this);
                    }
                    return true;
            }

        }
        return super.onKeyDown(keyCode, event);
    }

    private void exitDialog(Context ctx) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setTitle("Exit");
        builder.setMessage("Are you sure ?");

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override            
        public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override            
        public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}
********************************************************************************

             Code to make splash secreen

*******************************************************************************
package com.hitech.astrologeranilverma;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class SplashScreen extends AppCompatActivity implements Animation.AnimationListener {
    Context ctx = SplashScreen.this;

    public static boolean isOnline(Context c) {
        boolean online = false;
        TelephonyManager tm = (TelephonyManager) c.getSystemService(c.TELEPHONY_SERVICE);
        if (tm != null) {
            if (tm.getDataState() == TelephonyManager.DATA_CONNECTED) {
                online = true;
            } else {
                ConnectivityManager connectivityManager = (ConnectivityManager)
                    c.getSystemService(c.CONNECTIVITY_SERVICE);
                if (connectivityManager != null) {
                    NetworkInfo info = connectivityManager.getActiveNetworkInfo();
                    if (info != null) {
                        online = info.isConnected();
                    }
                }
            }
        }
        return online;

    }

    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        StartAnimation();
    }

    private void StartAnimation() {
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        anim.reset();
        RelativeLayout rl = (RelativeLayout) findViewById(R.id.relative_layout);
        rl.clearAnimation();
        ImageView imageView = (ImageView) findViewById(R.id.astrologerIcon);
        imageView.startAnimation(anim);
        anim.setAnimationListener(this);
    }

    @Override    public void onAnimationStart(Animation animation) {

    }

    @Override    public void onAnimationEnd(Animation animation) {
        if (isOnline(SplashScreen.this)) {
            Intent intent = new Intent(ctx, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(intent);
            SplashScreen.this.finish();
        } else {
            dialog(SplashScreen.this);
        }
    }

    @Override    public void onAnimationRepeat(Animation animation) {

    }

    private void dialog(SplashScreen splashScreen) {
        runOnUiThread(new Runnable() {
            @Override            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
                builder.setTitle("No internet access");
                builder.setMessage("Please connect to internet");
                builder.setCancelable(false);

                builder.setPositiveButton("Open Setting",
                new DialogInterface.OnClickListener() {
                    @Override                   
                public void onClick(DialogInterface dialog, int which) {
                        startActivityForResult(new Intent(Settings.ACTION_SETTINGS), 0);
                    }
                });

                builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
                    @Override                   
                 public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
    }
}
Share This:
Facebook Twitter Google+ Pinterest Linkedin Whatsapp
at September 22, 2016
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Home
Subscribe to: Post Comments (Atom)

Popular

  • Way To Find  Serial Key Of Any Software Using Simple Newbie Trick
    Way To Find Serial Key Of Any Software Using Simple Newbie Trick
    Hi Newbie's ,  In this post i'm gonna give you a newbie tips and tricks to find any sofware serial key by using simple newbie tri...
  • [How to] Logic Behind To Print Pattern In Any language Using The Concept Of For Loop
    [How to] Logic Behind To Print Pattern In Any language Using The Concept Of For Loop
    Hi all newbie's , here in this tutorial i'm going to show a simple logic behind to print pattern using for  in any programming lang...
  • Part -2 :How To Print Diamond in C++
    #include using namespace std; int main(){ int i,j,k,row; row=3; for( k=1;k<=row;k++) { for(j=1;j<=3-k;j++){ cout<<...
  • How To Implement Chronometer In Android
    In this post i'll going to share the problem when implementing chronometer in android application Problem: I have one activity with t...
  • How to print diamond pattern in c++ & c...
    Following is the program to print diamond using for loop in any programming language. #include<iostream> using namespace std; ...

Tags

batch programming newbie tips and tricks Programming Logic To Print Diamond Pattern In C and C++ .......n so on. protect folder with password SHA1 Fingerprint cerification in android through Cmd Top 54 Hidden list of proxy sites trick

Search This Blog

Suraj Bahadur | 2016 |. Powered by Blogger.

Content

  • ▼  2016 (16)
    • ►  December (1)
    • ►  November (1)
    • ►  October (7)
    • ▼  September (7)
      • Create Launcher Icon For Android Application
      • Top 54 Hidden list of proxy sites
      • [HOW] to open banned websites with proxy
      • How to print diamond pattern in c++ & c...
      • How to print diamond pattern in c++ & c...
      • Google Sign In - How to obtain SHA1 fingerprint ce...
      • How To Make Android Web View Application With Spla...

Suraj Bahadur

Suraj Bahadur

Report Abuse

Follow @surajbahadur1

About Me

My photo
Suraj Bahadur
View my complete profile
Suraj D NeWbie | 

Linkedin

Suraj Bahadur

Instagram

Subscribe me

Posts
Atom
Posts
Comments
Atom
Comments

Visitors

suraj

  • Facebook
  • Twitter
  • LinkedIn
Created By SoraTemplates | Distributed By Blogger Templates