summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/FocusHelper.java
diff options
context:
space:
mode:
authorHyunyoung Song <hyunyoungs@google.com>2015-03-03 19:25:16 -0800
committerHyunyoung Song <hyunyoungs@google.com>2015-03-03 19:25:16 -0800
commit38531719636eba7c924e3e71c583ebce2c89a1d0 (patch)
tree68125591c75ce10680d45cd7b8df6157777bf596 /src/com/android/launcher3/FocusHelper.java
parent8dbf0fff1f424df8db1bbedfe8e5cfd7783a92ea (diff)
downloadandroid_packages_apps_Trebuchet-38531719636eba7c924e3e71c583ebce2c89a1d0.tar.gz
android_packages_apps_Trebuchet-38531719636eba7c924e3e71c583ebce2c89a1d0.tar.bz2
android_packages_apps_Trebuchet-38531719636eba7c924e3e71c583ebce2c89a1d0.zip
[key event focus] DPAD navigates to the nearest item on next/previous page
b/19381790 b/16351792 TL;DR;; Previously, when RIGHT is handled on the right most column of the current page or when LEFT is handled on the left most column, the next icon of focus is next page 'first' icon or the previous page 'last icon'. With this change, the row information is preserved when trying to locate an icon to give focus in the next/previous page. Next CL: long awaited unit tests that capture corner cases for different orientation/ device configuration. Change-Id: I5278bed45275b3e4cb39fb698df35f90bb45a415
Diffstat (limited to 'src/com/android/launcher3/FocusHelper.java')
-rw-r--r--src/com/android/launcher3/FocusHelper.java46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/com/android/launcher3/FocusHelper.java b/src/com/android/launcher3/FocusHelper.java
index bdfd7b287..ebb319b0b 100644
--- a/src/com/android/launcher3/FocusHelper.java
+++ b/src/com/android/launcher3/FocusHelper.java
@@ -89,6 +89,7 @@ public class FocusHelper {
countX = ((CellLayout) parentLayout).getCountX();
countY = ((CellLayout) parentLayout).getCountY();
} else if (v.getParent() instanceof ViewGroup) {
+ //TODO(hyunyoungs): figure out when this needs to be called.
itemContainer = parentLayout = (ViewGroup) v.getParent();
countX = ((PagedViewGridLayout) parentLayout).getCellCountX();
countY = ((PagedViewGridLayout) parentLayout).getCellCountY();
@@ -102,6 +103,7 @@ public class FocusHelper {
final int pageCount = container.getChildCount();
ViewGroup newParent = null;
View child = null;
+ // TODO(hyunyoungs): this matrix is not applicable on the last page.
int[][] matrix = FocusLogic.createFullMatrix(countX, countY, true);
// Process focus.
@@ -111,12 +113,22 @@ public class FocusHelper {
return consume;
}
switch (newIconIndex) {
+ case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
+ newParent = getAppsCustomizePage(container, pageIndex -1);
+ if (newParent != null) {
+ int row = FocusLogic.findRow(matrix, iconIndex);
+ container.snapToPage(pageIndex - 1);
+ // no need to create a new matrix.
+ child = newParent.getChildAt(matrix[countX-1][row]);
+ }
+ break;
case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
container.snapToPage(pageIndex - 1);
child = newParent.getChildAt(0);
}
+ break;
case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
@@ -131,6 +143,14 @@ public class FocusHelper {
child = newParent.getChildAt(0);
}
break;
+ case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
+ newParent = getAppsCustomizePage(container, pageIndex + 1);
+ if (newParent != null) {
+ container.snapToPage(pageIndex + 1);
+ int row = FocusLogic.findRow(matrix, iconIndex);
+ child = newParent.getChildAt(matrix[0][row]);
+ }
+ break;
case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
child = container.getChildAt(0);
break;
@@ -256,7 +276,7 @@ public class FocusHelper {
// Initialize the variables.
ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
- final CellLayout iconLayout = (CellLayout) parent.getParent();
+ CellLayout iconLayout = (CellLayout) parent.getParent();
final Workspace workspace = (Workspace) iconLayout.getParent();
final ViewGroup launcher = (ViewGroup) workspace.getParent();
final ViewGroup tabs = (ViewGroup) launcher.findViewById(R.id.search_drop_target_bar);
@@ -301,10 +321,23 @@ public class FocusHelper {
newIcon = tabs;
}
break;
+ case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
+ int row = FocusLogic.findRow(matrix, iconIndex);
+ parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
+ if (parent != null) {
+ iconLayout = (CellLayout) parent.getParent();
+ matrix = FocusLogic.createSparseMatrix(iconLayout, orientation,
+ iconLayout.getCountX(), row);
+ newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX + 1, countY, matrix,
+ FocusLogic.PIVOT, pageIndex - 1, pageCount);
+ newIcon = parent.getChildAt(newIconIndex);
+ }
+ break;
case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
newIcon = parent.getChildAt(0);
workspace.snapToPage(pageIndex - 1);
+ break;
case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
newIcon = parent.getChildAt(parent.getChildCount() - 1);
@@ -315,6 +348,17 @@ public class FocusHelper {
newIcon = parent.getChildAt(0);
workspace.snapToPage(pageIndex + 1);
break;
+ case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
+ row = FocusLogic.findRow(matrix, iconIndex);
+ parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
+ if (parent != null) {
+ iconLayout = (CellLayout) parent.getParent();
+ matrix = FocusLogic.createSparseMatrix(iconLayout, orientation, -1, row);
+ newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX + 1, countY, matrix,
+ FocusLogic.PIVOT, pageIndex, pageCount);
+ newIcon = parent.getChildAt(newIconIndex);
+ }
+ break;
case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
newIcon = parent.getChildAt(0);
break;