package com.edu.tdc.blackbar.tourismguide;

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.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.provider.Settings;

import com.wang.avi.AVLoadingIndicatorView;

public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen_layout);
        AVLoadingIndicatorView loading = (AVLoadingIndicatorView) findViewById(R.id.aviSplashLoading) ;
        loading.show();
        if(isOnline()) {
           goNextActivity();
        }else{
            showAlerDialog();
        }

    }

    public boolean isOnline() {
        ConnectivityManager cm =
                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        return netInfo != null && netInfo.isConnectedOrConnecting();
    }

    public void showAlerDialog(){
        AlertDialog.Builder warning = new AlertDialog.Builder(this);
        warning.setCancelable(true);
        warning.setPositiveButton("Yes",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                        Intent sitting = new Intent(Settings.ACTION_SETTINGS);
                        startActivityForResult(sitting,1);
                        dialogInterface.cancel();
                    }
                });

        warning.setNegativeButton("No",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.cancel();
                        finish();
                    }
                });

        warning.setTitle("NetWork Connection Fail").setMessage("Do you want to go network setting?");
        warning.setIcon(R.drawable.warning);
        AlertDialog connectionFail = warning.create();
        connectionFail.show();
    }

    public void goNextActivity(){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 4000);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1){
            if(isOnline())
                goNextActivity();
            else
                showAlerDialog();
        }
    }
}


@@ -2940,24 +2940,152 @@
 ode == 1)%7B%0D%0A
+            new Handler().postDelayed(new Runnable() %7B%0D%0A                @Override%0D%0A                public void run() %7B%0D%0A        
             
@@ -3100,16 +3100,24 @@
 ine())%0D%0A
+        
         
@@ -3155,16 +3155,24 @@
         
+        
 else%0D%0A  
@@ -3177,32 +3177,40 @@
                 
+   
+     
 showAlerDialog()
@@ -3204,32 +3204,76 @@
 wAlerDialog();%0D%0A
+                %7D%0D%0A            %7D, 4000);%0D%0A%0D%0A
         %7D%0D%0A    %7D

fix schedule time deplay