Exemplo n.º 1
2
  private synchronized void initWebSettings() {

    if (android.os.Build.VERSION.SDK_INT >= 21) WebView.enableSlowWholeDocumentDraw();

    WebSettings webSettings = getSettings();
    userAgentOriginal = webSettings.getUserAgentString();

    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);

    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().toString());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setGeolocationDatabasePath(context.getFilesDir().toString());

    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      webSettings.setLoadsImagesAutomatically(true);
    } else {
      webSettings.setLoadsImagesAutomatically(false);
    }
  }
Exemplo n.º 2
0
 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);
   }
 }
Exemplo n.º 3
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");
  }
 /** * 初始化内容控件 */
 private void initWeb() {
   // TODO Auto-generated method stub
   String release = android.os.Build.VERSION.RELEASE;
   release = release.substring(0, 3);
   if ("4.4".equals(release)) {
     web_content.setWebViewClient(new MyWebViewClient());
   } else {
     web_content.setVisibility(View.VISIBLE);
     WebSettings ws = web_content.getSettings();
     ws.setJavaScriptEnabled(true);
     ws.setAllowFileAccess(true);
     ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
     ws.setDefaultTextEncodingName("utf-8");
     ws.setTextSize(TextSize.NORMAL);
     ws.setAppCacheEnabled(false);
     ws.setDomStorageEnabled(true);
     if (android.os.Build.VERSION.SDK_INT >= 8) {
       ws.setPluginState(PluginState.ON);
     }
     ws.setRenderPriority(RenderPriority.HIGH);
     web_content.setWebViewClient(new WebViewClientDemo());
     web_content.setWebChromeClient(new WebViewChromeClientDemo());
     web_content.loadDataWithBaseURL("", unit.getIntroduce(), "text/html", "utf-8", null);
   }
 }
Exemplo n.º 5
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);
   }*/
 }
  @Override
  public void initComponents() {
    wvUrl = (WebView) innerView.findViewById(R.id.wvUrl);
    WebSettings ws = wvUrl.getSettings();
    ws.setAllowFileAccess(true);
    ws.setAppCacheEnabled(true);
    ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    ws.setBuiltInZoomControls(false);
    ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    ws.setDisplayZoomControls(false);
    ws.setJavaScriptEnabled(true);
    ws.setSupportZoom(false);
    ws.setDefaultTextEncodingName("GBK");

    wvUrl.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            view.post(
                new Runnable() {

                  @Override
                  public void run() {
                    view.loadUrl(url);
                  }
                });
            return false;
          }
        });
    wvUrl.setWebChromeClient(new WebChromeClient());
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_post_content, container, false);
    // View view = inflater.inflate(R.layout.activity_post_single, container, false);
    swipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_post_container);
    swipeRefreshLayout.setAddStatesFromChildren(false);
    // 设置刷新时动画的颜色,可以设置4个
    swipeRefreshLayout.setColorSchemeResources(
        android.R.color.holo_blue_light,
        android.R.color.holo_red_light,
        android.R.color.holo_orange_light,
        android.R.color.holo_green_light);
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {

          @Override
          public void onRefresh() {
            // Toast.makeText(getApplication(), "正在刷新", Toast.LENGTH_SHORT);
            // TODO Auto-generated method stub
            new Handler()
                .postDelayed(
                    new Runnable() {

                      @Override
                      public void run() {
                        // TODO Auto-generated method stub
                        //   Toast.makeText(getApplication(), "刷新完成", Toast.LENGTH_SHORT);
                        swipeRefreshLayout.setRefreshing(false);
                      }
                    },
                    3000);
          }
        });

    postContentView = ((WebView) rootView.findViewById(R.id.post_Content));
    WebSettings Settings = postContentView.getSettings();
    Settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    Settings.setJavaScriptEnabled(true);
    Settings.setAllowFileAccess(true);
    mWebView = new MappingWebView(postContentView);
    // postContentView.addJavascriptInterface(mWebView, "JwebView");
    postContentView.addJavascriptInterface(this, "shareButton");

    basehtml = LocalFileReader.getFromAssets("index.html", getContext());

    String iniHtml =
        basehtml.replaceAll(contentReplace, "<div style=\"text-align:center\">文章加载中,请稍候……</div>");

    postContentView.loadDataWithBaseURL(null, iniHtml, "text/html", "utf-8", null);
    postContentView.setWebViewClient(new BYBlogWebViewClient(getContext()));
    SinglePostRequstAsyncTask task = new SinglePostRequstAsyncTask(1586, "王柏元的博客", "王柏元", "");
    task.execute("?ope=getPostContent&postid=" + postid);
    if (BYBlog.speaker == null) BYBlog.speaker = new TextToSpeech(getActivity(), null);

    //        }

    return rootView;
  }
