diff options
author | Ze G Riande <zriand@codeaurora.org> | 2015-06-03 11:15:24 -0700 |
---|---|---|
committer | jrizzoli <joey@cyanogenmoditalia.it> | 2015-08-28 13:15:45 +0200 |
commit | 2a675c288d856073ebe4139d2fad5299e483165d (patch) | |
tree | 90824a9952cff7dd756aede46059570c2638cc99 /src/com/android/browser | |
parent | 21dad566a57084c8c5eae66909f917ff7c1fd222 (diff) | |
download | android_packages_apps_Gello-2a675c288d856073ebe4139d2fad5299e483165d.tar.gz android_packages_apps_Gello-2a675c288d856073ebe4139d2fad5299e483165d.tar.bz2 android_packages_apps_Gello-2a675c288d856073ebe4139d2fad5299e483165d.zip |
Add reader mode option in popup menu
Reader mode use the DOM distiller to load the distilled version of a webpage
Reader mode is disabled by default and will be available only with the use
of the command line flag "reader-mode"
Change-Id: Ide36057cae4e71b94e8118cc767f600cd610b82e
Diffstat (limited to 'src/com/android/browser')
-rw-r--r-- | src/com/android/browser/Controller.java | 36 | ||||
-rw-r--r-- | src/com/android/browser/NavTabView.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/SnapshotBar.java | 30 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 68 | ||||
-rw-r--r-- | src/com/android/browser/TitleBar.java | 13 |
5 files changed, 147 insertions, 2 deletions
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 5563b627..5c6a9b8d 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -1952,6 +1952,11 @@ public class Controller } else { bookmark_icon.setChecked(false); } + + // update reader mode checkbox + MenuItem readerSwitcher = menu.findItem(R.id.reader_mode_menu_id); + readerSwitcher.setVisible(false); + readerSwitcher.setChecked(false); } @Override @@ -1964,6 +1969,9 @@ public class Controller boolean isLiveScheme = false; boolean isPageFinished = false; boolean isSavable = false; + + boolean isDistillable = false; + boolean isDistilled = false; resetMenuItems(menu); if (tab != null) { @@ -1973,6 +1981,9 @@ public class Controller isLiveScheme = UrlUtils.isLiveScheme(tab.getWebView().getUrl()); isPageFinished = (tab.getPageFinishedStatus() || !tab.inPageLoad()); isSavable = tab.getWebView().isSavable(); + + isDistillable = tab.isDistillable(); + isDistilled = tab.isDistilled(); } final MenuItem forward = menu.findItem(R.id.forward_menu_id); @@ -2001,11 +2012,19 @@ public class Controller setMenuItemVisibility(menu, R.id.add_to_homescreen, isLive && isLiveScheme && isPageFinished); setMenuItemVisibility(menu, R.id.save_snapshot_menu_id, - isLive && isLiveScheme && isPageFinished && isSavable); + isLive && ( isLiveScheme || isDistilled ) && isPageFinished && isSavable); // history and snapshots item are the members of COMBO menu group, // so if show history item, only make snapshots item invisible. menu.findItem(R.id.snapshots_menu_id).setVisible(false); + + // update reader mode checkbox + final MenuItem readerSwitcher = menu.findItem(R.id.reader_mode_menu_id); + // The reader mode checkbox is hidden only + // when the current page is neither distillable nor distilled + readerSwitcher.setVisible(isDistillable || isDistilled); + readerSwitcher.setChecked(isDistilled); + mUi.updateMenuState(tab, menu); } @@ -2154,6 +2173,10 @@ public class Controller toggleUserAgent(); break; + case R.id.reader_mode_menu_id: + toggleReaderMode(); + break; + case R.id.window_one_menu_id: case R.id.window_two_menu_id: case R.id.window_three_menu_id: @@ -2294,6 +2317,17 @@ public class Controller mSettings.toggleDesktopUseragent(web); } + // This function calls the method in the webview to enable/disable + // the reader mode through the DOM distiller + public void toggleReaderMode() { + Tab t = mTabControl.getCurrentTab(); + if (t.isDistilled()) { + closeTab(t); + } else if (t.isDistillable()) { + openTab(t.getDistilledUrl(), false, true, false, t); + } + } + @Override public void findOnPage() { getCurrentTopWebView().showFindDialog(null, true); diff --git a/src/com/android/browser/NavTabView.java b/src/com/android/browser/NavTabView.java index 0fc8dfd7..c79dafca 100644 --- a/src/com/android/browser/NavTabView.java +++ b/src/com/android/browser/NavTabView.java @@ -90,6 +90,8 @@ public class NavTabView extends LinearLayout { } if (mTab.isSnapshot()) { setTitleIcon(R.drawable.ic_suggest_history_normal); + } else if (mTab.isDistilled()) { + setTitleIcon(R.drawable.ic_deco_reader_mode_normal); } else if (mTab.isPrivateBrowsingEnabled()) { mContent.setBackgroundResource(R.drawable.nav_tab_title_incognito); mTitle.setTextColor(getResources().getColor(R.color.white)); diff --git a/src/com/android/browser/SnapshotBar.java b/src/com/android/browser/SnapshotBar.java index d17a3ac4..29f2a902 100644 --- a/src/com/android/browser/SnapshotBar.java +++ b/src/com/android/browser/SnapshotBar.java @@ -47,6 +47,8 @@ public class SnapshotBar extends LinearLayout implements OnClickListener { private static final long DURATION_SHOW_DATE = BaseUi.HIDE_TITLEBAR_DELAY; private ImageView mFavicon; + private ImageView mSnapshoticon; + private ImageView mReadericon; private TextView mDate; private TextView mTitle; private View mBookmarks; @@ -107,6 +109,8 @@ public class SnapshotBar extends LinearLayout implements OnClickListener { protected void onFinishInflate() { super.onFinishInflate(); mFavicon = (ImageView) findViewById(R.id.favicon); + mSnapshoticon = (ImageView) findViewById(R.id.snapshot_icon); + mReadericon = (ImageView) findViewById(R.id.reader_icon); mDate = (TextView) findViewById(R.id.date); mTitle = (TextView) findViewById(R.id.title); mBookmarks = findViewById(R.id.all_btn); @@ -234,4 +238,30 @@ public class SnapshotBar extends LinearLayout implements OnClickListener { return mIsAnimating; } + public void setTitle(String title) { + mTitle.setText(title); + } + + public void setDate(String date) { + mDate.setText(date); + } + + public void setSnapshoticonVisibility(int visibility) { + if (mSnapshoticon.getVisibility() != visibility) { + mSnapshoticon.setVisibility(visibility); + } + } + + public void setReadericonVisibility(int visibility) { + if (mReadericon.getVisibility() != visibility) { + mReadericon.setVisibility(visibility); + } + } + + public void setFaviconVisibility(int visibility) { + if (mFavicon.getVisibility() != visibility) { + mFavicon.setVisibility(visibility); + } + } + } diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index ef4c3806..4b361a1b 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -76,6 +76,7 @@ import org.codeaurora.swe.WebView.PictureListener; import org.codeaurora.swe.WebView.CreateWindowParams; import org.codeaurora.swe.WebViewClient; import org.codeaurora.swe.util.Observable; +import org.codeaurora.swe.DomDistillerUtils; import java.io.ByteArrayOutputStream; import java.io.File; @@ -206,6 +207,8 @@ class Tab implements PictureListener { return mTabHistoryUpdateObservable; } + // dertermines if the tab contains a disllable page + private boolean mIsDistillable = false; private static synchronized Bitmap getDefaultFavicon(Context context) { if (sDefaultFavicon == null) { @@ -315,6 +318,7 @@ class Tab implements PictureListener { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { + setIsDistillable(false); mInPageLoad = true; mPageFinished = false; mFirstVisualPixelPainted = false; @@ -1716,6 +1720,7 @@ class Tab implements PictureListener { protected void onPageFinished() { mPageFinished = true; + isDistillable(); } public boolean getPageFinishedStatus() { @@ -2127,4 +2132,67 @@ class Tab implements PictureListener { setSecurityState(SecurityState.SECURITY_STATE_MIXED); } } + + // dertermines if the tab contains a dislled page + public boolean isDistilled() { + if (!BrowserCommandLine.hasSwitch("reader-mode")) { + return false; + } + try { + return DomDistillerUtils.isUrlDistilled(getUrl()); + } catch (Exception e) { + return false; + } + } + + //determines if the tab contains a distillable page + public boolean isDistillable() { + if (!BrowserCommandLine.hasSwitch("reader-mode")) { + mIsDistillable = false; + return mIsDistillable; + } + final ValueCallback<String> onIsDistillable = new ValueCallback<String>() { + @Override + public void onReceiveValue(String str) { + mIsDistillable = Boolean.parseBoolean(str); + } + }; + + if (isDistilled()) { + mIsDistillable = true; + return mIsDistillable; + } + + try { + DomDistillerUtils.isWebViewDistillable(getWebView(), onIsDistillable); + } catch (Exception e) { + mIsDistillable = false; + } + + return mIsDistillable; + } + + // Function that sets the mIsDistillable variable + public void setIsDistillable(boolean value) { + if (!BrowserCommandLine.hasSwitch("reader-mode")) { + mIsDistillable = false; + } + mIsDistillable = value; + } + + // Function that returns the distilled url of the current url + public String getDistilledUrl() { + if (getUrl() != null) { + return DomDistillerUtils.getDistilledUrl(getUrl()); + } + return new String(); + } + + // function that returns the non-distilled version of the current url + public String getNonDistilledUrl() { + if (getUrl() != null) { + return DomDistillerUtils.getOriginalUrlFromDistilledUrl(getUrl()); + } + return new String(); + } } diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java index 357da3c9..3c2b5f1d 100644 --- a/src/com/android/browser/TitleBar.java +++ b/src/com/android/browser/TitleBar.java @@ -387,10 +387,21 @@ public class TitleBar extends FrameLayout implements ViewTreeObserver.OnPreDrawL mSnapshotBar.onTabDataChanged(tab); } - if (tab.isSnapshot()) { + if (tab.isSnapshot() || tab.isDistilled()) { inflateSnapshotBar(); mSnapshotBar.setVisibility(VISIBLE); mNavBar.setVisibility(GONE); + if (tab.isDistilled()) { + mSnapshotBar.setTitle(tab.getWebView().getTitle()); + mSnapshotBar.setDate(tab.getNonDistilledUrl()); + mSnapshotBar.setSnapshoticonVisibility(View.GONE); + mSnapshotBar.setFaviconVisibility(View.GONE); + mSnapshotBar.setReadericonVisibility(View.VISIBLE); + } else { + mSnapshotBar.setSnapshoticonVisibility(View.VISIBLE); + mSnapshotBar.setFaviconVisibility(View.VISIBLE); + mSnapshotBar.setReadericonVisibility(View.GONE); + } } else { if (mSnapshotBar != null) { mSnapshotBar.setVisibility(GONE); |