Example #1
0
  /**
   * 初始化
   *
   * @param web_view
   * @param activity
   * @return
   */
  public static WebView WebSettingInit(WebView web_view, final Activity activity) {
    WebSettings ws = web_view.getSettings();
    ws.setJavaScriptEnabled(true); // 支持js
    ws.setBuiltInZoomControls(false); // 支持缩放按钮
    ws.setUseWideViewPort(true); // 设置此属性,可任意比例缩放 将图片调整到适合webview的大小
    ws.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
    ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    ws.setSupportZoom(false); // 支持缩放
    // 设置 缓存模式
    ws.setCacheMode(WebSettings.LOAD_NO_CACHE); // 关闭webview中缓存

    web_view.clearCache(true);
    web_view.setTag(true);
    // 开启 DOM storage API 功能
    ws.setDomStorageEnabled(true);

    ws.setRenderPriority(RenderPriority.HIGH);
    // 开启 database storage API 功能
    ws.setDatabaseEnabled(false);

    web_view.setWebChromeClient(
        new WebChromeClient() {

          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
          }
        });
    return web_view;
  }
Example #2
0
  /**
   * @Title: initViews @Description: TODO(这里用一句话描述这个方法的作用)
   *
   * @param 设定文件
   * @return void 返回类型
   * @throws
   */
  private void initViews() {
    mWebView = (CustomWebView) rootView.findViewById(R.id.webview);
    mWebView.setScrollBarStyle(0);
    WebSettings settings = mWebView.getSettings();
    settings.setDefaultTextEncodingName("utf-8"); // 避免中文乱码
    settings.setNeedInitialFocus(false);
    settings.setSupportZoom(true);
    settings.setLoadWithOverviewMode(true); // 适应屏幕
    settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    settings.setLoadsImagesAutomatically(true); // 自动加载图片
    settings.setCacheMode(WebSettings.LOAD_DEFAULT | WebSettings.LOAD_CACHE_ELSE_NETWORK);

    // 滚动事件监听
    mWebView.setOnCustomScroolChangeListener(
        new ScrollInterface() {
          @Override
          public void onScrollChanged(int l, int t, int oldl, int oldt) {
            // TODO Auto-generated method stub
            if (t == 0) { // 已经处于顶端
              mCanScrollUp = true;
            } else {
              mCanScrollUp = false;
            }
          }
        });
  }
 public void initWebview(WebView paramWebView) {
   WebSettings localWebSettings = paramWebView.getSettings();
   localWebSettings.setJavaScriptEnabled(true);
   if (Build.VERSION.SDK_INT > 7) localWebSettings.setPluginState(WebSettings.PluginState.ON);
   localWebSettings.setSupportZoom(true);
   localWebSettings.setBuiltInZoomControls(true);
   localWebSettings.setAllowFileAccess(true);
   localWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
   localWebSettings.setUseWideViewPort(true);
   if (Build.VERSION.SDK_INT >= 8) {
     localWebSettings.setLoadWithOverviewMode(true);
     localWebSettings.setDatabaseEnabled(true);
     localWebSettings.setDomStorageEnabled(true);
     localWebSettings.setGeolocationEnabled(true);
     localWebSettings.setAppCacheEnabled(true);
   }
   if (Build.VERSION.SDK_INT >= 11) ;
   try {
     Class[] arrayOfClass = new Class[1];
     arrayOfClass[0] = Boolean.TYPE;
     Method localMethod =
         WebSettings.class.getDeclaredMethod("setDisplayZoomControls", arrayOfClass);
     localMethod.setAccessible(true);
     Object[] arrayOfObject = new Object[1];
     arrayOfObject[0] = Boolean.valueOf(false);
     localMethod.invoke(localWebSettings, arrayOfObject);
     return;
   } catch (Exception localException) {
     com.taobao.newxp.common.Log.e(ExchangeConstants.LOG_TAG, "", localException);
   }
 }
  private void setData() {
    webView.setVisibility(View.VISIBLE);
    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDefaultFontSize(16);
    webView.requestFocusFromTouch(); // 支持获取手势焦点
    webView.setWebViewClient(
        new WebViewClient() { // 打开网页时不调用系统浏览器, 而是在本WebView中显示
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
          }
        });

    webView.loadDataWithBaseURL(null, CONTENT, "text/html", "UTF-8", null);
    dialog.cancel();
  }
  @TargetApi(8)
  private void load() {
    final String uri = getPath();
    final WebSettings settings = wv.getSettings();

    if (uri.endsWith(".swf") && ActivityUtil.isGreaterThan_2_1()) // android 2.2
    {
      wv.setWebChromeClient(new WebChromeClient());
      // settings.setPluginState(PluginState.ON);
      wv.loadUrl(uri);

      getSupportActionBar().setTitle("查看视频");
    } else { // images

      settings.setSupportZoom(true);
      settings.setBuiltInZoomControls(true);
      settings.setUseWideViewPort(true);
      if (ActivityUtil.isGreaterThan_2_1()) settings.setLoadWithOverviewMode(true);
      // settings.setUserAgentString(IPHONE_UA);
      wv.setWebViewClient(
          new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              // TODO Auto-generated method stub
              return false;
            }
          });
      wv.loadUrl(uri);
      getSupportActionBar().setTitle("查看图片");
    }
  }