Exemplo n.º 8
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(final Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_reader);

    final int apiVersion = android.os.Build.VERSION.SDK_INT;
    if (apiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      getActionBar().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
      getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.WHITE));
    }

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

    if (TextUtils.isEmpty(syndicationName)) {
      getActionBar().setTitle(Html.fromHtml("<b><u>" + getTitle().toString() + "</u><b>"));
    } else {
      getActionBar().setTitle(Html.fromHtml("<b><u>" + syndicationName + "</u><b>"));
    }

    publicationTitle = getIntent().getStringExtra("title");
    if (!TextUtils.isEmpty(publicationTitle)) {
      final TextView tv = (TextView) findViewById(R.id.reader_title);
      tv.setTypeface(TypeFaceSingleton.getInstance(this).getUserTypeFace(), Typeface.BOLD);

      tv.setText(publicationTitle);
      getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    }

    getActionBar().setBackgroundDrawable(new ColorDrawable(0xeeeeee));
    getActionBar().setStackedBackgroundDrawable(new ColorDrawable(0xeeeeee));

    final String text = getIntent().getStringExtra("read");
    link = getIntent().getStringExtra("link");
    isFavorite = getIntent().getBooleanExtra("isFavorite", false);
    publicationId = getIntent().getIntExtra("publicationId", -1);
    syndicationId = getIntent().getIntExtra("syndicationId", -1);

    final WebView webView = (WebView) findViewById(R.id.reader);
    final WebSettings settings = webView.getSettings();
    settings.setAllowFileAccess(true);
    settings.setDefaultTextEncodingName("utf-8");

    // For enable video
    webView.setWebChromeClient(new WebChromeClient());

    settings.setJavaScriptEnabled(true);

    settings.setDefaultFontSize(
        TypeFaceSingleton.getInstance(getApplicationContext()).getUserFontSize());

    webView.loadDataWithBaseURL(null, getHtmlData(text), "text/html", "utf-8", null);

    publicationRepository = new PublicationRepository(this);
  }
Exemplo n.º 9
0
  private void initWebView() {
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setPluginsEnabled(true);
    settings.setAllowFileAccess(false);
    settings.setPluginState(WebSettings.PluginState.ON);

    webView.setBackgroundColor(0x00000000); // transparent
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebChromeClient(new OpenXAdWebChromeClient());

    addView(webView);
  }
Exemplo n.º 10
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_about_app);
   about = (WebView) findViewById(R.id.about_webview);
   WebSettings webSettings = about.getSettings();
   // 设置WebView属性,能够执行Javascript脚本
   webSettings.setJavaScriptEnabled(true);
   // 设置可以访问文件
   webSettings.setAllowFileAccess(true);
   // 设置支持缩放
   webSettings.setBuiltInZoomControls(true);
   // 设置Web视图
   about.setWebViewClient(new webViewClient());
   // 加载需要显示的网页
   about.loadUrl(
       "http://mp.weixin.qq.com/s?__biz=MzA4ODY3MTU0MQ==&mid=401741723&idx=1&sn=a58c3652f9373edc095a605b64215006#rd");
 }
Exemplo n.º 11
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);
        }
    }*/
  }
  @SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
  private void initWebView() {
    mWebContent = (WebView) findViewById(R.id.news_detail_content);
    customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer);
    mWebViewClient = new CustomWebViewClient();
    mWebContent.setWebViewClient(mWebViewClient);

    mWebChromeClient = new MyWebChromeClient();
    mWebContent.addJavascriptInterface(new JavascriptCallBack(), "Android");
    mWebContent.setWebChromeClient(mWebChromeClient);
    WebSettings settings = mWebContent.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setAppCachePath(AppUtils.getWebCachePath(this));
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDefaultTextEncodingName("UTF-8");
    settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    mWebContent.loadUrl(url);
  }
