Add a tip toast for double tap.
Fix http://b/issue?id=2059934
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index 196bbd7..3c43fd15 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -17,6 +17,7 @@
package android.webkit;
import android.content.Context;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
@@ -193,12 +194,20 @@
// with Google' and the browser.
static GoogleLocationSettingManager sGoogleLocationSettingManager;
+ // private WebSettings, not accessible by the host activity
+ private int mDoubleTapToastCount = 3;
+
+ private static final String PREF_FILE = "WebViewSettings";
+ private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";
+
// Class to handle messages before WebCore is ready.
private class EventHandler {
// Message id for syncing
static final int SYNC = 0;
// Message id for setting priority
static final int PRIORITY = 1;
+ // Message id for writing double-tap toast count
+ static final int SET_DOUBLE_TAP_TOAST_COUNT = 2;
// Actual WebCore thread handler
private Handler mHandler;
@@ -224,6 +233,16 @@
setRenderPriority();
break;
}
+
+ case SET_DOUBLE_TAP_TOAST_COUNT: {
+ SharedPreferences.Editor editor = mContext
+ .getSharedPreferences(PREF_FILE,
+ Context.MODE_PRIVATE).edit();
+ editor.putInt(DOUBLE_TAP_TOAST_COUNT,
+ mDoubleTapToastCount);
+ editor.commit();
+ break;
+ }
}
}
};
@@ -1311,6 +1330,19 @@
}
}
+ int getDoubleTapToastCount() {
+ return mDoubleTapToastCount;
+ }
+
+ void setDoubleTapToastCount(int count) {
+ if (mDoubleTapToastCount != count) {
+ mDoubleTapToastCount = count;
+ // write the settings in the non-UI thread
+ mEventHandler.sendMessage(Message.obtain(null,
+ EventHandler.SET_DOUBLE_TAP_TOAST_COUNT));
+ }
+ }
+
/**
* Transfer messages from the queue to the new WebCoreThread. Called from
* WebCore thread.
@@ -1323,6 +1355,10 @@
}
sGoogleLocationSettingManager = new GoogleLocationSettingManager(mContext);
sGoogleLocationSettingManager.start();
+ SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE,
+ Context.MODE_PRIVATE);
+ mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT,
+ mDoubleTapToastCount);
nativeSync(frame.mNativeFrame);
mSyncPending = false;
mEventHandler.createHandler();
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 2a92e05..9101578 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3750,6 +3750,13 @@
&& !mZoomButtonsController.isVisible()
&& mMinZoomScale < mMaxZoomScale) {
mZoomButtonsController.setVisible(true);
+ int count = settings.getDoubleTapToastCount();
+ if (mInZoomOverview && count > 0) {
+ settings.setDoubleTapToastCount(count--);
+ Toast.makeText(mContext,
+ com.android.internal.R.string.double_tap_toast,
+ Toast.LENGTH_SHORT).show();
+ }
}
}
@@ -4522,7 +4529,8 @@
mZoomCenterY = mLastTouchY;
mInZoomOverview = !mInZoomOverview;
// remove the zoom control after double tap
- if (getSettings().getBuiltInZoomControls()) {
+ WebSettings settings = getSettings();
+ if (settings.getBuiltInZoomControls()) {
if (mZoomButtonsController.isVisible()) {
mZoomButtonsController.setVisible(false);
}
@@ -4534,6 +4542,7 @@
mZoomControls.hide();
}
}
+ settings.setDoubleTapToastCount(0);
if (mInZoomOverview) {
// Force the titlebar fully reveal in overview mode
if (mScrollY < getTitleHeight()) mScrollY = 0;
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index bd79c75..a1a0102 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1391,6 +1391,9 @@
<!-- Title of the WebView save password dialog. If the user enters a password in a form on a website, a dialog will come up asking if they want to save the password. -->
<string name="save_password_label">Confirm</string>
+ <!-- Toast for double-tap -->
+ <string name="double_tap_toast">Tip: double-tap to zoom in and out.</string>
+
<!-- Title of an application permission, listed so the user can choose whether
they want to allow the application to do this. -->
<string name="permlab_readHistoryBookmarks">read Browser\'s history and bookmarks</string>