示例#1
0
 public static void initializeSettings(WebSettings settings, Context context) {
   settings.setJavaScriptEnabled(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   settings.setUserAgentString(settings.getUserAgentString() + DB.USER_AGENT);
   settings.setSupportMultipleWindows(true);
   settings.setSaveFormData(false);
   settings.setSavePassword(false); // 设置为true,系统会弹出AlertDialog确认框
   if (API < 18) {
     settings.setAppCacheMaxSize(Long.MAX_VALUE);
   }
   if (API < 17) {
     settings.setEnableSmoothTransition(true);
   }
   if (API < 19) {
     settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + "/databases");
   }
   settings.setDomStorageEnabled(true);
   settings.setAppCachePath(context.getCacheDir().toString());
   settings.setAppCacheEnabled(true);
   settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
   settings.setGeolocationDatabasePath(context.getCacheDir().getAbsolutePath());
   settings.setAllowFileAccess(true);
   settings.setDatabaseEnabled(true);
   settings.setSupportZoom(true);
   settings.setBuiltInZoomControls(true);
   settings.setDisplayZoomControls(false);
   settings.setAllowContentAccess(true);
   settings.setDefaultTextEncodingName("utf-8");
   /*if (API > 16) {
   	settings.setAllowFileAccessFromFileURLs(false);
   	settings.setAllowUniversalAccessFromFileURLs(false);
   }*/
 }
 private dd(Context context, ab abVar, boolean z, boolean z2, l lVar, db dbVar) {
   super(context);
   this.mg = new Object();
   this.pZ = context;
   this.mF = abVar;
   this.qb = z;
   this.nP = lVar;
   this.mG = dbVar;
   setBackgroundColor(0);
   WebSettings settings = getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setSavePassword(false);
   settings.setSupportMultipleWindows(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   cv.a(context, dbVar.pU, settings);
   if (VERSION.SDK_INT >= 17) {
     cx.a(getContext(), settings);
   } else if (VERSION.SDK_INT >= 11) {
     cw.a(getContext(), settings);
   }
   setDownloadListener(this);
   if (VERSION.SDK_INT >= 11) {
     this.pY = new dg(this, z2);
   } else {
     this.pY = new de(this, z2);
   }
   setWebViewClient(this.pY);
   if (VERSION.SDK_INT >= 14) {
     setWebChromeClient(new dh(this));
   } else if (VERSION.SDK_INT >= 11) {
     setWebChromeClient(new df(this));
   }
   bf();
 }
示例#3
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));
  }
  /** Initialize the WebView options to the ones define by user. */
  public void initializeOptions() {
    WebSettings settings = getSettings();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true));
    settings.setSaveFormData(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true));
    settings.setSavePassword(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true));
    settings.setDefaultZoom(
        ZoomDensity.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString())));
    settings.setUserAgentString(
        prefs.getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT));

    settings.setPluginState(
        PluginState.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_ENABLE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance()
        .setAcceptCookie(prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_COOKIES, true));

    // Technical settings
    // settings.setUseWideViewPort(true);
    settings.setSupportMultipleWindows(true);
    setLongClickable(true);
    setScrollbarFadingEnabled(true);
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setDrawingCacheEnabled(true);

    settings.setAppCacheEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
  }
  public TiUIWebView(TiViewProxy proxy) {
    super(proxy);
    this.isFocusable = true;
    TiWebView webView =
        isHTCSenseDevice()
            ? new TiWebView(proxy.getActivity())
            : new NonHTCWebView(proxy.getActivity());
    webView.setVerticalScrollbarOverlay(true);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportMultipleWindows(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAllowFileAccess(true);
    settings.setDomStorageEnabled(
        true); // Required by some sites such as Twitter. This is in our iOS WebView too.
    File path = TiApplication.getInstance().getFilesDir();
    if (path != null) {
      settings.setDatabasePath(path.getAbsolutePath());
      settings.setDatabaseEnabled(true);
    }

    File cacheDir = TiApplication.getInstance().getCacheDir();
    if (cacheDir != null) {
      settings.setAppCacheEnabled(true);
      settings.setAppCachePath(cacheDir.getAbsolutePath());
    }

    // enable zoom controls by default
    boolean enableZoom = true;

    if (proxy.hasProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
      enableZoom = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS));
    }

    settings.setBuiltInZoomControls(enableZoom);
    settings.setSupportZoom(enableZoom);

    if (TiC.JELLY_BEAN_OR_GREATER) {
      settings.setAllowUniversalAccessFromFileURLs(
          true); // default is "false" for JellyBean, TIMOB-13065
    }

    // We can only support webview settings for plugin/flash in API 8 and higher.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) {
      initializePluginAPI(webView);
    }

    boolean enableJavascriptInterface =
        TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE), true);
    chromeClient = new TiWebChromeClient(this);
    webView.setWebChromeClient(chromeClient);
    client = new TiWebViewClient(this, webView);
    webView.setWebViewClient(client);
    if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) {
      client.getBinding().addJavascriptInterfaces();
    }
    webView.client = client;

    if (proxy instanceof WebViewProxy) {
      WebViewProxy webProxy = (WebViewProxy) proxy;
      String username = webProxy.getBasicAuthenticationUserName();
      String password = webProxy.getBasicAuthenticationPassword();
      if (username != null && password != null) {
        setBasicAuthentication(username, password);
      }
      webProxy.clearBasicAuthentication();
    }

    TiCompositeLayout.LayoutParams params = getLayoutParams();
    params.autoFillsHeight = true;
    params.autoFillsWidth = true;

    setNativeView(webView);
  }
