Ejemplo n.º 1
0
 /**
  * 清除缓存 private void clearCache() { File file = CacheManager.getCacheFileBaseDir(); if
  * (file.exists()) { if (file.isFile()) { file.delete(); } else { File[] files = file.listFiles();
  * if (files != null && files.length != 0) for (File f : files) { deleteFile(f); } file.delete();
  * } } webView.clearCache(true); webView.clearHistory(); webView.clearFormData();
  * this.deleteDatabase("webview.db"); this.deleteDatabase("webviewCache.db"); } private boolean
  * deleteFile(File file) { if (file == null) return false; if (file.isFile()) { return
  * file.delete(); } else { File[] files = file.listFiles(); if (files != null && files.length !=
  * 0) for (File f : files) { if (!deleteFile(f)) { return false; } } file.delete(); } return true;
  * }
  */
 public void clearCache() {
   if (contentWebView != null) {
     contentWebView.clearCache(true);
   }
   if (toolbarWebView != null) {
     toolbarWebView.clearCache(true);
   }
 }
Ejemplo n.º 2
0
 void forceClearCache() {
   Log.v(LOGTAG, "forceClearCache....");
   for (Tab t : mTabs) {
     Log.v(LOGTAG, "force Clear Cache ID: " + t.getId());
     final WebView webview = t.getWebView();
     if (webview != null) {
       webview.clearCache(true);
     }
     final WebView subview = t.getSubWebView();
     if (subview != null) {
       subview.clearCache(true);
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * Creates the root view of the fragement, set title, the version number and the listener for the
   * download button.
   *
   * @return The fragment's root view.
   */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = getLayoutView();

    versionHelper = new VersionHelper(versionInfo.toString(), this);

    TextView nameLabel = (TextView) view.findViewById(UpdateView.NAME_LABEL_ID);
    nameLabel.setText(getAppName());

    TextView versionLabel = (TextView) view.findViewById(UpdateView.VERSION_LABEL_ID);
    versionLabel.setText(
        "Version " + versionHelper.getVersionString() + "\n" + versionHelper.getFileInfoString());

    Button updateButton = (Button) view.findViewById(UpdateView.UPDATE_BUTTON_ID);
    updateButton.setOnClickListener(this);

    WebView webView = (WebView) view.findViewById(UpdateView.WEB_VIEW_ID);
    webView.clearCache(true);
    webView.destroyDrawingCache();
    webView.loadDataWithBaseURL(
        Constants.BASE_URL, versionHelper.getReleaseNotes(), "text/html", "utf-8", null);

    return view;
  }
Ejemplo n.º 4
0
 @Override
 public boolean onMenuItemClick(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_reset_webview:
       if (mWebView != null) {
         ViewGroup container = getContainer();
         container.removeView(mWebView);
         mWebView.destroy();
         mWebView = null;
       }
       createAndInitializeWebView();
       return true;
     case R.id.menu_clear_cache:
       if (mWebView != null) {
         mWebView.clearCache(true);
       }
       return true;
     case R.id.menu_about:
       about();
       hideKeyboard(mUrlBar);
       return true;
     default:
       return false;
   }
 }
Ejemplo n.º 5
0
  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;
          }
        });
  }
  // ------------------------------------------------------------------------------------------
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register_twitter_account);

    // Find And Initial Views
    webView = (WebView) findViewById(R.id.web_view);

    CookieSyncManager.createInstance(this);
    CookieManager cm = CookieManager.getInstance();
    cm.removeSessionCookie();
    // Web View
    webView.setWebViewClient(
        new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            webView.loadUrl(url);
            return true;
          }
        });
    webView.clearCache(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.clearHistory();
    webView.clearFormData();

    pinCode = (TextView) findViewById(R.id.pin_text);

    tableImage = (LinearLayout) findViewById(R.id.tableImage);
    finish = (Button) findViewById(R.id.finish_button);
    number0 = (Button) findViewById(R.id.Button00);
    number1 = (Button) findViewById(R.id.Button01);
    number2 = (Button) findViewById(R.id.Button02);
    number3 = (Button) findViewById(R.id.Button03);
    number4 = (Button) findViewById(R.id.Button04);
    number5 = (Button) findViewById(R.id.Button05);
    number6 = (Button) findViewById(R.id.Button06);
    number7 = (Button) findViewById(R.id.Button07);
    number8 = (Button) findViewById(R.id.Button08);
    number9 = (Button) findViewById(R.id.Button09);
    cancel = (Button) findViewById(R.id.ButtonCancel);

    message = pinCode.getText().toString();

    tableImage.setVisibility(View.GONE);

    // Set Listener
    pinCode.setOnClickListener(this);
    finish.setOnClickListener(this);
    number0.setOnClickListener(this);
    number1.setOnClickListener(this);
    number2.setOnClickListener(this);
    number3.setOnClickListener(this);
    number4.setOnClickListener(this);
    number5.setOnClickListener(this);
    number6.setOnClickListener(this);
    number7.setOnClickListener(this);
    number8.setOnClickListener(this);
    number9.setOnClickListener(this);
    cancel.setOnClickListener(this);
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  @Test
  public void shouldRecordClearCacheWithDiskFiles() {
    assertThat(shadowWebView.wasClearCacheCalled()).isFalse();

    webView.clearCache(true);
    assertThat(shadowWebView.wasClearCacheCalled()).isTrue();
    assertThat(shadowWebView.didClearCacheIncludeDiskFiles()).isTrue();
  }
Ejemplo n.º 9
0
 @Override
 protected void prepareDataForContentView() {
   WebView webView = (WebView) findViewById(R.id.gek_about_html);
   webView.clearCache(true);
   webView.clearHistory();
   //		webView.loadData(this.content, "text/html", "UTF-8");
   webView.loadUrl("file:///android_asset/" + htmlTemplate);
 }
Ejemplo n.º 10
0
 private void initWebView(String url) {
   WebView authorizationView = (WebView) findViewById(R.id.third_partyWebView);
   authorizationView.clearCache(true);
   authorizationView.getSettings().setJavaScriptEnabled(true);
   authorizationView.getSettings().setSupportZoom(true);
   authorizationView.getSettings().setBuiltInZoomControls(true);
   authorizationView.setWebViewClient(new WebViewC());
   authorizationView.loadUrl(url);
 }
Ejemplo n.º 11
0
 public void clear() {
   //        WebStorage webStorage = WebStorage.getInstance();
   //        webStorage.deleteAllData();
   deleteDatabase("webview.db");
   deleteDatabase("webviewCache.db");
   webView.clearCache(true);
   webView.clearHistory();
   clearCache(getCacheDir().toString());
 }
Ejemplo n.º 12
0
  public WebView createWebView() {
    WebView view = new WebView(this);
    mWebSettings.setWebSettings(view);
    view.setWebChromeClient(mChromeClient);
    view.setWebViewClient(mWebViewClient);
    view.clearCache(true);

    return view;
  }
Ejemplo n.º 13
0
  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (webViewer != null) {
      webViewer.setVisibility(View.GONE);
      webViewer.clearCache(true);
      webViewer.clearHistory();
      webViewer.destroy();
    }
  }
