> settings,
diff --git a/src/com/fsck/k9/view/MessageWebView.java b/src/com/fsck/k9/view/MessageWebView.java
index bb5d3d737..8869a1d89 100644
--- a/src/com/fsck/k9/view/MessageWebView.java
+++ b/src/com/fsck/k9/view/MessageWebView.java
@@ -2,18 +2,18 @@ package com.fsck.k9.view;
import android.annotation.TargetApi;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
-import android.view.View;
import android.webkit.WebSettings;
-import android.webkit.WebView;
import android.widget.Toast;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import java.lang.reflect.Method;
import com.nobu_games.android.view.web.TitleBarWebView;
+
public class MessageWebView extends TitleBarWebView {
@@ -103,15 +103,16 @@ public class MessageWebView extends TitleBarWebView {
final WebSettings webSettings = this.getSettings();
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
+
webSettings.setSupportZoom(true);
+ webSettings.setBuiltInZoomControls(true);
+
+ disableDisplayZoomControls();
+
webSettings.setJavaScriptEnabled(false);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
- if (K9.zoomControlsEnabled()) {
- webSettings.setBuiltInZoomControls(true);
- }
-
if (isSingleColumnLayoutSupported() && K9.mobileOptimizedLayout()) {
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
} else {
@@ -127,6 +128,21 @@ public class MessageWebView extends TitleBarWebView {
}
+ /**
+ * Disable on-screen zoom controls on devices that support zooming via pinch-to-zoom.
+ */
+ @TargetApi(11)
+ private void disableDisplayZoomControls() {
+ if (Build.VERSION.SDK_INT >= 11) {
+ PackageManager pm = getContext().getPackageManager();
+ boolean supportsMultiTouch =
+ pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH) ||
+ pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT);
+
+ getSettings().setDisplayZoomControls(!supportsMultiTouch);
+ }
+ }
+
@TargetApi(9)
private void disableOverscrolling() {
if (Build.VERSION.SDK_INT >= 9) {
diff --git a/src/com/nobu_games/android/view/web/TitleBarWebView.java b/src/com/nobu_games/android/view/web/TitleBarWebView.java
index 2df1c99dd..4931bed03 100644
--- a/src/com/nobu_games/android/view/web/TitleBarWebView.java
+++ b/src/com/nobu_games/android/view/web/TitleBarWebView.java
@@ -32,6 +32,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
+import android.webkit.WebViewClassic.TitleBarDelegate;
import android.widget.FrameLayout;
/**
@@ -43,7 +44,7 @@ import android.widget.FrameLayout;
* Call {@link #setEmbeddedTitleBarCompat(View)} for setting a view as embedded
* title bar on top of the displayed WebView page.
*/
-public class TitleBarWebView extends WebView {
+public class TitleBarWebView extends WebView implements TitleBarDelegate {
/**
* Internally used view wrapper for suppressing unwanted touch events on the
* title bar view when WebView contents is being touched.
@@ -82,6 +83,13 @@ public class TitleBarWebView extends WebView {
private Matrix mMatrix = new Matrix();
private Method mNativeGetVisibleTitleHeightMethod;
+ /**
+ * This will always contain a reference to the title bar view no matter if
+ * {@code setEmbeddedTitleBar()} or the Jelly Bean workaround is used. We use this in
+ * {@link #getTitleHeight()}.
+ */
+ private View mTitleBarView;
+
public TitleBarWebView(Context context) {
super(context);
init();
@@ -172,6 +180,8 @@ public class TitleBarWebView extends WebView {
"Native setEmbeddedTitleBar not available. Starting workaround");
setEmbeddedTitleBarJellyBean(v);
}
+
+ mTitleBarView = v;
}
@Override
@@ -225,6 +235,11 @@ public class TitleBarWebView extends WebView {
@Override
protected void onDraw(Canvas canvas) {
+ if (Build.VERSION.SDK_INT >= 16) {
+ super.onDraw(canvas);
+ return;
+ }
+
canvas.save();
if(mTitleBar != null) {
@@ -264,8 +279,25 @@ public class TitleBarWebView extends WebView {
scrollBar.draw(canvas);
}
- private int getTitleHeight() {
- if(mTitleBar != null) return mTitleBar.getHeight();
+ /**
+ * Get the height of the title bar view.
+ *
+ *
+ * In the Jelly Bean workaround we need this method because we have to implement the
+ * {@link TitleBarDelegate} interface. But by implementing this method we override the hidden
+ * {@code getTitleHeight()} of the {@link WebView}s in older Android versions.
+ *
+ * What we should do, is return the title height on Jelly Bean and call through to the parent
+ * class on older Android versions. But this would require even more trickery, so we just
+ * inline the parent functionality which simply calls {@link View#getHeight()}. This is exactly
+ * what we do on Jelly Bean anyway.
+ *
+ */
+ @Override
+ public int getTitleHeight() {
+ if (mTitleBarView != null) {
+ return mTitleBarView.getHeight();
+ }
return 0;
}
@@ -315,4 +347,7 @@ public class TitleBarWebView extends WebView {
mTitleBar = v;
}
+
+ @Override
+ public void onSetEmbeddedTitleBar(View title) { /* unused */ }
}