am dec12adb: Merge "Changing hotseat keyboard controls" into ub-now-porkchop

* commit 'dec12adb6dba114ad2feedce3a9f3ce0c178fc04':
  Changing hotseat keyboard controls
This commit is contained in:
Sunny Goyal
2014-08-25 18:36:55 +00:00
committed by Android Git Automerger
3 changed files with 84 additions and 43 deletions
+82 -41
View File
@@ -17,7 +17,9 @@
package com.android.launcher3; package com.android.launcher3;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.SoundEffectConstants;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
@@ -225,13 +227,6 @@ public class FocusHelper {
* Handles key events in a PageViewCellLayout containing PagedViewIcons. * Handles key events in a PageViewCellLayout containing PagedViewIcons.
*/ */
static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) { static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) {
final int action = e.getAction();
if (((action == KeyEvent.ACTION_DOWN) && v.onKeyDown(keyCode, e))
|| ((action == KeyEvent.ACTION_UP) && v.onKeyUp(keyCode, e))) {
// Let the view handle the confirmation key.
return true;
}
ViewGroup parentLayout; ViewGroup parentLayout;
ViewGroup itemContainer; ViewGroup itemContainer;
int countX; int countX;
@@ -258,6 +253,7 @@ public class FocusHelper {
final int x = iconIndex % countX; final int x = iconIndex % countX;
final int y = iconIndex / countX; final int y = iconIndex / countX;
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP); final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
ViewGroup newParent = null; ViewGroup newParent = null;
// Side pages do not always load synchronously, so check before focusing child siblings // Side pages do not always load synchronously, so check before focusing child siblings
@@ -270,13 +266,17 @@ public class FocusHelper {
// Select the previous icon or the last icon on the previous page // Select the previous icon or the last icon on the previous page
if (iconIndex > 0) { if (iconIndex > 0) {
itemContainer.getChildAt(iconIndex - 1).requestFocus(); itemContainer.getChildAt(iconIndex - 1).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} else { } else {
if (pageIndex > 0) { if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1); newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) { if (newParent != null) {
container.snapToPage(pageIndex - 1); container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(newParent.getChildCount() - 1); child = newParent.getChildAt(newParent.getChildCount() - 1);
if (child != null) child.requestFocus(); if (child != null) {
child.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
}
} }
} }
} }
@@ -288,13 +288,17 @@ public class FocusHelper {
// Select the next icon or the first icon on the next page // Select the next icon or the first icon on the next page
if (iconIndex < (itemCount - 1)) { if (iconIndex < (itemCount - 1)) {
itemContainer.getChildAt(iconIndex + 1).requestFocus(); itemContainer.getChildAt(iconIndex + 1).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} else { } else {
if (pageIndex < (pageCount - 1)) { if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1); newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) { if (newParent != null) {
container.snapToPage(pageIndex + 1); container.snapToPage(pageIndex + 1);
child = newParent.getChildAt(0); child = newParent.getChildAt(0);
if (child != null) child.requestFocus(); if (child != null) {
child.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
}
} }
} }
} }
@@ -307,16 +311,21 @@ public class FocusHelper {
if (y > 0) { if (y > 0) {
int newiconIndex = ((y - 1) * countX) + x; int newiconIndex = ((y - 1) * countX) + x;
itemContainer.getChildAt(newiconIndex).requestFocus(); itemContainer.getChildAt(newiconIndex).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
} }
wasHandled = true; wasHandled = true;
break; break;
case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_DOWN:
if (handleKeyEvent) { if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise do nothing // Select the closest icon in the next row, otherwise do nothing
if (y < (countY - 1)) { if (y < (countY - 1)) {
int newiconIndex = Math.min(itemCount - 1, ((y + 1) * countX) + x); int newiconIndex = Math.min(itemCount - 1, ((y + 1) * countX) + x);
itemContainer.getChildAt(newiconIndex).requestFocus(); int newIconY = newiconIndex / countX;
if (newIconY != y) {
itemContainer.getChildAt(newiconIndex).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
} }
} }
wasHandled = true; wasHandled = true;
@@ -330,10 +339,14 @@ public class FocusHelper {
if (newParent != null) { if (newParent != null) {
container.snapToPage(pageIndex - 1); container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(0); child = newParent.getChildAt(0);
if (child != null) child.requestFocus(); if (child != null) {
child.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
} }
} else { } else {
itemContainer.getChildAt(0).requestFocus(); itemContainer.getChildAt(0).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
} }
wasHandled = true; wasHandled = true;
@@ -347,10 +360,14 @@ public class FocusHelper {
if (newParent != null) { if (newParent != null) {
container.snapToPage(pageIndex + 1); container.snapToPage(pageIndex + 1);
child = newParent.getChildAt(0); child = newParent.getChildAt(0);
if (child != null) child.requestFocus(); if (child != null) {
child.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
} }
} else { } else {
itemContainer.getChildAt(itemCount - 1).requestFocus(); itemContainer.getChildAt(itemCount - 1).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
} }
wasHandled = true; wasHandled = true;
@@ -359,6 +376,7 @@ public class FocusHelper {
if (handleKeyEvent) { if (handleKeyEvent) {
// Select the first icon on this page // Select the first icon on this page
itemContainer.getChildAt(0).requestFocus(); itemContainer.getChildAt(0).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
wasHandled = true; wasHandled = true;
break; break;
@@ -366,6 +384,7 @@ public class FocusHelper {
if (handleKeyEvent) { if (handleKeyEvent) {
// Select the last icon on this page // Select the last icon on this page
itemContainer.getChildAt(itemCount - 1).requestFocus(); itemContainer.getChildAt(itemCount - 1).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
wasHandled = true; wasHandled = true;
break; break;
@@ -432,53 +451,56 @@ public class FocusHelper {
* Handles key events in the workspace hotseat (bottom of the screen). * Handles key events in the workspace hotseat (bottom of the screen).
*/ */
static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e, int orientation) { static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e, int orientation) {
final ViewGroup parent = (ViewGroup) v.getParent(); ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
final ViewGroup launcher = (ViewGroup) parent.getParent(); final CellLayout layout = (CellLayout) parent.getParent();
final Workspace workspace = (Workspace) launcher.findViewById(R.id.workspace);
final int buttonIndex = parent.indexOfChild(v);
final int buttonCount = parent.getChildCount();
final int pageIndex = workspace.getCurrentPage();
// NOTE: currently we don't special case for the phone UI in different // NOTE: currently we don't special case for the phone UI in different
// orientations, even though the hotseat is on the side in landscape mode. This // orientations, even though the hotseat is on the side in landscape mode. This
// is to ensure that accessibility consistency is maintained across rotations. // is to ensure that accessibility consistency is maintained across rotations.
final int action = e.getAction(); final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP); final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
boolean wasHandled = false; boolean wasHandled = false;
switch (keyCode) { switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_LEFT:
if (handleKeyEvent) { if (handleKeyEvent) {
// Select the previous button, otherwise snap to the previous page ArrayList<View> views = getCellLayoutChildrenSortedSpatially(layout, parent);
if (buttonIndex > 0) { int myIndex = views.indexOf(v);
parent.getChildAt(buttonIndex - 1).requestFocus(); // Select the previous button, otherwise do nothing
} else { if (myIndex > 0) {
workspace.snapToPage(pageIndex - 1); views.get(myIndex - 1).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} }
} }
wasHandled = true; wasHandled = true;
break; break;
case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) { if (handleKeyEvent) {
// Select the next button, otherwise snap to the next page ArrayList<View> views = getCellLayoutChildrenSortedSpatially(layout, parent);
if (buttonIndex < (buttonCount - 1)) { int myIndex = views.indexOf(v);
parent.getChildAt(buttonIndex + 1).requestFocus(); // Select the next button, otherwise do nothing
} else { if (myIndex < views.size() - 1) {
workspace.snapToPage(pageIndex + 1); views.get(myIndex + 1).requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} }
} }
wasHandled = true; wasHandled = true;
break; break;
case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_UP:
if (handleKeyEvent) { if (handleKeyEvent) {
// Select the first bubble text view in the current page of the workspace final Workspace workspace = (Workspace)
final CellLayout layout = (CellLayout) workspace.getChildAt(pageIndex); v.getRootView().findViewById(R.id.workspace);
final ShortcutAndWidgetContainer children = layout.getShortcutsAndWidgets(); if (workspace != null) {
final View newIcon = getIconInDirection(layout, children, -1, 1); int pageIndex = workspace.getCurrentPage();
if (newIcon != null) { CellLayout topLayout = (CellLayout) workspace.getChildAt(pageIndex);
newIcon.requestFocus(); ShortcutAndWidgetContainer children = topLayout.getShortcutsAndWidgets();
} else { final View newIcon = getIconInDirection(layout, children, -1, 1);
workspace.requestFocus(); // Select the first bubble text view in the current page of the workspace
if (newIcon != null) {
newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} else {
workspace.requestFocus();
}
} }
} }
wasHandled = true; wasHandled = true;
@@ -497,8 +519,8 @@ public class FocusHelper {
*/ */
private static ShortcutAndWidgetContainer getCellLayoutChildrenForIndex( private static ShortcutAndWidgetContainer getCellLayoutChildrenForIndex(
ViewGroup container, int i) { ViewGroup container, int i) {
ViewGroup parent = (ViewGroup) container.getChildAt(i); CellLayout parent = (CellLayout) container.getChildAt(i);
return (ShortcutAndWidgetContainer) parent.getChildAt(0); return parent.getShortcutsAndWidgets();
} }
/** /**
@@ -622,6 +644,7 @@ public class FocusHelper {
View newIcon = getIconInDirection(layout, parent, v, -1); View newIcon = getIconInDirection(layout, parent, v, -1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} else { } else {
if (pageIndex > 0) { if (pageIndex > 0) {
parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1); parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
@@ -633,6 +656,7 @@ public class FocusHelper {
// Snap to the previous page // Snap to the previous page
workspace.snapToPage(pageIndex - 1); workspace.snapToPage(pageIndex - 1);
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} }
} }
} }
@@ -644,6 +668,7 @@ public class FocusHelper {
View newIcon = getIconInDirection(layout, parent, v, 1); View newIcon = getIconInDirection(layout, parent, v, 1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} else { } else {
if (pageIndex < (pageCount - 1)) { if (pageIndex < (pageCount - 1)) {
parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1); parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
@@ -654,6 +679,7 @@ public class FocusHelper {
// Snap to the next page // Snap to the next page
workspace.snapToPage(pageIndex + 1); workspace.snapToPage(pageIndex + 1);
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} }
} }
} }
@@ -669,6 +695,7 @@ public class FocusHelper {
} else { } else {
tabs.requestFocus(); tabs.requestFocus();
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
break; break;
case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_DOWN:
@@ -677,9 +704,11 @@ public class FocusHelper {
View newIcon = getClosestIconOnLine(layout, parent, v, 1); View newIcon = getClosestIconOnLine(layout, parent, v, 1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
wasHandled = true; wasHandled = true;
} else if (hotseat != null) { } else if (hotseat != null) {
hotseat.requestFocus(); hotseat.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
} }
break; break;
@@ -696,10 +725,12 @@ public class FocusHelper {
// Snap to the previous page // Snap to the previous page
workspace.snapToPage(pageIndex - 1); workspace.snapToPage(pageIndex - 1);
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} else { } else {
View newIcon = getIconInDirection(layout, parent, -1, 1); View newIcon = getIconInDirection(layout, parent, -1, 1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
} }
} }
@@ -718,11 +749,13 @@ public class FocusHelper {
// Snap to the next page // Snap to the next page
workspace.snapToPage(pageIndex + 1); workspace.snapToPage(pageIndex + 1);
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} else { } else {
View newIcon = getIconInDirection(layout, parent, View newIcon = getIconInDirection(layout, parent,
parent.getChildCount(), -1); parent.getChildCount(), -1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
} }
} }
@@ -734,6 +767,7 @@ public class FocusHelper {
View newIcon = getIconInDirection(layout, parent, -1, 1); View newIcon = getIconInDirection(layout, parent, -1, 1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
} }
wasHandled = true; wasHandled = true;
@@ -745,6 +779,7 @@ public class FocusHelper {
parent.getChildCount(), -1); parent.getChildCount(), -1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
} }
wasHandled = true; wasHandled = true;
@@ -774,6 +809,7 @@ public class FocusHelper {
View newIcon = getIconInDirection(layout, parent, v, -1); View newIcon = getIconInDirection(layout, parent, v, -1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} }
} }
wasHandled = true; wasHandled = true;
@@ -787,6 +823,7 @@ public class FocusHelper {
} else { } else {
title.requestFocus(); title.requestFocus();
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} }
wasHandled = true; wasHandled = true;
break; break;
@@ -796,6 +833,7 @@ public class FocusHelper {
View newIcon = getClosestIconOnLine(layout, parent, v, -1); View newIcon = getClosestIconOnLine(layout, parent, v, -1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
} }
wasHandled = true; wasHandled = true;
@@ -809,6 +847,7 @@ public class FocusHelper {
} else { } else {
title.requestFocus(); title.requestFocus();
} }
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
wasHandled = true; wasHandled = true;
break; break;
@@ -818,6 +857,7 @@ public class FocusHelper {
View newIcon = getIconInDirection(layout, parent, -1, 1); View newIcon = getIconInDirection(layout, parent, -1, 1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} }
} }
wasHandled = true; wasHandled = true;
@@ -829,6 +869,7 @@ public class FocusHelper {
parent.getChildCount(), -1); parent.getChildCount(), -1);
if (newIcon != null) { if (newIcon != null) {
newIcon.requestFocus(); newIcon.requestFocus();
v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} }
} }
wasHandled = true; wasHandled = true;
+1 -1
View File
@@ -64,7 +64,6 @@ public class Hotseat extends FrameLayout {
public void setup(Launcher launcher) { public void setup(Launcher launcher) {
mLauncher = launcher; mLauncher = launcher;
setOnKeyListener(new HotseatIconKeyEventListener());
} }
CellLayout getLayout() { CellLayout getLayout() {
@@ -155,6 +154,7 @@ public class Hotseat extends FrameLayout {
allAppsButton.setCompoundDrawables(null, d, null, null); allAppsButton.setCompoundDrawables(null, d, null, null);
allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
if (mLauncher != null) { if (mLauncher != null) {
allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
mLauncher.setAllAppsButton(allAppsButton); mLauncher.setAllAppsButton(allAppsButton);
+1 -1
View File
@@ -999,7 +999,7 @@ public class Workspace extends SmoothPagedView
final CellLayout layout; final CellLayout layout;
if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
layout = mLauncher.getHotseat().getLayout(); layout = mLauncher.getHotseat().getLayout();
child.setOnKeyListener(null); child.setOnKeyListener(new HotseatIconKeyEventListener());
// Hide folder title in the hotseat // Hide folder title in the hotseat
if (child instanceof FolderIcon) { if (child instanceof FolderIcon) {