Ejemplo n.º 14
0
  private void initContentView() {
    mWvOauth = (WebView) findViewById(R.id.wvOauthPage);
    mWvOauth.getSettings().setJavaScriptEnabled(true);
    CookieSyncManager.createInstance(getApplicationContext());
    CookieManager.getInstance().removeAllCookie();
    mWvOauth.clearCache(true);

    mWvOauth.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            SnsLogManager.printD(TAG, "onPageStarted url = " + url);
            if (url.startsWith(mRequest.redirectUrl)) {
              SinaRespOauth soi =
                  new SinaRespOauth(); // SinaResponseParser.parseSinaOauth2Info(url);
              soi.setDataFromJson(url);
              if (soi.isParseJsonSuccess()) {
                SnsLogManager.printD(TAG, "soi.getExpiresIn() = " + soi.getExpiresIn());
                mRequest.prefs.saveOauth2Info(
                    soi.getAccessToken(), soi.getExpiresIn(), soi.getUid());

                mWvOauth.stopLoading();
                if (mRequest instanceof OauthRequest) {
                  ((OauthRequest) mRequest).lisn.onSuccess();
                  finish();
                } else {
                  SinaWeiboService.startWeiboEditActivity(WeiboSinaOauthActivity.this);
                  finishNoRecycle();
                }
              } else {
                // oauth interface expires in or user click webView cancel
                //						finish();
              }
            }
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            if (url.startsWith(SINA_URL_OAUTH2)) {
              dismissLoadingDialog();
            }
          }
        });
    mWvOauth.loadUrl(
        String.format(HttpParams.SINA_URL_OAUTH2_CHECK, mRequest.appKey, mRequest.redirectUrl));
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    webview = (WebView) findViewById(R.id.vkontakteview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.clearCache(true);

    webview.setWebViewClient(new VkontakteWebViewClient());

    CookieSyncManager.createInstance(this);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    String url = Auth.getUrl(Constants.API_ID, Auth.getSettings());
    webview.loadUrl(url);
    progressDialog =
        ProgressDialog.show(LoginActivity.this, "", "Загрузка. Пожалуйста подождите", true);
    progressDialog.setCancelable(true);
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // GoToPanel();

    Access = PreferencesManager.LoadPreferences_Access(this.getApplicationContext());

    if (!Access.IsValid()) // No tenemos un token valido, lo necesitamos
    {
      browser = (WebView) findViewById(R.id.webview);

      browser.getSettings().setJavaScriptEnabled(true);
      browser.addJavascriptInterface(this, "jsNativeInterface");
      browser.loadUrl(LoginInterface.DialogURL);
      browser.clearCache(true);
      browser.setWebViewClient(
          new LoginViewClient()); // Evita que se abra un navegador cuando se produce la carga de
      // otra url
    } else {
      GoToPanel();
    }
  }
