summaryrefslogtreecommitdiffstats
path: root/core/java/android/view
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2014-03-24 15:14:42 -0700
committerMichael Wright <michaelwr@google.com>2014-03-26 14:40:42 -0700
commit1e3c93975ee9c88284449406d49df2569f03f498 (patch)
treee3630a487609c74c69c33950d17b9d2d3084ef85 /core/java/android/view
parent2b45d84e24946d0cbbcc577ca3e195c0db687c9a (diff)
downloadframeworks_base-1e3c93975ee9c88284449406d49df2569f03f498.zip
frameworks_base-1e3c93975ee9c88284449406d49df2569f03f498.tar.gz
frameworks_base-1e3c93975ee9c88284449406d49df2569f03f498.tar.bz2
Adds API for determining confirm and cancel keys.
Bug: 13624048 Change-Id: I9f42eeb9c3a6bdae35eb0d7213fb4ac0fd8dc0d9
Diffstat (limited to 'core/java/android/view')
-rw-r--r--core/java/android/view/KeyEvent.java27
-rw-r--r--core/java/android/view/View.java4
2 files changed, 25 insertions, 6 deletions
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 6a6c127..437ccfb 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -1847,13 +1847,32 @@ public class KeyEvent extends InputEvent implements Parcelable {
}
}
- /** Whether key will, by default, trigger a click on the focused view.
- * @hide
+ /**
+ * Returns true if the key event should be treated as a confirming action.
+ * @return True for a confirmation key, such as {@link #KEYCODE_DPAD_CENTER},
+ * {@link #KEYCODE_ENTER}, or {@link #KEYCODE_BUTTON_A}.
*/
- public static final boolean isConfirmKey(int keyCode) {
- switch (keyCode) {
+ public final boolean isConfirmKey() {
+ switch (mKeyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
+ case KeyEvent.KEYCODE_BUTTON_A:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Returns true if the key event should be treated as a cancelling action.
+ * @return True for a cancellation key, such as {@link #KEYCODE_ESCAPE},
+ * {@link #KEYCODE_BACK}, or {@link #KEYCODE_BUTTON_B}.
+ */
+ public final boolean isCancelKey() {
+ switch (mKeyCode) {
+ case KeyEvent.KEYCODE_BUTTON_B:
+ case KeyEvent.KEYCODE_ESCAPE:
+ case KeyEvent.KEYCODE_BACK:
return true;
default:
return false;
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 6b73ae7..80725dc 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -8186,7 +8186,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean result = false;
- if (KeyEvent.isConfirmKey(keyCode)) {
+ if (event.isConfirmKey()) {
if ((mViewFlags & ENABLED_MASK) == DISABLED) {
return true;
}
@@ -8228,7 +8228,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @param event The KeyEvent object that defines the button action.
*/
public boolean onKeyUp(int keyCode, KeyEvent event) {
- if (KeyEvent.isConfirmKey(keyCode)) {
+ if (event.isConfirmKey()) {
if ((mViewFlags & ENABLED_MASK) == DISABLED) {
return true;
}