Esempio n. 1
0
  protected static void clearTraces() {
    CustomWebView WV = (CustomWebView) webLayout.findViewById(R.id.browser_page);
    if (WV != null) {
      WV.clearHistory();
      WV.clearCache(true);
    }

    WebViewDatabase wDB = WebViewDatabase.getInstance(activity);
    wDB.clearFormData();

    CookieSyncManager.createInstance(activity);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    // Usefull for future commits:
    //			cookieManager.setAcceptCookie(false)
    //
    //			WebView webview = new WebView(this);
    //			WebSettings ws = webview.getSettings();
    //			ws.setSaveFormData(false);
    //			ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecat
  }
Esempio n. 2
0
  public void browserActionClicked(View v) {
    Handler handler = new Handler();
    Runnable r =
        new Runnable() {
          public void run() {
            contentView.closeDrawers();
          }
        };
    if (v.getId() != R.id.browser_bookmark) handler.postDelayed(r, 500);

    if (webWindows.size() == 0) {
      webWindows.add(new CustomWebView(MainActivity.this, null, null));
      ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews();
      ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).addView(webWindows.get(0));
    }

    Message msg = new Message();
    final CustomWebView WV = (CustomWebView) webLayout.findViewById(R.id.browser_page);
    switch (v.getId()) {
      case R.id.browser_home:
        WV.loadUrl(mPrefs.getString("browserhome", assetHomePage));
        WV.clearHistory();
        break;
      case R.id.browser_share:
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Link");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, WV.getUrl());
        startActivity(
            Intent.createChooser(sharingIntent, getResources().getString(R.string.share)));
        break;
      case R.id.browser_back:
        WV.goBack();
        break;
      case R.id.browser_forward:
        WV.goForward();
        break;
      case R.id.browser_refresh:
        if (WV.getProgress() != 100) WV.stopLoading();
        else WV.reload();
        break;
      case R.id.browser_bookmark:
        ImageButton BI = (ImageButton) MainActivity.bar.findViewById(R.id.browser_bookmark);
        // Find out if already a bookmark
        String url = WV.getUrl();
        if (WV != null && url != null) {
          String bookmarkName =
              BookmarksActivity.bookmarksMgr.root.containsBookmarkDeep(WV.getUrl());

          if (bookmarkName != null) {
            BookmarksActivity.bookmarksMgr.root.removeBookmarkDeep(bookmarkName);
            BI.setImageResource(R.drawable.btn_omnibox_bookmark_normal);
            System.out.println("BOOKMARK REMOVED!!");
          } else {
            Bookmark newBookmark = new Bookmark(url, WV.getTitle());

            try {
              Bitmap b = WV.getFavicon();
              if (b.getRowBytes() > 1) {
                new File(getApplicationInfo().dataDir + "/icons/").mkdirs();
                URL wvURL = new URL(url);
                String pathToFavicon = getApplicationInfo().dataDir + "/icons/" + wvURL.getHost();
                FileOutputStream out = new FileOutputStream(pathToFavicon);
                WV.getFavicon().compress(Bitmap.CompressFormat.PNG, 100, out);
                out.flush();
                out.close();
                Log.d("LB", "FAVICON SAVED AT " + pathToFavicon + "BITMAP IS " + b);
                newBookmark.setPathToFavicon(pathToFavicon);
              } else {

              }
            } catch (Exception e) {
              e.printStackTrace();
            }
            ;

            BookmarksActivity.bookmarksMgr.root.addBookmark(newBookmark);
            BI.setImageResource(R.drawable.btn_omnibox_bookmark_selected_normal);
            System.out.println("BOOKMARK SET!!");
          }

          BookmarksActivity.bookmarksMgr.saveBookmarksManager();
          CustomToolbar.colorizeToolbar(
              toolbar, Properties.appProp.primaryIntColor, MainActivity.activity);
        }
        break;
      case R.id.browser_find_on_page:
        actionBarControls.show();
        actionBarControls.lock(true);
        SetupLayouts.setUpFindBar();
        setUpFindBarListeners();
        suggestionsAdapter = null;
        // Focus on Find Bar
        TextView findText = (TextView) bar.findViewById(R.id.find_searchbar);
        findText.requestFocus();
        imm.showSoftInput(findText, InputMethodManager.SHOW_IMPLICIT);
        break;
      case R.id.browser_open_bookmarks:
        startActivity(new Intent(ctxt, BookmarksActivity.class));
        break;
      case R.id.browser_set_home:
        mPrefs.edit().putString("browserhome", WV.getUrl()).commit();
        msg.obj = WV.getTitle() + " set";
        msg.what = 1;
        messageHandler.sendMessage(msg);
        break;

      case R.id.browser_settings:
        if (mNotificationManager != null) mNotificationManager.cancel(1);
        startActivity(new Intent(ctxt, SettingsV2.class));
        onStop();
        android.os.Process.killProcess(android.os.Process.myPid());
        break;
      case R.id.browser_exit:
        doExiting();
        break;
      case R.id.browser_toggle_desktop:
        mGlobalPrefs
            .edit()
            .putBoolean("usedesktopview", !Properties.webpageProp.useDesktopView)
            .commit();
        Properties.webpageProp.useDesktopView = !Properties.webpageProp.useDesktopView;

        for (int I = 0; I < webWindows.size(); I++) {
          if (Properties.webpageProp.useDesktopView) {
            webWindows
                .get(I)
                .getSettings()
                .setUserAgentString(webWindows.get(I).createUserAgentString("desktop"));
            webWindows.get(I).getSettings().setLoadWithOverviewMode(true);
          } else {
            webWindows
                .get(I)
                .getSettings()
                .setUserAgentString(webWindows.get(I).createUserAgentString("mobile"));
            webWindows.get(I).getSettings().setLoadWithOverviewMode(false);
          }
          webWindows.get(I).reload();
        }
        break;
    }
  }