[Android 問題] How to Activate Multi-Touch in WebView (for Web Browser, Google Map, etc)?

Deadly 提交于 2020-01-02 07:55:02

Android's native web browser is webkit based.

Each front view of web is an object of WebView added by TabControl as the structure illustrated below:

 

Android originally support multi-touch scenerio.

In framworks/base/core/java/android/webkit/WebView.java,

There is a function showed below checking if current environment support multi-touch.

void updateMultiTouchSupport(Context context) {
        WebSettings settings = getSettings();
        mSupportMultiTouch = context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)
                && settings.supportZoom() && settings.getBuiltInZoomControls();

 

        if (mSupportMultiTouch && (mScaleDetector == null)) {
            mScaleDetector = new ScaleGestureDetector(context,
                    new ScaleDetectorListener());
        } else if (!mSupportMultiTouch && (mScaleDetector != null)) {
            mScaleDetector = null;
        }
    }

 

There are 3 flags:

 

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)

Check if there is a feature in system that support/permit multi-touch,

in frameworks/base/data/etc/

The feature

<feature name="android.hardware.touchscreen.multitouch.distinct" />
has been already defined in android.hardware.touchscreen.multitouch.distinct.xml

 

But in device/...../YOURDEVICENAME.mk

you have to copy it from frameworks/base/data/etc/ to system image system/etc/permissions/ when build your images.

bacause in the run time,  PackageManagerService.java will read the features/permissions from all  ...../etc/permissions/ through

readPermissionsFromXml() and use hasSystemFeature() to check if the feature exist.

 

PRODUCT_COPY_FILES := \
    frameworks/base/data/etc/android.hardware.camera.xml:system/etc/permissions/android.hardware.camera.xml \
    frameworks/base/data/etc/android.hardware.camera.autofocus.xml:system/etc/permissions/android.hardware.camera.autofocus.xml \
    frameworks/base/data/etc/android.hardware.camera.flash-autofocus.xml:system/etc/permissions/android.hardware.camera.flash-autofocus.xml \
    frameworks/base/data/etc/android.hardware.telephony.gsm.xml:system/etc/permissions/android.hardware.telephony.gsm.xml \
    frameworks/base/data/etc/android.hardware.telephony.cdma.xml:system/etc/permissions/android.hardware.telephony.cdma.xml \
    frameworks/base/data/etc/android.hardware.location.xml:system/etc/permissions/android.hardware.location.xml \
    frameworks/base/data/etc/android.hardware.location.gps.xml:system/etc/permissions/android.hardware.location.gps.xml \
   frameworks/base/data/etc/android.hardware.touchscreen.multitouch.distinct.xml:system/etc/permissions/android.hardware.touchscreen.multitouch.distinct.xml \
    frameworks/base/data/etc/android.hardware.bluetooth.xml:system/etc/permissions/android.hardware.bluetooth.xml \

 

settings.supportZoom()

Default set true, but might be changed unexpectedly.

You can set it  supportZoom(true) manually to make sure.

 

 

settings.getBuiltInZoomControls()

 Set to be "true" natively in application of browser.

 

by the way, this kind of permissions seems to be allowed to add in pure applications,

But i'm not sure if it works...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!