Example #6
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d();
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mBrowser = this;

    mVizWebViewClient = new VizWebViewClient(this);
    mWebChromeClient = new VizWebChromeClient(this);

    mVizWebView = new WebView(getActivity()); // get attributes?
    mVizWebView.setWebViewClient(mVizWebViewClient);
    mVizWebView.setWebChromeClient(mWebChromeClient);
    if (savedInstanceState != null) {
      Log.d("restoring web view state");
      mVizWebView.restoreState(savedInstanceState);
    }
    WebSettings s = mVizWebView.getSettings();
    s.setJavaScriptEnabled(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setBuiltInZoomControls(true);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    s.setSaveFormData(true);

    mVizWebView.setId(61377); // PhoneWindow complained about no id (focus couldn't be saved)

    // Loading homepage here results in an exception on ICS, not sure why.
    // Update: post-poning until onCreatingView doesn't entirely fix the
    // issue either.
    // mVizWebView.loadUrl(defaultURL);
  }
Example #7
0
  /**
   * Convenience method to set some generic defaults for a given WebView
   *
   * @param webView
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
      // Hide the zoom controls for HONEYCOMB+
      settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      WebView.setWebContentsDebuggingEnabled(true);
    }

    // We set the WebViewClient to ensure links are consumed by the WebView rather
    // than passed to a browser if it can
    webView.setWebViewClient(new WebViewClient());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);
    mContext = this;
    mUrl = getIntent().getStringExtra(EXTRA_URL);
    mTitle = getIntent().getStringExtra(EXTRA_TITLE);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setAppCacheEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);
    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new LoveClient());

    mWebView.loadUrl(mUrl);

    mTextSwitcher.setFactory(
        () -> {
          TextView textView = new TextView(this);
          textView.setTextAppearance(this, R.style.WebTitle);
          textView.setSingleLine(true);
          textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
          textView.postDelayed(() -> textView.setSelected(true), 1738);
          return textView;
        });
    mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
    mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);
    if (mTitle != null) setTitle(mTitle);
  }
  private void initViewer() {
    settings.setLoadsImagesAutomatically(true);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setLightTouchEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);

    viewer.setInitialScale(0);
    viewer.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    viewer.setHorizontalScrollBarEnabled(false);
    viewer.setVerticalScrollBarEnabled(false);
    viewer.setBackgroundColor(0x000000);
    viewer.clearCache(true);
    viewer.setFocusable(false);

    viewer.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {}

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {}

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
          }
        });
  }
Example #10
0
  @SuppressLint({"NewApi", "SetJavaScriptEnabled"})
  private void loadWebView() {
    // 实例化WebView对象
    // webview = new MyWebView(WebViewActivity.this);
    LogUtil.i(TAG, "loadWebView===实例化WebView===");
    webview = (MyWebView) findViewById(R.id.id_webview);
    new MobclickAgentJSInterface(this, webview);

    WebSettings webSettings = webview.getSettings();
    // 设置WebView属性,能够执行Javascript脚本
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    //
    webSettings.setUseWideViewPort(true); // 关键点
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAppCacheEnabled(true);

    webSettings.setAppCacheMaxSize(8 * 1024 * 1024); // 8MB
    // webSettings.setAppCachePath(Constants.WEBVIEW_CACHE_DIR );
    String appCacheDir =
        this.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
    webSettings.setAppCachePath(appCacheDir);
    webSettings.setAllowFileAccess(true);
    webSettings.setDomStorageEnabled(true);

    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

    // js调用安卓方法
    webview.addJavascriptInterface(this, "RedirectListner");
  }
Example #11
0
  /**
   * @author lijing
   * @time 2014-7-22 下午3:31:38
   */
  private void initInfo() {
    webview = (WebView) layout.findViewById(R.id.webview);

    WebSettings webSettings = webview.getSettings(); // webView: 类WebView的实例
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setSupportZoom(true);
    // webSettings.setBuiltInZoomControls(true);
    webSettings.setLoadWithOverviewMode(true);

    webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // 就是这句
    pb = (ProgressBar) layout.findViewById(R.id.pb);
    pb.setMax(100);
    if (TextUtils.isEmpty(url)) return;
    webview.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
    webview.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            pb.setProgress(newProgress);
            if (newProgress == 100) {
              pb.setVisibility(View.GONE);
            }
            super.onProgressChanged(view, newProgress);
          }
        });
    webview.loadUrl(url);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_webview);

    mWebView = (WebView) findViewById(R.id.webview);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);

    mWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (URLUtil.isNetworkUrl(url)) {
              if (mLoadingProgressBar != null) {
                mLoadingProgressBar.setVisibility(View.VISIBLE);
                mLoadingProgressBar.startAnimation(
                    AnimationUtils.loadAnimation(WebViewActivity.this, R.anim.abc_fade_in));
              }
              view.loadUrl(url);
            } else {
              // Otherwise allow the OS to handle things like tel, mailto, etc.
              Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
              startActivity(intent);
            }
            return true;
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            if (mLoadingProgressBar != null) {
              mLoadingProgressBar.setVisibility(View.GONE);
              mLoadingProgressBar.startAnimation(
                  AnimationUtils.loadAnimation(WebViewActivity.this, R.anim.abc_fade_out));
            }
          }
        });

    Intent intent = getIntent();
    if (intent != null) {
      String url = intent.getStringExtra(DATA_URL);
      if (URLUtil.isNetworkUrl(url)) {
        mWebView.loadUrl(url);
      }

      String title = intent.getStringExtra(DATA_TITLE);
      if (!TextUtils.isEmpty(title)) {
        setTitle(title);
      }
    }

    mLoadingProgressBar = getToolbar().findViewById(R.id.toolbar_progress_bar);
    mLoadingProgressBar.setVisibility(View.VISIBLE);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_innerweb);
    ButterKnife.bind(this);

    StatusBarHelper.setStatusBar(this);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    WebSettings webSettings = wbInnerweb.getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSaveFormData(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    wbInnerweb.requestFocus();
    wbInnerweb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

    wbInnerweb.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.indexOf("tel:") < 0) {
              view.loadUrl(url);
            }
            return true;
          }

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            pbLoading.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            pbLoading.setVisibility(View.GONE);
            wbInnerweb.setVisibility(View.VISIBLE);
            super.onPageFinished(view, url);
          }
        });

    mUrl = getIntent().getStringExtra(PARAM_WEB_URL);
    wbInnerweb.loadUrl(mUrl);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_show_webview);

    String title = this.getIntent().getStringExtra("title");
    String url = this.getIntent().getStringExtra("url");

    backBtn = (Button) this.findViewById(R.id.backBtn);
    backBtn.setOnClickListener(this);

    shareBtn = (Button) this.findViewById(R.id.shareBtn);
    shareBtn.setOnClickListener(this);

    // 是否显示分享,默认不显示
    boolean showShareBtn = this.getIntent().getBooleanExtra("SHOW_SHARE", false);
    shareBtn.setVisibility(showShareBtn ? View.VISIBLE : View.GONE);

    titleTextView = (TextView) this.findViewById(R.id.titleTextView);
    titleTextView.setText(title);

    webView = (NoZoomControllWebView) this.findViewById(R.id.webview);
    WebSettings setting = webView.getSettings();

    setting.setJavaScriptEnabled(true);
    setting.setJavaScriptCanOpenWindowsAutomatically(true);

    setting.setSupportZoom(true);
    setting.setLoadsImagesAutomatically(true);

    setting.setBuiltInZoomControls(true);

    setting.setUseWideViewPort(true);
    setting.setLoadWithOverviewMode(true);
    setting.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);

    webView.loadUrl(url);

    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
  }