Exemplo n.º 13
0
  public void init(Context context) {
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);

    settings.setAllowFileAccess(true);

    settings.setAppCacheEnabled(true);

    final HybridInterface hybridInterface = new HybridInterface(this);
    this.addJavascriptInterface(hybridInterface, "hybridAndroid");

    HybridWebViewClient hybridWebViewClient = new HybridWebViewClient();
    hybridWebViewClient.setHybridWebView(this);
    this.setWebViewClient(hybridWebViewClient);

    this.setWebChromeClient(new HybridWebChromeClient());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      if (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
      }
    }
  }
Exemplo n.º 14
0
    public Web(final Loon activity, final WebProcess webProcess, final String url) {

      super(activity);
      this.url = url;
      this.activity = activity;
      // 允许显示滚动条
      this.setHorizontalScrollBarEnabled(true);
      // 清空原有的缓存数据
      this.clearCache(true);
      // 隐藏当前View
      this.setVisible(false);
      // 不要背景图
      java.lang.reflect.Method drawable = null;
      try {
        drawable =
            this.getClass()
                .getMethod("setBackgroundDrawable", android.graphics.drawable.Drawable.class);
        drawable.invoke(this, (android.graphics.drawable.Drawable) null);
      } catch (Exception ex) {
        try {
          drawable =
              this.getClass().getMethod("setBackground", android.graphics.drawable.Drawable.class);
          drawable.invoke(this, (android.graphics.drawable.Drawable) null);
        } catch (Exception e) {

        }
      }
      // 进行细节设置
      webSettings = getSettings();
      // 数据库访问权限开启
      webSettings.setAllowFileAccess(true);
      // 密码保存与Form信息不保存
      // webSettings.setSavePassword(false);
      webSettings.setSaveFormData(false);
      if (!webSettings.getJavaScriptEnabled()) {
        // 响应JavaScript事件
        webSettings.setJavaScriptEnabled(true);
      }
      // 允许JavaScript脚本打开新的窗口
      webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      // 允许自动加载图像资源
      webSettings.setLoadsImagesAutomatically(true);
      // 不支持网页缩放
      webSettings.setSupportZoom(false);

      // 当流程监听存在时
      if (webProcess != null) {
        setWebViewClient(
            new android.webkit.WebViewClient() {

              @Override
              public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
                webProcess.onPageStarted(url, favicon);
                super.onPageStarted(view, url, favicon);
              }

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

              @Override
              public void onLoadResource(android.webkit.WebView view, String url) {
                webProcess.onLoadResource(url);
                super.onLoadResource(view, url);
              }

              @Override
              public boolean shouldOverrideUrlLoading(android.webkit.WebView view, String url) {
                webProcess.shouldOverrideUrlLoading(url);
                return super.shouldOverrideUrlLoading(view, url);
              }

              @Override
              public void onReceivedHttpAuthRequest(
                  android.webkit.WebView view,
                  android.webkit.HttpAuthHandler handler,
                  String host,
                  String realm) {
                webProcess.onReceivedHttpAuthRequest(handler, host, realm);
                super.onReceivedHttpAuthRequest(view, handler, host, realm);
              }
            });
      }

      // 加载进度条
      final android.widget.ProgressBar progress = new android.widget.ProgressBar(activity);
      activity.addView(progress, AndroidLocation.CENTER);
      setWebChromeClient(
          new android.webkit.WebChromeClient() {
            @Override
            public void onProgressChanged(
                final android.webkit.WebView view, final int newProgress) {
              Loon.self.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      progress.setProgress(newProgress);
                      progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                      if (newProgress == 100) {
                        activity.removeView(progress);
                      }
                      setVisible(newProgress == 100 ? true : false);
                    }
                  });
            }
          });
      if (url != null) {
        loadUrl(url);
      }
    }
Exemplo n.º 15
0
  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);
  }
