content: package com.jingewenku.abrahamcaijin.commonutil;
  
  /**
   * @Description:主要功能:WebView管理器，提供常用设置
   * @Prject: CommonUtilLibrary
   * @Package: com.jingewenku.abrahamcaijin.commonutil
   * @author: AbrahamCaiJin
   * @date: 2017年05月24日 18:19
   * @Copyright: 个人版权所有
   * @Company:
   * @version: 1.0.0
   */
  
  import android.annotation.SuppressLint;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  
  public class WebViewManager {
      private WebView webView;
      private WebSettings webSettings;
  
      public WebViewManager(WebView webView){
          this.webView = webView;
          webSettings = webView.getSettings();
          webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
      }
  
      /**
       * 开启自适应功能
       */
      public WebViewManager enableAdaptive(){
          webSettings.setUseWideViewPort(true);
          webSettings.setLoadWithOverviewMode(true);
          return this;
      }
  
      /**
       * 禁用自适应功能
       */
      public WebViewManager disableAdaptive(){
          webSettings.setUseWideViewPort(false);
          webSettings.setLoadWithOverviewMode(false);
          return this;
      }
  
      /**
       * 开启缩放功能
       */
      public WebViewManager enableZoom(){
          webSettings.setSupportZoom(true);
          webSettings.setUseWideViewPort(true);
          webSettings.setBuiltInZoomControls(true);
          return this;
      }
  
      /**
       * 禁用缩放功能
       */
      public WebViewManager disableZoom(){
          webSettings.setSupportZoom(false);
          webSettings.setUseWideViewPort(false);
          webSettings.setBuiltInZoomControls(false);
          return this;
      }
  
      /**
       * 开启JavaScript
       */
      @SuppressLint("SetJavaScriptEnabled")
      public WebViewManager enableJavaScript(){
          webSettings.setJavaScriptEnabled(true);
          return this;
      }
  
      /**
       * 禁用JavaScript
       */
      public WebViewManager disableJavaScript(){
          webSettings.setJavaScriptEnabled(false);
          return this;
      }
  
      /**
       * 开启JavaScript自动弹窗
       */
      public WebViewManager enableJavaScriptOpenWindowsAutomatically(){
          webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
          return this;
      }
  
      /**
       * 禁用JavaScript自动弹窗
       */
      public WebViewManager disableJavaScriptOpenWindowsAutomatically(){
          webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
          return this;
      }
  
      /**
       * 返回
       * @return true：已经返回，false：到头了没法返回了
       */
      public boolean goBack(){
          if(webView.canGoBack()){
              webView.goBack();
              return true;
          }else{
              return false;
          }
      }
  }
  