Example #15
0
  public synchronized void initPreferences() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    WebSettings webSettings = getSettings();

    webSettings.setLoadWithOverviewMode(true);
    webSettings.setTextZoom(100);
    webSettings.setUseWideViewPort(true);

    webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true));
    webSettings.setJavaScriptEnabled(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setJavaScriptCanOpenWindowsAutomatically(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true));
    webSettings.setSupportMultipleWindows(
        sp.getBoolean(context.getString(R.string.sp_multiple_windows), false));
    webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true));

    boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true);
    if (textReflow) {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
          webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        } catch (Exception e) {
        }
      }
    } else {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    }

    int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0"));
    if (userAgent == 1) {
      webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP);
    } else if (userAgent == 2) {
      webSettings.setUserAgentString(
          sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal));
    } else {
      webSettings.setUserAgentString(userAgentOriginal);
    }

    int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0"));
    initRendering(mode);

    webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true));
  }
Example #16
0
  @SuppressLint({"InflateParams", "SetJavaScriptEnabled"})
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.frag_home, null);
    webview = (WebView) view.findViewById(R.id.webView1_home);
    cookies = new ArrayList<Cookie>();
    WebSettings ws = webview.getSettings();
    ws.setJavaScriptEnabled(true);
    ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    ws.setSupportZoom(true);
    ws.setBuiltInZoomControls(true);
    ws.setUseWideViewPort(true);
    ws.setLoadWithOverviewMode(true);

    // ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webview.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    webview.setOnKeyListener(
        new OnKeyListener() {

          @Override
          public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
            if ((arg1 == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
              webview.goBack();
              return true;
            }
            return false;
          }
        });

    setCookie(getActivity().getApplicationContext());
    webview.loadUrl(devbaseURL + "?app-default");
    return view;
  }
