Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 216bccf8 authored by Adam Powell's avatar Adam Powell
Browse files

Updated GestureDetector to ignore multitouch if requested by the app

or if targetSdkVersion >= Froyo. Made ScaleGestureDetector
public. current.xml API updates for gestures.
parent 8c18d89f
Loading
Loading
Loading
Loading
+254 −0
Original line number Diff line number Diff line
@@ -110028,6 +110028,17 @@
 visibility="public"
>
</field>
<field name="FROYO"
 type="int"
 transient="false"
 volatile="false"
 value="8"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="Bundle"
 extends="java.lang.Object"
@@ -163140,6 +163151,22 @@
<parameter name="handler" type="android.os.Handler">
</parameter>
</constructor>
<constructor name="GestureDetector"
 type="android.view.GestureDetector"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="listener" type="android.view.GestureDetector.OnGestureListener">
</parameter>
<parameter name="handler" type="android.os.Handler">
</parameter>
<parameter name="ignoreMultitouch" type="boolean">
</parameter>
</constructor>
<method name="isLongpressEnabled"
 return="boolean"
 abstract="false"
@@ -168514,6 +168541,233 @@
>
</field>
</class>
<class name="ScaleGestureDetector"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="ScaleGestureDetector"
 type="android.view.ScaleGestureDetector"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="listener" type="android.view.ScaleGestureDetector.OnScaleGestureListener">
</parameter>
</constructor>
<method name="getCurrentSpan"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getEventTime"
 return="long"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getFocusX"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getFocusY"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getPreviousSpan"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getScaleFactor"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getTimeDelta"
 return="long"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="isInProgress"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="onTouchEvent"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="event" type="android.view.MotionEvent">
</parameter>
</method>
</class>
<interface name="ScaleGestureDetector.OnScaleGestureListener"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="onScale"
 return="boolean"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="detector" type="android.view.ScaleGestureDetector">
</parameter>
</method>
<method name="onScaleBegin"
 return="boolean"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="detector" type="android.view.ScaleGestureDetector">
</parameter>
</method>
<method name="onScaleEnd"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="detector" type="android.view.ScaleGestureDetector">
</parameter>
</method>
</interface>
<class name="ScaleGestureDetector.SimpleOnScaleGestureListener"
 extends="java.lang.Object"
 abstract="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.view.ScaleGestureDetector.OnScaleGestureListener">
</implements>
<constructor name="ScaleGestureDetector.SimpleOnScaleGestureListener"
 type="android.view.ScaleGestureDetector.SimpleOnScaleGestureListener"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="onScale"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="detector" type="android.view.ScaleGestureDetector">
</parameter>
</method>
<method name="onScaleBegin"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="detector" type="android.view.ScaleGestureDetector">
</parameter>
</method>
<method name="onScaleEnd"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="detector" type="android.view.ScaleGestureDetector">
</parameter>
</method>
</class>
<class name="SoundEffectConstants"
 extends="java.lang.Object"
 abstract="false"
+2 −0
Original line number Diff line number Diff line
@@ -178,6 +178,8 @@ public class Build {
         * January 2010: Android 2.1
         */
        public static final int ECLAIR_MR1 = 7;
        
        public static final int FROYO = 8;
    }
    
    /** The type of build, like "user" or "eng". */
+67 −16
Original line number Diff line number Diff line
@@ -16,9 +16,10 @@

package android.view;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.content.Context;

/**
 * Detects various gestures and events using the supplied {@link MotionEvent}s.
@@ -232,6 +233,13 @@ public class GestureDetector {

    private boolean mIsLongpressEnabled;
    
    /**
     * True if we are at a target API level of >= Froyo or the developer can
     * explicitly set it. If true, input events with > 1 pointer will be ignored
     * so we can work side by side with multitouch gesture detectors.
     */
    private boolean mIgnoreMultitouch;

    /**
     * Determines speed during touch scrolling
     */
