diff options
| author | Michael Wright <michaelwr@google.com> | 2014-04-22 15:03:48 -0700 |
|---|---|---|
| committer | Michael Wright <michaelwr@google.com> | 2014-04-28 14:33:40 -0700 |
| commit | 337d9d2edc262141f9b8f684e53aae5e47f0ae13 (patch) | |
| tree | 486f2c212e2084a2730cf670fa3a41d11c16b188 /core/java/android/view/MotionEvent.java | |
| parent | b78263d37690a6a5cb12dd31d82ad2e140b3dfc7 (diff) | |
Move key attribute information into KeyEvent.
This consolidates all of the information that was in the native
KeyEvent and the KeyLayout files into the managed KeyEvent class.
It also moves the definition for all of the key names to the native
side, rather than having them in both places.
Change-Id: I172e3b554e7eb52c79ae2ec406ef4332e8b25ffa
Diffstat (limited to 'core/java/android/view/MotionEvent.java')
| -rw-r--r-- | core/java/android/view/MotionEvent.java | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index 6378ffd99749..0626ab96b0fe 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -167,6 +167,7 @@ import android.util.SparseArray; */ public final class MotionEvent extends InputEvent implements Parcelable { private static final long NS_PER_MS = 1000000; + private static final String LABEL_PREFIX = "AXIS_"; /** * An invalid pointer id. @@ -1369,6 +1370,9 @@ public final class MotionEvent extends InputEvent implements Parcelable { private static native long nativeReadFromParcel(long nativePtr, Parcel parcel); private static native void nativeWriteToParcel(long nativePtr, Parcel parcel); + private static native String nativeAxisToString(int axis); + private static native int nativeAxisFromString(String label); + private MotionEvent() { } @@ -3051,8 +3055,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @return The symbolic name of the specified axis. */ public static String axisToString(int axis) { - String symbolicName = AXIS_SYMBOLIC_NAMES.get(axis); - return symbolicName != null ? symbolicName : Integer.toString(axis); + String symbolicName = nativeAxisToString(axis); + return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis); } /** @@ -3064,17 +3068,13 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see KeyEvent#keyCodeToString(int) */ public static int axisFromString(String symbolicName) { - if (symbolicName == null) { - throw new IllegalArgumentException("symbolicName must not be null"); + if (symbolicName.startsWith(LABEL_PREFIX)) { + symbolicName = symbolicName.substring(LABEL_PREFIX.length()); } - - final int count = AXIS_SYMBOLIC_NAMES.size(); - for (int i = 0; i < count; i++) { - if (symbolicName.equals(AXIS_SYMBOLIC_NAMES.valueAt(i))) { - return i; - } + int axis = nativeAxisFromString(symbolicName); + if (axis >= 0) { + return axis; } - try { return Integer.parseInt(symbolicName, 10); } catch (NumberFormatException ex) { |