Example #17
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView");

    // Inflate layout of the dialog
    View rootView =
        inflater.inflate(
            R.layout.sso_dialog,
            container,
            false); // null parent view because it will go in the dialog layout
    mSsoWebView = (WebView) rootView.findViewById(R.id.sso_webview);

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    if (savedInstanceState == null) {
      Log_OC.d(TAG, "   initWebView start");
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.setAcceptCookie(true);
      cookieManager.removeAllCookie();
      mSsoWebView.loadUrl(mInitialUrl);

    } else {
      Log_OC.d(TAG, "   restoreWebView start");
      WebBackForwardList history =
          mSsoWebView.restoreState(savedInstanceState.getBundle(KEY_WEBVIEW_STATE));
      if (history == null) {
        Log_OC.e(TAG, "Error restoring WebView state ; back to starting URL");
        mSsoWebView.loadUrl(mInitialUrl);
      }
    }

    WebSettings webSettings = mSsoWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setSavePassword(false);
    webSettings.setUserAgentString(WebdavClient.USER_AGENT);
    webSettings.setSaveFormData(false);

    return rootView;
  }
Example #18
0
  @SuppressLint("SetJavaScriptEnabled")
  private void initUI() {
    showLoading();
    mContentWebView = (WebView) getView().findViewById(R.id.webview_content);

    WebSettings settings = mContentWebView.getSettings();
    // 设置支持JavaScript
    settings.setJavaScriptEnabled(true);
    // 设置不缓存
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    if (isSupportZoomByRatio()) {
      // 支持缩放
      settings.setSupportZoom(true);
      settings.setBuiltInZoomControls(true);
      settings.setDisplayZoomControls(false);
      // 按比例缩放
      settings.setUseWideViewPort(true);
      // 自适应屏幕
      settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
      settings.setLoadWithOverviewMode(true);
    }

    // 在本地WebView中加载网页
    mContentWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            hideLoading();
          }
        });

    String url = getUrl();
    mContentWebView.loadUrl(url);
  }