@@ -336,6 +344,26 @@ public class GestureDetector {
     * @throws NullPointerException if {@code listener} is null.
     */
    public GestureDetector(Context context, OnGestureListener listener, Handler handler) {
        this(context, listener, handler, context != null &&
                context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.FROYO);
    }
    
    /**
     * Creates a GestureDetector with the supplied listener.
     * You may only use this constructor from a UI thread (this is the usual situation).
     * @see android.os.Handler#Handler()
     *
     * @param context the application's context
     * @param listener the listener invoked for all the callbacks, this must
     * not be null.
     * @param handler the handler to use
     * @param ignoreMultitouch whether events involving more than one pointer should
     * be ignored.
     *
     * @throws NullPointerException if {@code listener} is null.
     */
    public GestureDetector(Context context, OnGestureListener listener, Handler handler,
            boolean ignoreMultitouch) {
        if (handler != null) {
            mHandler = new GestureHandler(handler);
        } else {
@@ -345,14 +373,15 @@ public class GestureDetector {
        if (listener instanceof OnDoubleTapListener) {
            setOnDoubleTapListener((OnDoubleTapListener) listener);
        }
        init(context);
        init(context, ignoreMultitouch);
    }

    private void init(Context context) {
    private void init(Context context, boolean ignoreMultitouch) {
        if (mListener == null) {
            throw new NullPointerException("OnGestureListener must not be null");
        }
        mIsLongpressEnabled = true;
        mIgnoreMultitouch = ignoreMultitouch;

        // Fallback to support pre-donuts releases
        int touchSlop, doubleTapSlop;
@@ -425,7 +454,26 @@ public class GestureDetector {

        boolean handled = false;

        switch (action) {
        switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_DOWN:
            if (mIgnoreMultitouch) {
                // Multitouch event - abort.
                cancel();
            }
            break;

        case MotionEvent.ACTION_POINTER_UP:
            // Ending a multitouch gesture and going back to 1 finger
            if (mIgnoreMultitouch && ev.getPointerCount() == 2) {
                int id = (((action & MotionEvent.ACTION_POINTER_ID_MASK)
                        >> MotionEvent.ACTION_POINTER_ID_SHIFT) == 0) ? 1 : 0;
                mLastMotionX = ev.getX(id);
                mLastMotionY = ev.getY(id);
                mVelocityTracker.recycle();
                mVelocityTracker = VelocityTracker.obtain();
            }
            break;

        case MotionEvent.ACTION_DOWN:
            if (mDoubleTapListener != null) {
                boolean hadTapMessage = mHandler.hasMessages(TAP);
@@ -462,7 +510,7 @@ public class GestureDetector {
            break;

        case MotionEvent.ACTION_MOVE:
            if (mInLongPress) {
            if (mInLongPress || (mIgnoreMultitouch && ev.getPointerCount() > 1)) {
                break;
            }
            final float scrollX = mLastMotionX - x;
@@ -525,6 +573,12 @@ public class GestureDetector {
            mHandler.removeMessages(LONG_PRESS);
            break;
        case MotionEvent.ACTION_CANCEL:
            cancel();
        }
        return handled;
    }

    private void cancel() {
        mHandler.removeMessages(SHOW_PRESS);
        mHandler.removeMessages(LONG_PRESS);
        mHandler.removeMessages(TAP);
@@ -534,11 +588,8 @@ public class GestureDetector {
        mStillDown = false;
        if (mInLongPress) {
            mInLongPress = false;
                break;
        }
    }
        return handled;
    }

    private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp,
            MotionEvent secondDown) {
+2 −5
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.view;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;

/**
 * Detects transformation gestures involving more than one pointer ("multitouch")
@@ -34,7 +33,6 @@ import android.util.Log;
 *          {@link #onTouchEvent(MotionEvent)}. The methods defined in your
 *          callback will be executed when the events occur.
 * </ul>
 * @hide Pending API approval
 */
public class ScaleGestureDetector {
    /**
@@ -82,8 +80,7 @@ public class ScaleGestureDetector {

        /**
         * Responds to the end of a scale gesture. Reported by existing
         * pointers going up. If the end of a gesture would result in a fling,
         * {@link onTransformFling()} is called instead.
         * pointers going up.
         * 
         * Once a scale has ended, {@link ScaleGestureDetector#getFocusX()}
         * and {@link ScaleGestureDetector#getFocusY()} will return the location
@@ -103,7 +100,7 @@ public class ScaleGestureDetector {
     * {@link OnScaleGestureListener#onScaleBegin(ScaleGestureDetector)} return
     * {@code true}. 
     */
    public class SimpleOnScaleGestureListener implements OnScaleGestureListener {
    public static class SimpleOnScaleGestureListener implements OnScaleGestureListener {

        public boolean onScale(ScaleGestureDetector detector) {
            return true;