Be Smart

FANTAISIE

SmartPhone - iPhone, iPad, Android

My Links

Blog Stats

News

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

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

posted on 2011-01-03 20:51 FANTAISIE 阅读(...) 评论(...) 编辑 收藏