Example #19
0
  void init() {
    setWebViewClient(new LoveClient());
    setWebChromeClient(new Chrome());
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSaveFormData(false);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setUseWideViewPort(true);

    /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (BuildConfig.DEBUG) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }*/
  }
  private void loadWebViewContent() {
    // TODO Auto-generated method stub
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    // 启用支持javascript
    webSettings.setJavaScriptEnabled(true);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    // WebView加载web资源
    mWebView.loadUrl("http://www.baidu.com/");
    // 覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开
    mWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            // 返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
            view.loadUrl(url);
            return true;
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (progressDialog != null) {
              progressDialog.dismiss();
              progressDialog = null;
            }
          }

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            if (progressDialog != null) {
              progressDialog.show();
            }
          }
        });
  }
Example #21
0
 private void setWebView() {
   WebSettings settings = wvIt.getSettings();
   settings.setDomStorageEnabled(true);
   settings.setAppCacheEnabled(true);
   settings.setJavaScriptEnabled(true);
   settings.setPluginState(WebSettings.PluginState.ON);
   settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
   settings.setDomStorageEnabled(true);
   settings.setDatabaseEnabled(true);
   settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache");
   settings.setAppCacheEnabled(true);
   settings.setLoadWithOverviewMode(true);
   wvIt.setWebViewClient(
       new WebViewClient() {
         @Override
         public boolean shouldOverrideUrlLoading(WebView view, String url) {
           view.loadUrl(url);
           return true;
         }
       });
   wvIt.setWebChromeClient(
       new WebChromeClient() {
         @Override
         public void onProgressChanged(WebView view, int newProgress) {
           if (pbWeb != null) { // 修复未加载完成,用户返回会崩溃
             if (newProgress == 100) {
               pbWeb.setVisibility(View.GONE);
             } else {
               if (pbWeb.getVisibility() == View.GONE) {
                 pbWeb.setVisibility(View.VISIBLE);
               }
               pbWeb.setProgress(newProgress);
             }
           }
           super.onProgressChanged(view, newProgress);
         }
       });
 }
Example #22
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_web);
   ButterKnife.bind(this);
   mToolbar.setTitle(mTitle);
   setSupportActionBar(mToolbar);
   ActionBar actionBar = getSupportActionBar();
   if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
   mUrl = getIntent().getStringExtra(EXTRA_URL);
   mTitle = getIntent().getStringExtra(EXTRA_TITLE);
   mWebView = new WebView(getApplicationContext());
   mRelativeLayout.addView(mWebView);
   WebSettings settings = mWebView.getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setLoadWithOverviewMode(true);
   settings.setAppCacheEnabled(true);
   settings.setSupportZoom(true);
   settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
   mWebView.setWebChromeClient(new ChromeClient());
   mWebView.setWebViewClient(new ViewClient());
   mWebView.loadUrl(mUrl);
 }
