// Path: app/src/main/java/com/hut/zero/util/NetworkState.java
// public class NetworkState {
// 
//     // 检查是否连接到网络
//     // whether connect to internet
//     public static boolean networkConnected(Context context){
// 
//         if (context != null){
//             ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo info = manager.getActiveNetworkInfo();
//             if (info != null)
//                 return info.isAvailable();
//         }
// 
//         return false;
//     }
// 
//     // 检查WiFi是否连接
//     // if wifi connect
//     public static boolean wifiConnected(Context context){
//         if (context != null){
//             ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo info = manager.getActiveNetworkInfo();
//             if (info != null){
//                 if (info.getType() == ConnectivityManager.TYPE_WIFI)
//                     return info.isAvailable();
//             }
//         }
//         return false;
//     }
// 
//     // 检查移动网络是否连接
//     // if mobile data connect
//     public static boolean mobileDataConnected(Context context){
//         if (context != null){
//             ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo info = manager.getActiveNetworkInfo();
//             if (info != null){
//                 if (info.getType() == ConnectivityManager.TYPE_MOBILE)
//                     return true;
//             }
//         }
//         return false;
//     }
// 
// }


import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.hut.zero.R;
import com.hut.zero.util.NetworkState;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_inner_browser, container, false);

        initViews(view);
        initWebViewSettings(webView);

        // if not set this, click the back arrow will call nothing
        setHasOptionsMenu(true);

        webView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                changeToolbarAndProgressBar(newProgress);
            }
        });

        webView.setWebViewClient(new WebViewClient(){

            @Override
            public void onReceivedError(WebView view1, WebResourceRequest request, WebResourceError error) {

                webView.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
                textView.setVisibility(View.VISIBLE);

                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
// Path: app/src/main/java/com/hut/zero/util/NetworkState.java
// public class NetworkState {
// 
//     // 检查是否连接到网络
//     // whether connect to internet
//     public static boolean networkConnected(Context context){
// 
//         if (context != null){
//             ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo info = manager.getActiveNetworkInfo();
//             if (info != null)
//                 return info.isAvailable();
//         }
// 
//         return false;
//     }
// 
//     // 检查WiFi是否连接
//     // if wifi connect
//     public static boolean wifiConnected(Context context){
//         if (context != null){
//             ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo info = manager.getActiveNetworkInfo();
//             if (info != null){
//                 if (info.getType() == ConnectivityManager.TYPE_WIFI)
//                     return info.isAvailable();
//             }
//         }
//         return false;
//     }
// 
//     // 检查移动网络是否连接
//     // if mobile data connect
//     public static boolean mobileDataConnected(Context context){
//         if (context != null){
//             ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             NetworkInfo info = manager.getActiveNetworkInfo();
//             if (info != null){
//                 if (info.getType() == ConnectivityManager.TYPE_MOBILE)
//                     return true;
//             }
//         }
//         return false;
//     }
// 
// }


// Path: app/src/main/java/com/hut/zero/innerbrowser/InnerBrowserFragment.java
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.hut.zero.R;
import com.hut.zero.util.NetworkState;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_inner_browser, container, false);

        initViews(view);
        initWebViewSettings(webView);

        // if not set this, click the back arrow will call nothing
        setHasOptionsMenu(true);

        webView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                changeToolbarAndProgressBar(newProgress);
            }
        });

        webView.setWebViewClient(new WebViewClient(){

            @Override
            public void onReceivedError(WebView view1, WebResourceRequest request, WebResourceError error) {

                webView.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
                textView.setVisibility(View.VISIBLE);

                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (NetworkState.networkConnected(getContext())){