@SuppressLint("SetJavaScriptEnabled")
  public void setUpWebView() {
    // mWebView.setWebViewClient(new AhWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setUseWideViewPort(true);
    mWebView.getSettings().setAppCacheEnabled(true);
    mWebView.getSettings().setLoadsImagesAutomatically(true);
    mWebView.setMixedContentAllowed(true);
    mWebView.setCookiesEnabled(true);
    mWebView.setGeolocationEnabled(true);
    mWebView.setThirdPartyCookiesEnabled(true);
    mWebView.setListener(mActivity, this);

    if (!showRefreshDialog()) {
      mWebView.loadUrl(mURL);
    }
  }
示例#2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browser);

    mBrowserWv = (AdvancedWebView) findViewById(R.id.browser_web_view);
    /*mBrowserWv.setListener(this, new AdvancedWebView.Listener() {
        @Override
        public void onPageStarted(String s, Bitmap bitmap) {

        }

        @Override
        public void onPageFinished(String s) {

        }

        @Override
        public void onPageError(int i, String s, String s1) {

        }

        @Override
        public void onDownloadRequested(String s, String s1, String s2, String s3, long l) {

        }

        @Override
        public void onExternalPageRequest(String s) {

        }
    });*/
    mChromeClient =
        new WebChromeClient() {
          @Override
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            getTitleBar().setTitleCenter(title);
            mTitle = title;
          }

          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            Log.v(TAG, "chromeClient onJsAlert");
            return super.onJsAlert(view, url, message, result);
          }

          @Override
          public boolean onShowFileChooser(
              WebView webView,
              ValueCallback<Uri[]> filePathCallback,
              FileChooserParams fileChooserParams) {
            Toast.makeText(BrowserActivity.this, "onShowFileChooser", Toast.LENGTH_SHORT).show();
            Log.v(TAG, "chromeClient onShowFileChooser ");
            return super.onShowFileChooser(webView, filePathCallback, fileChooserParams);
          }

          public void openFileChooser(
              ValueCallback<Uri> uploadMsg, String AcceptType, String capture) {
            this.openFileChooser(uploadMsg);
            Log.v(TAG, "openFileChooser");
          }

          @SuppressWarnings("unused")
          public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType) {
            this.openFileChooser(uploadMsg);
            Log.v(TAG, "openFileChooser");
          }

          public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            Log.v(TAG, "openFileChooser");
          }
        };
    mBrowserWv.setWebChromeClient(mChromeClient);
    mBrowserWv.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mUrl = url;
          }
        });
    WebSettings settings = mBrowserWv.getSettings();
    settings.setJavaScriptEnabled(true);

    canGoOut = getIntent().getBooleanExtra(ActivityDispatcher.KEY_CAN_GO_OUT, false);
    mUrl = getIntent().getStringExtra(ActivityDispatcher.KEY_URL);
    mBrowserWv.loadUrl(mUrl);

    getTitleBar()
        .setOnLeftBtnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                finish();
              }
            });
    if (canGoOut) {
      getTitleBar().setDrawableResourceRight(R.drawable.ic_dots_horizontal);
      getTitleBar().setTitleCenter(mUrl);

      getTitleBar()
          .setOnRightBtnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  showDialog();
                  // ActivityDispatcher.outBrowserActivity(BrowserActivity.this, mUrl);
                }
              });
    }
  }
 @Override
 public void onPageError(int i, String s, String s1) {
   if (!showRefreshDialog()) {
     mWebView.loadUrl(mURL);
   }
 }