Example #23
0
 public ag(@NonNull Context context, String str, String str2) {
   super(context, WebDialog.DEFAULT_THEME);
   getWindow().setLayout(al.m9262a(context), al.m9285b(context));
   getWindow().setWindowAnimations(R.style.dialog_up_down_animation);
   setContentView(R.layout.view_web_dialog);
   findViewById(R.id.view_back_icon).setOnClickListener(this);
   TextView textView = (TextView) findViewById(R.id.view_back_title);
   textView.setText(str2);
   textView.setOnClickListener(this);
   this.f4433a = (WebView) findViewById(R.id.web_dialog_webview);
   if (!al.m9276a()) {
     this.f4433a.setLayerType(1, null);
   }
   this.f4433a.setScrollBarStyle(33554432);
   WebSettings settings = this.f4433a.getSettings();
   settings.setLoadWithOverviewMode(true);
   settings.setJavaScriptEnabled(true);
   settings.setBuiltInZoomControls(true);
   settings.setUserAgentString(C2239e.f3684a);
   this.f4433a.setWebViewClient(new C24621(this));
   this.f4433a.loadUrl(str);
   this.f4434b = Uri.parse(str).getHost();
 }
Example #24
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.news);

    ((Button) findViewById(R.id.button1))
        .setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View arg0) {
                // TODO Auto-generated method stub
                finish();
              }
            });
    progress = (ProgressBar) findViewById(R.id.progressBar1);
    progress.setVisibility(View.GONE);
    web = (WebView) findViewById(R.id.webview01);
    WebSettings webSettings = web.getSettings();

    final Activity activity = this;
    web.setWebChromeClient(
        new WebChromeClient() {
          public void onProgressChanged(WebView view, int progress) {

            activity.setProgress(progress * 1000);
          }
        });

    web.setWebViewClient(new myWebClient());
    web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl("http://instagram.com/hototwenty");

    webSettings.setLoadWithOverviewMode(true);
  }
