Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How disable the tip toast message that sometimes appears with the zoom controls in a WebView?

I haven't tested this on any other devices but on a 2.1 device, in a WebView with the zoom controls turned on, a toast message sometimes comes up that says something like "Tip: double tap to zoom in and out". I don't know where it is coming from as nothing in my code asked for it to appear. Is there any way to disable this?

I don't know how to reproduce it but it seems to happen more often when the app is freshly installed.

like image 949
cottonBallPaws Avatar asked Jan 09 '11 00:01

cottonBallPaws


2 Answers

As indicated in wajiw's answer, the toast is based on the double tap toast count in WebSettings. There is a workaround based on preempting that value. WebSettings gets its value for double tap toast count from SharedPreferences. Overriding the preferences value will disable the toast.

The preferences are based on private values in WebSettings so it's not ideal. If the implementation changes, this could very well stop working. So, use at your own risk.

Here are the values WebSettings uses for the SharedPreferences. You'll need to duplicate them in your class.

private static final String PREF_FILE = "WebViewSettings";
private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";

Then, you'll need to change the values before you use the WebView

SharedPreferences prefs = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
if (prefs.getInt(DOUBLE_TAP_TOAST_COUNT, 1) > 0) {
    prefs.edit().putInt(DOUBLE_TAP_TOAST_COUNT, 0).commit();
}

Check out WebSettings source code for more info.

like image 119
blazeroni Avatar answered Sep 26 '22 18:09

blazeroni


From looking at the WebView.java source it's coming from the startDrag function:

private void startDrag() {
        WebViewCore.reducePriority();
        // to get better performance, pause updating the picture
        WebViewCore.pauseUpdatePicture(mWebViewCore);
        if (!mDragFromTextInput) {
            nativeHideCursor();
        }
        WebSettings settings = getSettings();
        if (settings.supportZoom()
                && settings.getBuiltInZoomControls()
                && !getZoomButtonsController().isVisible()
                && mMinZoomScale < mMaxZoomScale
                && (mHorizontalScrollBarMode != SCROLLBAR_ALWAYSOFF
                        || mVerticalScrollBarMode != SCROLLBAR_ALWAYSOFF)) {
            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_LONG).show();
            }
        }
    }

the settings are accessible through getSettings(). From there I would try to call setDoubleTapToastCount and use something like 0 or -1 for the value. If that doesn't work you may be out of luck.

See full source of WebView.java here

like image 23
wajiw Avatar answered Sep 23 '22 18:09

wajiw