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

Commit 20e987bf authored by Jeff Brown's avatar Jeff Brown
Browse files

Add MotionEvent Matrix transformations.

Fixed issued in ViewGroup's transformation of MotionEvents to ensure
that the entire historical trace is transformed, not just the current
pointer.

Simplified the code in ViewGroup for splitting events across Views.
The new code also handles the case where some pointers are dispatched
to the ViewGroup in addition to its children whereas the previous
code would drop some pointers on the floor.

Change-Id: I56ac31903e1de8a9c376d9c935b7217b0c42d93e
parent 4f4870f0
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -195957,6 +195957,19 @@
<parameter name="y" type="float">
</parameter>
</method>
<method name="transform"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="matrix" type="android.graphics.Matrix">
</parameter>
</method>
<method name="writeToParcel"
 return="void"
 abstract="false"
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.graphics.Matrix;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
@@ -347,6 +348,8 @@ public final class MotionEvent extends InputEvent implements Parcelable {
    private RuntimeException mRecycledLocation;
    private boolean mRecycled;

    private native void nativeTransform(Matrix matrix);

    private MotionEvent(int pointerCount, int sampleCount) {
        mPointerIdentifiers = new int[pointerCount];
        mDataSamples = new float[pointerCount * sampleCount * NUM_SAMPLE_DATA];
@@ -1413,6 +1416,19 @@ public final class MotionEvent extends InputEvent implements Parcelable {
        mYOffset = y - dataSamples[lastDataSampleIndex + SAMPLE_Y];
    }
    
    /**
     * Applies a transformation matrix to all of the points in the event.
     *
     * @param matrix The transformation matrix to apply.
     */
    public final void transform(Matrix matrix) {
        if (matrix == null) {
            throw new IllegalArgumentException("matrix must not be null");
        }

        nativeTransform(matrix);
    }

    private final void getPointerCoordsAtSampleIndex(int sampleIndex,
            PointerCoords outPointerCoords) {
        final float[] dataSamples = mDataSamples;
+9 −1
Original line number Diff line number Diff line
@@ -5760,6 +5760,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
        }
    }

    /**
     * Determines whether the given point, in local coordinates is inside the view.
     */
    /*package*/ final boolean pointInView(float localX, float localY) {
        return localX >= 0 && localX < (mRight - mLeft)
                && localY >= 0 && localY < (mBottom - mTop);
    }

    /**
     * Utility method to determine whether the given point, in local coordinates,
     * is inside the view, where the area of the view is expanded by the slop factor.
@@ -5767,7 +5775,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
     * is still within the view.
     */
    private boolean pointInView(float localX, float localY, float slop) {
        return localX > -slop && localY > -slop && localX < ((mRight - mLeft) + slop) &&
        return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) &&
                localY < ((mBottom - mTop) + slop);
    }

+448 −592

File changed.

Preview size limit exceeded, changes collapsed.

+12 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@
#include "SkMatrix.h"
#include "SkTemplates.h"

#include "Matrix.h"

namespace android {

class SkMatrixGlue {
@@ -403,10 +405,20 @@ static JNINativeMethod methods[] = {
    {"native_equals", "(II)Z", (void*) SkMatrixGlue::equals}
};

static jfieldID sNativeInstanceField;

int register_android_graphics_Matrix(JNIEnv* env) {
    int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Matrix", methods,
        sizeof(methods) / sizeof(methods[0]));

    jclass clazz = env->FindClass("android/graphics/Matrix");
    sNativeInstanceField = env->GetFieldID(clazz, "native_instance", "I");

    return result;
}

SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrixObj) {
    return reinterpret_cast<SkMatrix*>(env->GetIntField(matrixObj, sNativeInstanceField));
}

}
Loading