content: package com.adymilk.easybrowser.por;
  
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.KeyEvent;
  import android.view.View;
  import android.webkit.WebChromeClient;
  import android.webkit.WebResourceRequest;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import com.just.agentweb.AgentWeb;
  import com.just.agentweb.ChromeClientCallbackManager;
  
  /**
   * Created by cenxiaozhong on 2017/5/26.
   *
   * source CODE  https://github.com/Justson/AgentWeb
   *
   * 使用 AgentWeb 需要通过组合或者继承。
   * <p>
   */
  
  public class BaseWebActivity extends AppCompatActivity {
  
  
  
      protected AgentWeb mAgentWeb;
      private LinearLayout mLinearLayout;
      private Toolbar mToolbar;
      private TextView mTitleTextView;
      private AlertDialog mAlertDialog;
  
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
  
          setContentView(com.adymilk.easybrowser.por.R.layout.activity_web);
  
          mLinearLayout = (LinearLayout) this.findViewById(com.adymilk.easybrowser.por.R.id.container);
          mToolbar = (Toolbar) this.findViewById(com.adymilk.easybrowser.por.R.id.toolbar);
          mToolbar.setTitleTextColor(Color.WHITE);
          mToolbar.setTitle("");
          mTitleTextView = (TextView) this.findViewById(com.adymilk.easybrowser.por.R.id.toolbar_title);
          this.setSupportActionBar(mToolbar);
          if (getSupportActionBar() != null)
              // Enable the Up button
              getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  showDialog();
              }
          });
  
  
          long p = System.currentTimeMillis();
  
          mAgentWeb = AgentWeb.with(this)//
                  .setAgentWebParent(mLinearLayout,new LinearLayout.LayoutParams(-1,-1) )//
                  .useDefaultIndicator()//
                  .defaultProgressBarColor()
                  .setReceivedTitleCallback(mCallback)
                  .setWebChromeClient(mWebChromeClient)
                  .setWebViewClient(mWebViewClient)
                  .setSecutityType(AgentWeb.SecurityType.strict)
                  .setWebLayout(new com.adymilk.easybrowser.por.WebLayout(this))
                  .createAgentWeb()//
                  .ready()
                  .go(getUrl());
  
          //mAgentWeb.getLoader().loadUrl(getUrl());
  
          long n = System.currentTimeMillis();
          Log.i("Info", "init used time:" + (n - p));
  
  
  
  
  
      }
  
      private WebViewClient mWebViewClient=new WebViewClient(){
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
              return super.shouldOverrideUrlLoading(view, request);
          }
  
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
             //do you  work
              Log.i("Info","BaseWebActivity onPageStarted");
          }
      };
      private WebChromeClient mWebChromeClient=new WebChromeClient(){
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
              //do you work
  //            Log.i("Info","progress:"+newProgress);
          }
      };
      public String getUrl(){
  
  //        return "https://m.jd.com/";
          return "http://adymilk.cn/";
      }
  
      private ChromeClientCallbackManager.ReceivedTitleCallback mCallback = new ChromeClientCallbackManager.ReceivedTitleCallback() {
          @Override
          public void onReceivedTitle(WebView view, String title) {
              if (mTitleTextView != null)
                  mTitleTextView.setText(title);
          }
      };
  
  
      private void showDialog() {
  
          if (mAlertDialog == null)
              mAlertDialog = new AlertDialog.Builder(this)
                      .setMessage("您确定要关闭该页面吗?")
                      .setNegativeButton("再逛逛", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              if (mAlertDialog != null)
                                  mAlertDialog.dismiss();
                          }
                      })//
                      .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
  
                              if (mAlertDialog != null)
                                  mAlertDialog.dismiss();
  
                              BaseWebActivity.this.finish();
                          }
                      }).create();
          mAlertDialog.show();
  
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
  
          if (mAgentWeb.handleKeyEvent(keyCode, event)) {
              return true;
          }
          return super.onKeyDown(keyCode, event);
      }
  
      @Override
      protected void onPause() {
          mAgentWeb.getWebLifeCycle().onPause();
          super.onPause();
  
      }
  
      @Override
      protected void onResume() {
          mAgentWeb.getWebLifeCycle().onResume();
          super.onResume();
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
  //        LogUtils.i("Info", "result:" + requestCode + " result:" + resultCode);
          mAgentWeb.uploadFileResult(requestCode, resultCode, data);
          super.onActivityResult(requestCode, resultCode, data);
      }
  
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          //mAgentWeb.destroy();
          mAgentWeb.getWebLifeCycle().onDestroy();
  
      }
  }
  