示例#6
0
  private void initView() {
    // findViewById(R.id.btn_return).setOnClickListener(this);
    webView = (WebView) findViewById(R.id.webview);
    btn_showOwner = (Button) findViewById(R.id.btn_showOwner);
    btn_collect = (ImageButton) findViewById(R.id.btn_collectPost);
    btn_reply = (ImageButton) findViewById(R.id.btn_replyPost);
    btn_reward = (ImageButton) findViewById(R.id.btn_rewardPost);
    btn_return = (ImageView) findViewById(R.id.btn_left);
    btn_share = (ImageButton) findViewById(R.id.btn_sharePost);
    reply_layout = (RelativeLayout) findViewById(R.id.rl_reply);
    post_layout = (RelativeLayout) findViewById(R.id.rl_post);
    edt_content = (EditText) findViewById(R.id.edt_reply_Content);
    btn_pic = (ImageButton) findViewById(R.id.btn_addPic);
    mpics = (LinearLayout) findViewById(R.id.ll_piclayer);
    btn_showOwner.setVisibility(View.VISIBLE);

    btn_reward.setOnClickListener(this);
    btn_showOwner.setOnClickListener(this);
    btn_collect.setOnClickListener(this);
    btn_reply.setOnClickListener(this);
    btn_return.setOnClickListener(this);
    btn_share.setOnClickListener(this);
    btn_pic.setOnClickListener(this);
    edt_content.addTextChangedListener(this);

    tv_title = (TextView) findViewById(R.id.tv_title);
    tv_hint = (TextView) findViewById(R.id.tv_lengthHint);
    reply_layout = (RelativeLayout) findViewById(R.id.rl_reply);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setSupportMultipleWindows(true);
    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            // TODO Auto-generated method stub
            super.onProgressChanged(view, newProgress);
            if (0 == newProgress) {
              popupLoadingToast(getString(R.string.onloading_hint));
            }
            if (100 == newProgress) {

              if (null != webView) {
                mHandler.sendMessage(mHandler.obtainMessage(6));
                getParams();
              }
              runOnUiThread(
                  new Runnable() {

                    @Override
                    public void run() {
                      // TODO Auto-generated method stub
                      cancleLodingToast(true);
                    }
                  });
            }
          }
        });
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            // 返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
            Log.e(TAG, "url= " + url);
            view.loadUrl(url);
            return true;
          }
        });
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    addInterface();
  }