summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xres/drawable-hdpi/ic_deco_reader_mode_normal.pngbin0 -> 1595 bytes
-rwxr-xr-xres/drawable-xhdpi/ic_deco_reader_mode_normal.pngbin0 -> 2102 bytes
-rwxr-xr-xres/drawable-xxhdpi/ic_deco_reader_mode_normal.pngbin0 -> 3138 bytes
-rw-r--r--res/layout/title_bar_snapshot.xml10
-rw-r--r--res/menu/browser.xml6
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/browser/Controller.java36
-rw-r--r--src/com/android/browser/NavTabView.java2
-rw-r--r--src/com/android/browser/SnapshotBar.java30
-rw-r--r--src/com/android/browser/Tab.java68
-rw-r--r--src/com/android/browser/TitleBar.java13
11 files changed, 165 insertions, 2 deletions
diff --git a/res/drawable-hdpi/ic_deco_reader_mode_normal.png b/res/drawable-hdpi/ic_deco_reader_mode_normal.png
new file mode 100755
index 00000000..18a5bab1
--- /dev/null
+++ b/res/drawable-hdpi/ic_deco_reader_mode_normal.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_deco_reader_mode_normal.png b/res/drawable-xhdpi/ic_deco_reader_mode_normal.png
new file mode 100755
index 00000000..6db9f950
--- /dev/null
+++ b/res/drawable-xhdpi/ic_deco_reader_mode_normal.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_deco_reader_mode_normal.png b/res/drawable-xxhdpi/ic_deco_reader_mode_normal.png
new file mode 100755
index 00000000..32dd368d
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_deco_reader_mode_normal.png
Binary files differ
diff --git a/res/layout/title_bar_snapshot.xml b/res/layout/title_bar_snapshot.xml
index 74176061..26614497 100644
--- a/res/layout/title_bar_snapshot.xml
+++ b/res/layout/title_bar_snapshot.xml
@@ -18,8 +18,18 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:background="@android:color/white"
android:orientation="horizontal" >
<ImageView
+ android:id="@+id/reader_icon"
+ android:src="@drawable/ic_deco_reader_mode_normal"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:visibility="gone"
+ android:paddingEnd="16dip"
+ android:paddingStart="16dip" />
+ <ImageView
+ android:id="@+id/snapshot_icon"
android:src="@drawable/ic_suggest_history_normal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
diff --git a/res/menu/browser.xml b/res/menu/browser.xml
index af57357a..60e9e789 100644
--- a/res/menu/browser.xml
+++ b/res/menu/browser.xml
@@ -80,6 +80,12 @@
android:id="@+id/ua_desktop_menu_id"
android:checkable="true"
android:title="@string/ua_switcher_desktop" />
+
+ <item
+ android:id="@+id/reader_mode_menu_id"
+ android:checkable="true"
+ android:title="@string/enable_reader_mode" />
+
<item
android:id="@+id/save_snapshot_menu_id"
android:title="@string/menu_save_snapshot" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3172642e..d6d27132 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1015,6 +1015,8 @@
<string name="find_on_page">Find on page</string>
<!-- Popup menu checkbox that allows the user to request the desktop version of a webpage [CHAR LIMIT=50] -->
<string name="ua_switcher_desktop">Request desktop site</string>
+ <!-- Popup menu checkbox that loads the reader mode version of the current webpage -->
+ <string name="enable_reader_mode">Reader mode</string>
<!-- Preload permission label [CHAR LIMIT=40] -->
<string name="permission_preload_label">Preload results</string>
<!-- Empty text for the "saved pages" tab that is shown when no saved pages exist. [CHAR LIMIT=None] -->
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);