package com.android.launcher3;
import android.content.res.Configuration;
+import android.util.Log;
import android.view.KeyEvent;
+import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
* Handles key events in a PageViewCellLayout containing PagedViewIcons.
*/
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 itemContainer;
int countX;
final int x = iconIndex % countX;
final int y = iconIndex / countX;
+ final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
ViewGroup newParent = null;
// Side pages do not always load synchronously, so check before focusing child siblings
// Select the previous icon or the last icon on the previous page
if (iconIndex > 0) {
itemContainer.getChildAt(iconIndex - 1).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} else {
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(newParent.getChildCount() - 1);
- if (child != null) child.requestFocus();
+ if (child != null) {
+ child.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
+ }
}
}
}
// Select the next icon or the first icon on the next page
if (iconIndex < (itemCount - 1)) {
itemContainer.getChildAt(iconIndex + 1).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} else {
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
container.snapToPage(pageIndex + 1);
child = newParent.getChildAt(0);
- if (child != null) child.requestFocus();
+ if (child != null) {
+ child.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
+ }
}
}
}
if (y > 0) {
int newiconIndex = ((y - 1) * countX) + x;
itemContainer.getChildAt(newiconIndex).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
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)) {
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;
if (newParent != null) {
container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(0);
- if (child != null) child.requestFocus();
+ if (child != null) {
+ child.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
+ }
}
} else {
itemContainer.getChildAt(0).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
}
wasHandled = true;
if (newParent != null) {
container.snapToPage(pageIndex + 1);
child = newParent.getChildAt(0);
- if (child != null) child.requestFocus();
+ if (child != null) {
+ child.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
+ }
}
} else {
itemContainer.getChildAt(itemCount - 1).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
}
wasHandled = true;
if (handleKeyEvent) {
// Select the first icon on this page
itemContainer.getChildAt(0).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
wasHandled = true;
break;
if (handleKeyEvent) {
// Select the last icon on this page
itemContainer.getChildAt(itemCount - 1).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
wasHandled = true;
break;
* Handles key events in the workspace hotseat (bottom of the screen).
*/
static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e, int orientation) {
- final ViewGroup parent = (ViewGroup) v.getParent();
- final ViewGroup launcher = (ViewGroup) 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();
+ ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
+ final CellLayout layout = (CellLayout) parent.getParent();
// 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.
-
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
boolean wasHandled = false;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (handleKeyEvent) {
- // Select the previous button, otherwise snap to the previous page
- if (buttonIndex > 0) {
- parent.getChildAt(buttonIndex - 1).requestFocus();
- } else {
- workspace.snapToPage(pageIndex - 1);
+ ArrayList<View> views = getCellLayoutChildrenSortedSpatially(layout, parent);
+ int myIndex = views.indexOf(v);
+ // Select the previous button, otherwise do nothing
+ if (myIndex > 0) {
+ views.get(myIndex - 1).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) {
- // Select the next button, otherwise snap to the next page
- if (buttonIndex < (buttonCount - 1)) {
- parent.getChildAt(buttonIndex + 1).requestFocus();
- } else {
- workspace.snapToPage(pageIndex + 1);
+ ArrayList<View> views = getCellLayoutChildrenSortedSpatially(layout, parent);
+ int myIndex = views.indexOf(v);
+ // Select the next button, otherwise do nothing
+ if (myIndex < views.size() - 1) {
+ views.get(myIndex + 1).requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (handleKeyEvent) {
- // Select the first bubble text view in the current page of the workspace
- final CellLayout layout = (CellLayout) workspace.getChildAt(pageIndex);
- final ShortcutAndWidgetContainer children = layout.getShortcutsAndWidgets();
- final View newIcon = getIconInDirection(layout, children, -1, 1);
- if (newIcon != null) {
- newIcon.requestFocus();
- } else {
- workspace.requestFocus();
+ final Workspace workspace = (Workspace)
+ v.getRootView().findViewById(R.id.workspace);
+ if (workspace != null) {
+ int pageIndex = workspace.getCurrentPage();
+ CellLayout topLayout = (CellLayout) workspace.getChildAt(pageIndex);
+ ShortcutAndWidgetContainer children = topLayout.getShortcutsAndWidgets();
+ final View newIcon = getIconInDirection(layout, children, -1, 1);
+ // 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;
*/
private static ShortcutAndWidgetContainer getCellLayoutChildrenForIndex(
ViewGroup container, int i) {
- ViewGroup parent = (ViewGroup) container.getChildAt(i);
- return (ShortcutAndWidgetContainer) parent.getChildAt(0);
+ CellLayout parent = (CellLayout) container.getChildAt(i);
+ return parent.getShortcutsAndWidgets();
}
/**
View newIcon = getIconInDirection(layout, parent, v, -1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
} else {
if (pageIndex > 0) {
parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
// Snap to the previous page
workspace.snapToPage(pageIndex - 1);
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
}
}
}
View newIcon = getIconInDirection(layout, parent, v, 1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
} else {
if (pageIndex < (pageCount - 1)) {
parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
// Snap to the next page
workspace.snapToPage(pageIndex + 1);
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
}
}
}
} else {
tabs.requestFocus();
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
View newIcon = getClosestIconOnLine(layout, parent, v, 1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
wasHandled = true;
} else if (hotseat != null) {
hotseat.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
}
break;
// Snap to the previous page
workspace.snapToPage(pageIndex - 1);
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
} else {
View newIcon = getIconInDirection(layout, parent, -1, 1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
}
}
// Snap to the next page
workspace.snapToPage(pageIndex + 1);
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
} else {
View newIcon = getIconInDirection(layout, parent,
parent.getChildCount(), -1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
}
}
View newIcon = getIconInDirection(layout, parent, -1, 1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
}
wasHandled = true;
parent.getChildCount(), -1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
}
wasHandled = true;
View newIcon = getIconInDirection(layout, parent, v, -1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
}
}
wasHandled = true;
} else {
title.requestFocus();
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
}
wasHandled = true;
break;
View newIcon = getClosestIconOnLine(layout, parent, v, -1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
}
wasHandled = true;
} else {
title.requestFocus();
}
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
wasHandled = true;
break;
View newIcon = getIconInDirection(layout, parent, -1, 1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
}
}
wasHandled = true;
parent.getChildCount(), -1);
if (newIcon != null) {
newIcon.requestFocus();
+ v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
}
}
wasHandled = true;