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

本文详细介绍了Android系统中WebView组件如何判断和支持多点触控功能。通过分析源码,解释了三个关键条件:系统是否支持多点触控、WebView设置是否允许缩放以及是否启用了内置的缩放控件。

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...

转载于:https://www.cnblogs.com/fantaisie/archive/2011/01/03/1924955.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值