content: package info.meizi_retrofit.ui.about;
  
  import android.content.ClipData;
  import android.content.ClipboardManager;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.webkit.WebChromeClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.ProgressBar;
  import android.widget.Toast;
  
  import butterknife.Bind;
  import info.meizi_retrofit.R;
  import info.meizi_retrofit.ui.base.ToolBarActivity;
  
  /**
   * Created by Mr_Wrong on 16/1/8.
   */
  public class WebActivity extends ToolBarActivity {
      public static final String URL = "url";
      public static final String TITLE = "title";
      @Bind(R.id.myProgressBar)
      ProgressBar mProgressBar;
      @Bind(R.id.webview)
      WebView mWebView;
      private String url;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          url = getIntent().getStringExtra(URL);
  
          WebSettings settings = mWebView.getSettings();
          settings.setJavaScriptEnabled(true);
          mWebView.setWebChromeClient(new WebChromeClient() {
  
              @Override
              public void onProgressChanged(WebView view, int newProgress) {
                  if (newProgress == 100) {
                      mProgressBar.setVisibility(View.INVISIBLE);
                  } else {
                      if (View.INVISIBLE == mProgressBar.getVisibility()) {
                          mProgressBar.setVisibility(View.VISIBLE);
                      }
                      mProgressBar.setProgress(newProgress);
                  }
              }
  
              @Override
              public void onReceivedTitle(WebView view, String title) {
                  super.onReceivedTitle(view, title);
                  setTitle(title);
              }
          });
          mWebView.setWebViewClient(new WebViewClient() {
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  view.loadUrl(url);
                  return true;
              }
          });
          mWebView.loadUrl(url);
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_web, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          switch (id) {
              case R.id.action_refresh:
                  mWebView.reload();
                  return true;
              case R.id.action_copy_url:
                  ClipData clipData = ClipData.newPlainText("meizi", mWebView.getUrl());
                  ClipboardManager manager =
                          (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
                  manager.setPrimaryClip(clipData);
                  Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                  return true;
              case R.id.action_open_url:
                  Intent intent = new Intent();
                  intent.setAction(Intent.ACTION_VIEW);
                  Uri uri = Uri.parse(url);
                  intent.setData(uri);
                  if (intent.resolveActivity(getPackageManager()) != null) {
                      startActivity(intent);
                  }
                  return true;
  
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if (event.getAction() == KeyEvent.ACTION_DOWN) {
              switch (keyCode) {
                  case KeyEvent.KEYCODE_BACK:
                      if (mWebView.canGoBack()) {
                          mWebView.goBack();
                      } else {
                          finish();
                      }
                      return true;
              }
          }
          return super.onKeyDown(keyCode, event);
      }
  
      @Override
      protected int layoutId() {
          return R.layout.web;
      }
  }
  