diff options
author | Clare Bayley <clareb@google.com> | 2015-08-14 17:28:39 +0000 |
---|---|---|
committer | Trevor Johns <trevorjohns@google.com> | 2015-08-17 08:09:37 -0700 |
commit | d3c06bfcae316f85f3b0235612536dc7b82a8e57 (patch) | |
tree | b804761599081e00870e191359696aff19d439e6 /input | |
parent | 6ab42c36e877ca920212b0a1586268a2e855c2e3 (diff) | |
download | android-d3c06bfcae316f85f3b0235612536dc7b82a8e57.tar.gz |
Resolve conflicts for merge of 6a1d10d from lmp-mr1-ub-dev to mnc-dev
Merge: Merge "Add Stylus Info to BasicGestureDetect" into lmp-mr1-ub-docs
* commit '39cb9cb98b5241043c56c8ca238cd05e0781f848':
Add Stylus Info to BasicGestureDetect
Change-Id: I38b1b40c49fa54cc48b261b86ad61a7df8d4979b
Diffstat (limited to 'input')
-rw-r--r-- | input/gestures/BasicGestureDetect/Application/src/main/ic_launcher-web.png | bin | 0 -> 27510 bytes | |||
-rw-r--r-- | input/gestures/BasicGestureDetect/Application/src/main/java/com/example/android/basicgesturedetect/GestureListener.java | 96 | ||||
-rw-r--r-- | input/gestures/BasicGestureDetect/Application/src/main/res/drawable-hdpi/ic_launcher.png | bin | 4199 -> 2323 bytes | |||
-rw-r--r-- | input/gestures/BasicGestureDetect/Application/src/main/res/drawable-mdpi/ic_launcher.png | bin | 2535 -> 1551 bytes | |||
-rw-r--r-- | input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xhdpi/ic_launcher.png | bin | 6022 -> 3202 bytes | |||
-rw-r--r-- | input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xxhdpi/ic_launcher.png | bin | 11040 -> 5061 bytes | |||
-rw-r--r-- | input/gestures/BasicGestureDetect/screenshots/icon-web.png | bin | 75748 -> 40427 bytes |
7 files changed, 87 insertions, 9 deletions
diff --git a/input/gestures/BasicGestureDetect/Application/src/main/ic_launcher-web.png b/input/gestures/BasicGestureDetect/Application/src/main/ic_launcher-web.png Binary files differnew file mode 100644 index 00000000..2cb6bbfa --- /dev/null +++ b/input/gestures/BasicGestureDetect/Application/src/main/ic_launcher-web.png diff --git a/input/gestures/BasicGestureDetect/Application/src/main/java/com/example/android/basicgesturedetect/GestureListener.java b/input/gestures/BasicGestureDetect/Application/src/main/java/com/example/android/basicgesturedetect/GestureListener.java index 2e2921d4..19b588a6 100644 --- a/input/gestures/BasicGestureDetect/Application/src/main/java/com/example/android/basicgesturedetect/GestureListener.java +++ b/input/gestures/BasicGestureDetect/Application/src/main/java/com/example/android/basicgesturedetect/GestureListener.java @@ -16,6 +16,8 @@ package com.example.android.basicgesturedetect; +import android.annotation.TargetApi; +import android.os.Build; import android.view.GestureDetector; import android.view.MotionEvent; @@ -29,7 +31,7 @@ public class GestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onSingleTapUp(MotionEvent e) { // Up motion completing a single tap occurred. - Log.i(TAG, "Single Tap Up"); + Log.i(TAG, "Single Tap Up" + getTouchType(e)); return false; } @@ -37,14 +39,14 @@ public class GestureListener extends GestureDetector.SimpleOnGestureListener { public void onLongPress(MotionEvent e) { // Touch has been long enough to indicate a long press. // Does not indicate motion is complete yet (no up event necessarily) - Log.i(TAG, "Long Press"); + Log.i(TAG, "Long Press" + getTouchType(e)); } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // User attempted to scroll - Log.i(TAG, "Scroll"); + Log.i(TAG, "Scroll" + getTouchType(e1)); return false; } @@ -52,27 +54,27 @@ public class GestureListener extends GestureDetector.SimpleOnGestureListener { public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Fling event occurred. Notification of this one happens after an "up" event. - Log.i(TAG, "Fling"); + Log.i(TAG, "Fling" + getTouchType(e1)); return false; } @Override public void onShowPress(MotionEvent e) { // User performed a down event, and hasn't moved yet. - Log.i(TAG, "Show Press"); + Log.i(TAG, "Show Press" + getTouchType(e)); } @Override public boolean onDown(MotionEvent e) { // "Down" event - User touched the screen. - Log.i(TAG, "Down"); + Log.i(TAG, "Down" + getTouchType(e)); return false; } @Override public boolean onDoubleTap(MotionEvent e) { // User tapped the screen twice. - Log.i(TAG, "Double tap"); + Log.i(TAG, "Double tap" + getTouchType(e)); return false; } @@ -81,7 +83,7 @@ public class GestureListener extends GestureDetector.SimpleOnGestureListener { // Since double-tap is actually several events which are considered one aggregate // gesture, there's a separate callback for an individual event within the doubletap // occurring. This occurs for down, up, and move. - Log.i(TAG, "Event within double tap"); + Log.i(TAG, "Event within double tap" + getTouchType(e)); return false; } @@ -89,8 +91,84 @@ public class GestureListener extends GestureDetector.SimpleOnGestureListener { public boolean onSingleTapConfirmed(MotionEvent e) { // A confirmed single-tap event has occurred. Only called when the detector has // determined that the first tap stands alone, and is not part of a double tap. - Log.i(TAG, "Single tap confirmed"); + Log.i(TAG, "Single tap confirmed" + getTouchType(e)); return false; } // END_INCLUDE(init_gestureListener) + + + /** + * Returns a human-readable string describing the type of touch that triggered a MotionEvent. + */ + + private static String getTouchType(MotionEvent e){ + + String touchTypeDescription = " "; + int touchType = e.getToolType(0); + + switch (touchType) { + case MotionEvent.TOOL_TYPE_FINGER: + touchTypeDescription += "(finger)"; + break; + case MotionEvent.TOOL_TYPE_STYLUS: + touchTypeDescription += "(stylus, "; + //Get some additional information about the stylus touch + float stylusPressure = e.getPressure(); + touchTypeDescription += "pressure: " + stylusPressure; + + if(Build.VERSION.SDK_INT >= 21) { + touchTypeDescription += ", buttons pressed: " + getButtonsPressed(e); + } + + touchTypeDescription += ")"; + break; + case MotionEvent.TOOL_TYPE_ERASER: + touchTypeDescription += "(eraser)"; + break; + case MotionEvent.TOOL_TYPE_MOUSE: + touchTypeDescription += "(mouse)"; + break; + default: + touchTypeDescription += "(unknown tool)"; + break; + } + + return touchTypeDescription; + } + + /** + * Returns a human-readable string listing all the stylus buttons that were pressed when the + * input MotionEvent occurred. + */ + @TargetApi(21) + private static String getButtonsPressed(MotionEvent e){ + String buttons = ""; + + if(e.isButtonPressed(MotionEvent.BUTTON_PRIMARY)){ + buttons += " primary"; + } + + if(e.isButtonPressed(MotionEvent.BUTTON_SECONDARY)){ + buttons += " secondary"; + } + + if(e.isButtonPressed(MotionEvent.BUTTON_TERTIARY)){ + buttons += " tertiary"; + } + + if(e.isButtonPressed(MotionEvent.BUTTON_BACK)){ + buttons += " back"; + } + + if(e.isButtonPressed(MotionEvent.BUTTON_FORWARD)){ + buttons += " forward"; + } + + if (buttons.equals("")){ + buttons = "none"; + } + + return buttons; + } + } diff --git a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-hdpi/ic_launcher.png b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-hdpi/ic_launcher.png Binary files differindex b1efaf4b..4252db13 100644 --- a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-hdpi/ic_launcher.png +++ b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-mdpi/ic_launcher.png b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-mdpi/ic_launcher.png Binary files differindex f5f9244f..969456ee 100644 --- a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-mdpi/ic_launcher.png +++ b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xhdpi/ic_launcher.png Binary files differindex 5d07b3f0..608151af 100644 --- a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xhdpi/ic_launcher.png +++ b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xxhdpi/ic_launcher.png Binary files differindex 6ef21e1f..23ffa9a0 100644 --- a/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xxhdpi/ic_launcher.png +++ b/input/gestures/BasicGestureDetect/Application/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/input/gestures/BasicGestureDetect/screenshots/icon-web.png b/input/gestures/BasicGestureDetect/screenshots/icon-web.png Binary files differindex 04d0248c..3fb33363 100644 --- a/input/gestures/BasicGestureDetect/screenshots/icon-web.png +++ b/input/gestures/BasicGestureDetect/screenshots/icon-web.png |