summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2015-11-26 16:04:54 +0000
committerMichael Wright <michaelwr@google.com>2015-12-14 17:30:25 -0500
commitaa1a94daaa59e98303fdeb1c3066b60a58755dff (patch)
tree6a6bd2afca5e179dbc9776b9cc106ce204a8ced7 /core/java/android
parent8d19ad443face8b862ac0a3cac095070a5ac9ad0 (diff)
Make KEYCODE_SPACE a confirm key.
By default space should "click" the focused item. This behavior also applies to GridView and ListView if the items are clickable, but will continue the previous behavior of scrolling if it's just a list of items you can't really interact with. Change-Id: Ic3a0334614d1dc68ff98bc4b1fb1ae2f961f71af
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/KeyEvent.java1
-rw-r--r--core/java/android/view/View.java4
-rw-r--r--core/java/android/widget/GridView.java32
-rw-r--r--core/java/android/widget/ListView.java34
4 files changed, 22 insertions, 49 deletions
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 55cf56ff7c9f..f037958f5cfc 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -1779,6 +1779,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
+ case KeyEvent.KEYCODE_SPACE:
return true;
default:
return false;
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 6dd87a035d23..9f5cfa8dc3d7 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -10173,8 +10173,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent)
* KeyEvent.Callback.onKeyUp()}: perform clicking of the view
- * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or
- * {@link KeyEvent#KEYCODE_ENTER} is released.
+ * when {@link KeyEvent#KEYCODE_DPAD_CENTER}, {@link KeyEvent#KEYCODE_ENTER}
+ * or {@link KeyEvent#KEYCODE_SPACE} is released.
* <p>Key presses in software keyboards will generally NOT trigger this listener,
* although some may elect to do so in some situations. Do not rely on this to
* catch software key presses.
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java
index 607e955d5698..ee73092b3fb5 100644
--- a/core/java/android/widget/GridView.java
+++ b/core/java/android/widget/GridView.java
@@ -1643,8 +1643,16 @@ public class GridView extends AbsListView {
boolean handled = false;
int action = event.getAction();
+ if (KeyEvent.isConfirmKey(keyCode)
+ && event.hasNoModifiers() && action == KeyEvent.ACTION_UP) {
+ handled = resurrectSelectionIfNeeded();
+ if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
+ keyPressed();
+ handled = true;
+ }
+ }
- if (action != KeyEvent.ACTION_UP) {
+ if (!handled && action != KeyEvent.ACTION_UP) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (event.hasNoModifiers()) {
@@ -1674,28 +1682,6 @@ public class GridView extends AbsListView {
}
break;
- case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_ENTER:
- if (event.hasNoModifiers()) {
- handled = resurrectSelectionIfNeeded();
- if (!handled
- && event.getRepeatCount() == 0 && getChildCount() > 0) {
- keyPressed();
- handled = true;
- }
- }
- break;
-
- case KeyEvent.KEYCODE_SPACE:
- if (mPopup == null || !mPopup.isShowing()) {
- if (event.hasNoModifiers()) {
- handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
- } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
- handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
- }
- }
- break;
-
case KeyEvent.KEYCODE_PAGE_UP:
if (event.hasNoModifiers()) {
handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index b43ea76976e1..c2ddf6f9a3ae 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -2180,8 +2180,17 @@ public class ListView extends AbsListView {
boolean handled = false;
int action = event.getAction();
+ if (KeyEvent.isConfirmKey(keyCode)
+ && event.hasNoModifiers() && action == KeyEvent.ACTION_UP) {
+ handled = resurrectSelectionIfNeeded();
+ if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
+ keyPressed();
+ handled = true;
+ }
+ }
- if (action != KeyEvent.ACTION_UP) {
+
+ if (!handled && action != KeyEvent.ACTION_UP) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
if (event.hasNoModifiers()) {
@@ -2229,29 +2238,6 @@ public class ListView extends AbsListView {
}
break;
- case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_ENTER:
- if (event.hasNoModifiers()) {
- handled = resurrectSelectionIfNeeded();
- if (!handled
- && event.getRepeatCount() == 0 && getChildCount() > 0) {
- keyPressed();
- handled = true;
- }
- }
- break;
-
- case KeyEvent.KEYCODE_SPACE:
- if (mPopup == null || !mPopup.isShowing()) {
- if (event.hasNoModifiers()) {
- handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
- } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
- handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
- }
- handled = true;
- }
- break;
-
case KeyEvent.KEYCODE_PAGE_UP:
if (event.hasNoModifiers()) {
handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);