diff options
author | Sascha Haeberling <haeberling@google.com> | 2013-09-18 14:28:51 -0700 |
---|---|---|
committer | Sascha Haeberling <haeberling@google.com> | 2013-09-18 14:32:55 -0700 |
commit | 638e6f06c877d90b907f66ea9c22b3c6b73c7384 (patch) | |
tree | 6d2123a6d02228f867ccc6f7e51e2a658b2092d5 /src/com/android/camera/util/MotionEventHelper.java | |
parent | 4ed20592482d2ab2f3f48ee72d5b1c06bf009034 (diff) | |
download | android_packages_apps_Snap-638e6f06c877d90b907f66ea9c22b3c6b73c7384.tar.gz android_packages_apps_Snap-638e6f06c877d90b907f66ea9c22b3c6b73c7384.tar.bz2 android_packages_apps_Snap-638e6f06c877d90b907f66ea9c22b3c6b73c7384.zip |
Clean up ApiHelper and remove unused code paths.
Bug: 10821545
As we're targeting ICS there are a lot of checks and code paths
that are no longer in use. This CL cleans them up.
Change-Id: Ic3dd26628a94e134e25e2c496ccec1f1f957216d
Diffstat (limited to 'src/com/android/camera/util/MotionEventHelper.java')
-rw-r--r-- | src/com/android/camera/util/MotionEventHelper.java | 85 |
1 files changed, 1 insertions, 84 deletions
diff --git a/src/com/android/camera/util/MotionEventHelper.java b/src/com/android/camera/util/MotionEventHelper.java index eabaeab3b..001f83c41 100644 --- a/src/com/android/camera/util/MotionEventHelper.java +++ b/src/com/android/camera/util/MotionEventHelper.java @@ -1,10 +1,7 @@ package com.android.camera.util; -import android.annotation.TargetApi; import android.graphics.Matrix; -import android.util.FloatMath; import android.view.MotionEvent; -import android.view.MotionEvent.PointerCoords; public final class MotionEventHelper { private MotionEventHelper() {} @@ -12,92 +9,12 @@ public final class MotionEventHelper { public static MotionEvent transformEvent(MotionEvent e, Matrix m) { // We try to use the new transform method if possible because it uses // less memory. - if (ApiHelper.HAS_MOTION_EVENT_TRANSFORM) { - return transformEventNew(e, m); - } else { - return transformEventOld(e, m); - } + return transformEventNew(e, m); } - @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB) private static MotionEvent transformEventNew(MotionEvent e, Matrix m) { MotionEvent newEvent = MotionEvent.obtain(e); newEvent.transform(m); return newEvent; } - - // This is copied from Input.cpp in the android framework. - private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { - long downTime = e.getDownTime(); - long eventTime = e.getEventTime(); - int action = e.getAction(); - int pointerCount = e.getPointerCount(); - int[] pointerIds = getPointerIds(e); - PointerCoords[] pointerCoords = getPointerCoords(e); - int metaState = e.getMetaState(); - float xPrecision = e.getXPrecision(); - float yPrecision = e.getYPrecision(); - int deviceId = e.getDeviceId(); - int edgeFlags = e.getEdgeFlags(); - int source = e.getSource(); - int flags = e.getFlags(); - - // Copy the x and y coordinates into an array, map them, and copy back. - float[] xy = new float[pointerCoords.length * 2]; - for (int i = 0; i < pointerCount;i++) { - xy[2 * i] = pointerCoords[i].x; - xy[2 * i + 1] = pointerCoords[i].y; - } - m.mapPoints(xy); - for (int i = 0; i < pointerCount;i++) { - pointerCoords[i].x = xy[2 * i]; - pointerCoords[i].y = xy[2 * i + 1]; - pointerCoords[i].orientation = transformAngle( - m, pointerCoords[i].orientation); - } - - MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, - pointerCount, pointerIds, pointerCoords, metaState, xPrecision, - yPrecision, deviceId, edgeFlags, source, flags); - - return n; - } - - private static int[] getPointerIds(MotionEvent e) { - int n = e.getPointerCount(); - int[] r = new int[n]; - for (int i = 0; i < n; i++) { - r[i] = e.getPointerId(i); - } - return r; - } - - private static PointerCoords[] getPointerCoords(MotionEvent e) { - int n = e.getPointerCount(); - PointerCoords[] r = new PointerCoords[n]; - for (int i = 0; i < n; i++) { - r[i] = new PointerCoords(); - e.getPointerCoords(i, r[i]); - } - return r; - } - - private static float transformAngle(Matrix m, float angleRadians) { - // Construct and transform a vector oriented at the specified clockwise - // angle from vertical. Coordinate system: down is increasing Y, right is - // increasing X. - float[] v = new float[2]; - v[0] = FloatMath.sin(angleRadians); - v[1] = -FloatMath.cos(angleRadians); - m.mapVectors(v); - - // Derive the transformed vector's clockwise angle from vertical. - float result = (float) Math.atan2(v[0], -v[1]); - if (result < -Math.PI / 2) { - result += Math.PI; - } else if (result > Math.PI / 2) { - result -= Math.PI; - } - return result; - } } |