Ejemplo n.º 17
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   webView.clearCache(true);
 }
Ejemplo n.º 18
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   mWebView.clearHistory();
   mWebView.clearCache(true);
 }
Ejemplo n.º 19
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   // Saving memory
   mWebView.clearCache(true);
 }
Ejemplo n.º 20
0
 /**
  * ページのロードが終わった時の処理を記述する
  *
  * @param url
  */
 public void onFinishLoadPage(String url) {
   if (url != null) {
     this.urlEditText.setText(url);
     webView.clearCache(false);
   }
 }
Ejemplo n.º 21
0
  private void _showContent(String title, String content) {
    if (!title.equals("")) {
      versename = "pb-" + version + "-" + book.toLowerCase(Locale.US) + "-" + chapter;
    } else {
      versename = "versename";
    }
    copytext = "";
    showView(R.id.share, !copytext.equals(""));
    String context = content;
    // for biblegateway.com
    context =
        context.replaceAll(
            "<span class=\"chapternum\">.*?</span>", "<sup class=\"versenum\">1 </sup>");
    context = context.replaceAll("<span class=\"chapternum mid-paragraph\">.*?</span>", "");
    context =
        context.replaceAll(
            "(<strong>\\D*?(\\d+).*?</strong>)",
            "<span class=\"pb-verse\" title=\"$2\"><a id=\""
                + versename
                + "-$2\"></a><sup>$1</sup></span>");
    context =
        context.replaceAll(
            "<sup(.*?>\\D*?(\\d+).*?)</sup>",
            "<span class=\"pb-verse\" title=\"$2\"><a id=\""
                + versename
                + "-$2\"></a><sup><strong$1</strong></sup></span>");
    if (Locale.getDefault().equals(Locale.SIMPLIFIED_CHINESE)) {
      context = context.replaceAll("「", "“").replaceAll("」", "”");
      context = context.replaceAll("『", "‘").replaceAll("』", "’");
    }

    fontsize = (int) (fontsize * scale);
    if (fontsize > 32) {
      fontsize = 24;
    }

    String body =
        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
    body += "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
    body += "<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
    body +=
        "<meta name=\"viewport\" content=\"target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=2\" />\n";
    body += "<style type=\"text/css\">\n";
    if (font.exists()) {
      body += "@font-face { font-family: 'custom'; src: url('" + font.getAbsolutePath() + "'); }\n";
      body +=
          "body {font-family: 'custom', serif; line-height: 1.4em; font-weight: 100; font-size: "
              + fontsize
              + "pt;}\n";
    } else {
      body +=
          "body {font-family: serif; line-height: 1.4em; font-weight: 100; font-size: "
              + fontsize
              + "pt;}\n";
    }
    body += ".trans {display: none;}\n";
    body += ".wordsofchrist {color: red;}\n";
    body += "h1 {font-size: 2em;}\n";
    body += "h2 {font-size: 1.5em;}\n";
    body += ".selected {" + background + "}\n";
    body += ".highlight {" + background + "}\n";
    body += "</style>\n";
    body += "<title>" + title + "</title>\n";
    body += "<link rel=\"stylesheet\" type=\"text/css\" href=\"reader.css\"/>\n";
    body += "<script type=\"text/javascript\">\n";
    body +=
        String.format(
            "var verse_start=%s, verse_end=%s, versename=\"%s\", search=\"%s\";",
            verse.equals("") ? "-1" : verse,
            end.equals("") ? "-1" : verse,
            versename,
            items != null ? search : "");
    verse = "";
    search = "";
    body += "\n</script>\n";
    body += "<script type=\"text/javascript\" src=\"reader.js\"></script>\n";
    body += "</head>\n<body>\n";
    if (!"".equals(title) && bible.getVersion().endsWith("demo")) {
      String link_market =
          "<a href=\"market://search?q="
              + getString(R.string.bibledatalink)
              + "&c=apps\">market://search?q="
              + getString(R.string.bibledatahuman)
              + "&c=apps</a>";
      body +=
          "<div id=\"pb-demo\">"
              + getString(R.string.noversion, new Object[] {link_market, link_github})
              + "</div>\n";
    }
    body += "<div id=\"content\">\n";
    body += context;
    body += "</div>\n</body>\n</html>\n";
    webview.clearCache(true);
    webview.setInitialScale(100);
    scale = 1.0f;
    webview.loadDataWithBaseURL("file:///android_asset/", body, "text/html", "utf-8", null);
    dismiss();
    /*
    {
        String path = "/sdcard/" + versename + ".html";
        try {
            Log.d("write", path);
            java.io.OutputStream os = new java.io.BufferedOutputStream(new java.io.FileOutputStream(new java.io.File(path)));
            os.write(body.getBytes());
            os.close();
        } catch (Exception e) {
            Log.e("write", path, e);
        }
    }
    */
  }