Exemplo n.º 16
0
  public LGameWeb(
      final LGameAndroid2DActivity activity, final WebProcess webProcess, final String url) {

    super(activity);
    this.url = url;
    this.activity = activity;
    // 允许显示滚动条
    this.setHorizontalScrollBarEnabled(true);
    // 清空原有的缓存数据
    this.clearCache(true);
    // 隐藏当前View
    this.setVisible(false);
    // 不要背景图
    this.setBackgroundDrawable(null);
    // 进行细节设置
    webSettings = getSettings();
    // 数据库访问权限开启
    webSettings.setAllowFileAccess(true);
    // 密码保存与Form信息不保存
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    // 响应JavaScript事件
    webSettings.setJavaScriptEnabled(true);
    // 允许JavaScript脚本打开新的窗口
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    // 允许自动加载图像资源
    webSettings.setLoadsImagesAutomatically(true);
    // 不支持网页缩放
    webSettings.setSupportZoom(false);

    // 当流程监听存在时
    if (webProcess != null) {
      setWebViewClient(
          new WebViewClient() {

            public void onPageStarted(WebView view, String url, Bitmap favicon) {
              webProcess.onPageStarted(url, favicon);
              super.onPageStarted(view, url, favicon);
            }

            public void onPageFinished(WebView view, String url) {
              webProcess.onPageFinished(url);
              super.onPageFinished(view, url);
            }

            public void onLoadResource(WebView view, String url) {
              webProcess.onLoadResource(url);
              super.onLoadResource(view, url);
            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              webProcess.shouldOverrideUrlLoading(url);
              return super.shouldOverrideUrlLoading(view, url);
            }

            public void onReceivedHttpAuthRequest(
                WebView view, HttpAuthHandler handler, String host, String realm) {
              webProcess.onReceivedHttpAuthRequest(handler, host, realm);
              super.onReceivedHttpAuthRequest(view, handler, host, realm);
            }
          });
    }

    // 加载进度条
    final ProgressBar progress = new ProgressBar(activity);
    activity.addView(progress, Location.CENTER);
    setWebChromeClient(
        new WebChromeClient() {
          public void onProgressChanged(final WebView view, final int newProgress) {
            LSystem.post(
                new Runnable() {
                  public void run() {
                    progress.setProgress(newProgress);
                    progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                    if (newProgress == 100) {
                      activity.removeView(progress);
                    }
                    setVisible(newProgress == 100 ? true : false);
                  }
                });
          }
        });

    if (url != null) {
      loadUrl(url);
    }
  }
Exemplo n.º 17
0
  private void setWebView() {
    webSet = web.getSettings();
    webSet.setSavePassword(false);
    webSet.setAllowFileAccess(false);
    webSet.setJavaScriptEnabled(true);
    webSet.setSaveFormData(false);
    webSet.setSupportZoom(true);
    webSet.setBuiltInZoomControls(true);
    webSet.setCacheMode(WebSettings.LOAD_NO_CACHE);
    layout.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);

    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    web.setWebChromeClient(
        new WebChromeClient() { // 设置网页加载的进度条
          public void onProgressChanged(WebView view, int newProgress) {
            if (dialog_flag == true) {
              _showLoading();
              dialog_flag = false;
            }
            if (newProgress == 100) {
              dismissLoading();
              dialog_flag = true;
            }
          }

          // 设置应用程序的标题
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
          }
        });
    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    /*
     *
     * URL = ztspeechandroid://OAuthActivity?oauth_token=
     * f11203c98d813b227204254e3c148884&oauth_verifier=871525
     */
    web.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            LogInfo.LogOut(TAG, "WebView onPageStarted...");
            LogInfo.LogOut(TAG, "URL = " + url);
            if (url != null) {
              if (url.indexOf("checkType=verifycode") != -1) {
                int start = url.indexOf("checkType=verifycode&v=") + 23;
                String verifyCode = url.substring(start, start + 6);
                oAuth.setOauthVerifier(verifyCode);
                view.destroyDrawingCache();
                handler.sendMessage(
                    Message.obtain(
                        handler, ZtspeechWeiboManager.CONSTENT_TENCENT_WEIBO_REGIST, oAuth));
              } else if (url.contains("ztspeechandroid")) {
                // handler.sendMessage(Message.obtain(handler,
                // ZtspeechWeiboManager.CONSTENT_SINA_WEIBO_REGIST,
                // url));
              }
            }
            super.onPageStarted(view, url, favicon);
          }
        });
  }