Example #25
0
  private void setData(Mp4ba mp4ba) {
    if (null != name && !name.equals("")) {
      name = name.split("\\.")[0];
      tv_head.setText(name);
    }
    String content = mp4ba.getContent();
    webView.setVisibility(View.VISIBLE);
    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDefaultFontSize(16);
    webView.requestFocusFromTouch(); // 支持获取手势焦点
    webView.setWebViewClient(
        new WebViewClient() { // 打开网页时不调用系统浏览器, 而是在本WebView中显示
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
    dialog.cancel();
  }
Example #26
0
 public static void setupWebView(WebView webview) {
   webview.setVerticalScrollbarOverlay(true);
   WebSettings settings = webview.getSettings();
   settings.setLoadWithOverviewMode(true);
   settings.setUseWideViewPort(true);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 根布局参数
    LinearLayout.LayoutParams layoutParamsRoot =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

    // 根布局
    LinearLayout layoutRoot = new LinearLayout(this);
    layoutRoot.setLayoutParams(layoutParamsRoot);
    layoutRoot.setOrientation(LinearLayout.VERTICAL);
    layoutRoot.setBackgroundColor(0xFFF5F5F5);

    webView = new WebView(this);

    LinearLayout.LayoutParams webViewLayoutParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

    layoutRoot.addView(webView, webViewLayoutParams);

    setContentView(layoutRoot);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // 设置可以支持缩放
    webSettings.setSupportZoom(true);
    webSettings.setUseWideViewPort(true);
    // 设置默认加载的可视范围是大视野范围
    webSettings.setLoadWithOverviewMode(true);
    // 设置出现缩放工具
    webSettings.setBuiltInZoomControls(true);

    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 如下方案可在非微信内部WebView的H5页面中调出微信支付
            if (url.startsWith("weixin://wap/pay?")) {
              Intent intent = new Intent();
              intent.setAction(Intent.ACTION_VIEW);
              intent.setData(Uri.parse(url));
              startActivity(intent);

              return true;
            }
            return super.shouldOverrideUrlLoading(view, url);
          }

          @Override
          public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed(); // Ignore SSL certificate errors
          }
        });

    url = getIntent().getStringExtra("url");

    webView.loadUrl(url);
  }
  @Override
  protected void onStart() {
    super.onStart();

    try {
      jsonSrc = FileUtils.readFromAssetsFile(that, "json2.js");
      androidJsSrc = FileUtils.readFromAssetsFile(that, "android.js");
    } catch (IOException e1) {
      throw new RuntimeException(e1);
    }

    mObserver = new HtmlEventObserver();

    // TODO
    // RpcReceiverManager mFacadeManager = getRpcReceiverManager();
    // mFacadeManager.getReceiver(EventFacade.class).addGlobalEventObserver(mObserver);
    // mAPIWrapperSource = generateAPIWrapper();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, config.getLOG_TAG());
    mWebView.setKeepScreenOn(true);

    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    mWebView.setScrollbarFadingEnabled(false);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setScrollContainer(false);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);

    webSettings.setSupportZoom(false);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    mWebView.addJavascriptInterface(mWrapper, "_rpc_wrapper");
    mWebView.addJavascriptInterface(
        new Object() {

          @SuppressWarnings("unused")
          public void register(String event, int id) {
            mObserver.register(event, id);
          }
        },
        "_callback_wrapper");

    if (Build.VERSION.SDK_INT >= 5) {
      try {
        Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[] {Boolean.TYPE});
        m1.invoke(webSettings, Boolean.TRUE);

        Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[] {Boolean.TYPE});
        m2.invoke(webSettings, Boolean.TRUE);

        Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[] {String.class});
        m3.invoke(webSettings, this.getFilesDir().getParent() + "/databases/");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    mWebView.setWebChromeClient(new WebChromeClient() {});

    mWebView.setWebViewClient(
        new WebViewClient() {
          //        	public void onReceivedError(WebView view, int errorCode, String description,
          // String failingUrl) {
          //        		Toast.makeText(that, "Error: " + description, Toast.LENGTH_SHORT).show();
          //        	}
        });

    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);

    if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 14) {
      mWebView.setSystemUiVisibility(WebView.STATUS_BAR_HIDDEN);
    } else if (Build.VERSION.SDK_INT >= 14) {
      mWebView.setSystemUiVisibility(WebView.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }

    mWebView.loadUrl("javascript:" + jsonSrc);
    mWebView.loadUrl("javascript:" + androidJsSrc);
    mWebView.loadUrl("javascript:" + mAPIWrapperSource);
    Log.d(
        config.getLOG_TAG(),
        "Launch Webview: "
            + "file://"
            + this.getFilesDir().getAbsolutePath()
            + "/"
            + config.getMAIN_SCRIPT_NAME());
    mWebView.loadUrl(
        "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME());
  }
Example #29
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final boolean fetchProfile = getIntent().getBooleanExtra("fetchProfile", true);

    final boolean isFacebook = getIntent().getBooleanExtra("isfacebook", false);
    final String photoPath = getIntent().getStringExtra("Photo");
    final String albumName = getIntent().getStringExtra("Album");
    final String addComments = getIntent().getStringExtra("AddComments");
    final String likes = getIntent().getStringExtra("Likes");
    final String unLikes = getIntent().getStringExtra("Unlikes");
    final String photoId = getIntent().getStringExtra("PhotoId");
    final String comments = getIntent().getStringExtra("Comments");

    if (isFacebook) {
      facebook.authorize(
          this,
          new String[] {"user_photos,publish_checkins,publish_actions,publish_stream"},
          new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
              FacebookSocialNetwork socialNetwork =
                  new FacebookSocialNetwork(
                      Phlogit
                          .getPhlogitApplicationContext()); // (FacebookSocialNetwork)SocialNetwork.getProvider(SocialNetwork.SOCIAL_NETWORK_FACEBOOK);
              socialNetwork.setTokens(
                  facebook.getAccessToken(),
                  (values != null ? values.get("id") : null),
                  facebook.getAccessExpires());
              socialNetwork.fetchProfile();
              if (!TextUtils.isEmpty(photoPath)) {
                socialNetwork.uploadPhoto(photoPath, albumName, null);
              } else if ("true".equals(addComments)) {
                socialNetwork.addComment(photoId, comments);
                Toast.makeText(WebViewClientActivity.this, "Comments added", Toast.LENGTH_LONG)
                    .show();
              } else if ("true".equals(likes)) {
                socialNetwork.like(photoId);
                Toast.makeText(WebViewClientActivity.this, "Photo Liked", Toast.LENGTH_LONG).show();
              } else if ("true".equals(unLikes)) {
                socialNetwork.unLike(photoId);
                Toast.makeText(WebViewClientActivity.this, "Photo Unliked", Toast.LENGTH_LONG)
                    .show();
              }
              finish();
            }

            @Override
            public void onCancel() {
              Toast.makeText(WebViewClientActivity.this, "Cancel!", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onFacebookError(FacebookError e) {
              Toast.makeText(WebViewClientActivity.this, "FacebookError " + e, Toast.LENGTH_LONG)
                  .show();
            }

            @Override
            public void onError(DialogError e) {
              Toast.makeText(WebViewClientActivity.this, "Error " + e, Toast.LENGTH_LONG).show();
            }
          });
    } else {
      setContentView(R.layout.webview_activity);

      String authUrl = getIntent().getStringExtra("authUrl");

      webview = (WebView) findViewById(R.id.webview);
      webview.getSettings().setJavaScriptEnabled(true);
      WebSettings websettings = webview.getSettings();
      websettings.setLoadWithOverviewMode(true);

      websettings.setJavaScriptEnabled(true);
      webview.setWebViewClient(
          new WebViewClient() {

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
              handler.proceed();
            }

            @Override
            public void onLoadResource(WebView view, String url) {
              // Twitter
              if (url.startsWith("http://appsforandroid.blogspot.com")) {
                Uri uri = Uri.parse(url);
                String verifier = uri.getQueryParameter("oauth_verifier");
                TwitterSocialNetwork socialNetwork =
                    (TwitterSocialNetwork)
                        SocialNetwork.getProvider(SocialNetwork.SOCIAL_NETWORK_TWITTER);
                socialNetwork.setTokens(verifier);
                socialNetwork.fetchProfile();
                finish();
              }
            }
          });

      webview.loadUrl(authUrl);
    }
  }