Ejemplo n.º 22
0
 @Override
 public void onPageFinished(WebView view, String url) {
   setProgressBarIndeterminateVisibility(false);
   view.clearCache(true);
 }
Ejemplo n.º 23
-1
  @SuppressLint({"NewApi", "SetJavaScriptEnabled"})
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // 隐藏actionBar
    // getActionBar().hide();

    bootLayout = (FrameLayout) findViewById(R.id.bootLayout);
    // bootLayout.setVisibility(View.INVISIBLE);
    // logoLayout=(RelativeLayout)findViewById(R.id.logoLayout);
    // 启动LOGO尺寸
    /*bootLogo=(ImageView)findViewById(R.id.bootLogo);
    ViewGroup.LayoutParams para = bootLogo.getLayoutParams();
    para.width = para.height = this.getWindowManager().getDefaultDisplay().getWidth()/2;
    bootLogo.setLayoutParams(para);*/
    /*RelativeLayout.LayoutParams mp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    mp.topMargin =this.getWindowManager().getDefaultDisplay().getHeight()/20;
    logoLayout.setLayoutParams(mp);*/

    mTranslateAnimation =
        new TranslateAnimation(
            0, -this.getWindowManager().getDefaultDisplay().getWidth(), 0, 0); // 移动

    mTranslateAnimation.setDuration(500);
    // mAnimationSet.setFillAfter(true);
    // mTranslateAnimation.setFillAfter(true);
    mTranslateAnimation.setAnimationListener(
        new Animation.AnimationListener() {
          public void onAnimationStart(Animation animation) {}

          public void onAnimationEnd(Animation animation) {
            bootLayout.setVisibility(View.GONE);
          }

          public void onAnimationRepeat(Animation animation) {}
        });
    //
    webView = (WebView) findViewById(R.id.webView);
    // 禁用cache
    webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.clearCache(true);
    webView.destroyDrawingCache();
    // 允许JS
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // 响应JS
    class DemoJavaScriptInterface111 {
      // 是否在Web,用来决定返回键的处理办法
      @JavascriptInterface
      public void Set_IsInWeb(boolean v_) {
        IsInWeb = v_;
        Log.d("JavascriptInterface", new Boolean(v_).toString());
      }
      // web载入完毕
      @JavascriptInterface
      public void LoadOK() {
        Log.d("JavascriptInterface", "LoadOK(");
        Log.d("JavascriptInterface", "AutoUpdateVersion)");
        AutoUpdateVersion(); // 放到下边的动画后边的话,就不会执行,好奇怪
        // bootLayout.startAnimation(mTranslateAnimation);
        // bootLayout.setVisibility(View.INVISIBLE);
        new Thread() {
          public void run() {
            // 发送消息,通知handler在主线程中更新UI
            connectHanlderFive.sendEmptyMessage(0);
          }
        }.start();
        Log.d("JavascriptInterface", "LoadOK)");
      }
    }
    webView.addJavascriptInterface(new DemoJavaScriptInterface111(), "Machine");
    // alert
    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public boolean onJsAlert(
              WebView view,
              String url,
              String message,
              JsResult result) { // Required functionality here
            // return super.onJsAlert(view, url, message, result);
            if (message.length() != 0) {
              AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
              builder.setTitle("").setMessage(message).show();
              result.cancel();
              return true;
            }
            return false;
          }
        });
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 设置点击网页里面的链接还是在当前的webview里跳转
            view.loadUrl(url);
            return true;
          }
        });

    webView.loadUrl("http://m.nzjcy.gov.cn:81/#app");
    // shouldOverrideUrlLoading(webView, "http://m.nzjcy.gov.cn:81/#app");
    // 4.0以后不允许主线程new HttpGet()

    //        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads()
    //                .detectDiskWrites().detectNetwork().penaltyLog().build());
    //        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
    //                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
  }