Example #30
0
  @SuppressLint("SetJavaScriptEnabled")
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
      // get url and navigatio preference (default true)
      final String url = getIntent().getStringExtra(getPackageName() + ".URL");
      final boolean navigation =
          getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true);

      setContentView(R.layout.webviewnav);

      // if we want navigation bar and not hide it, make it visible. Make it invisible if not.
      if (navigation && !hideNavigationBar) {
        findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE);
      } else {
        findViewById(R.id.webBottomBar).setVisibility(View.GONE);
      }

      mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack);
      mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward);
      mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop);

      mProgressView = (ProgressBar) findViewById(R.id.progressBar);
      mProgressView.setIndeterminate(true);

      // init webview
      mWebView = (WebView) findViewById(R.id.webView);

      // disable hw accel as it creates flickering pages, html5 video won't work with this
      if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16)
        mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

      // This hides white bar on the right
      mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

      WebSettings settings = mWebView.getSettings();
      // enable plugins before java script
      settings.setPluginState(PluginState.ON);

      // TODO test these two settings with a big webpage (cafe lotty?)
      settings.setLoadWithOverviewMode(true);
      settings.setUseWideViewPort(true);
      // enable javascript and zoom controls
      settings.setJavaScriptEnabled(true);
      settings.setBuiltInZoomControls(true);
      settings.setGeolocationEnabled(true);
      settings.setDatabaseEnabled(true);
      String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath();
      settings.setDatabasePath(databasePath);
      settings.setGeolocationDatabasePath(databasePath);
      settings.setDomStorageEnabled(true);
      settings.setAppCacheEnabled(true);

      // allow XMLHttpRequests
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        settings.setAllowUniversalAccessFromFileURLs(true);

      MetaioWebViewClient client = new MetaioWebViewClient();
      mWebView.setWebViewClient(client);
      mWebView.setWebChromeClient(new MetaioWebChromeClient());

      registerForContextMenu(mWebView);

      if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
      } else {

        // if we don't have to override the url, load it in the webview
        if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url);
      }
    } catch (Exception e) {
      MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e);
    }
  }