diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2015-03-17 18:41:39 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-17 18:41:39 +0000 |
commit | a335f3b514a5450fe4dd890532e7842d59644cab (patch) | |
tree | d671cc7d1f621fd71e089b29750e271650dd0493 | |
parent | 367710c0f8b9d50ec6c1916f57e0832287ad39bc (diff) | |
parent | ce53e6dd12f5fa9e16ea77fbdafed3f8c2f448ac (diff) | |
download | android_packages_apps_Trebuchet-a335f3b514a5450fe4dd890532e7842d59644cab.tar.gz android_packages_apps_Trebuchet-a335f3b514a5450fe4dd890532e7842d59644cab.tar.bz2 android_packages_apps_Trebuchet-a335f3b514a5450fe4dd890532e7842d59644cab.zip |
am ce53e6dd: Merge "key event focus logic should support large tablets" into ub-launcher3-burnaby
* commit 'ce53e6dd12f5fa9e16ea77fbdafed3f8c2f448ac':
key event focus logic should support large tablets
-rw-r--r-- | src/com/android/launcher3/DeviceProfile.java | 5 | ||||
-rw-r--r-- | src/com/android/launcher3/FocusHelper.java | 43 | ||||
-rw-r--r-- | src/com/android/launcher3/util/FocusLogic.java | 13 |
3 files changed, 35 insertions, 26 deletions
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index ddd300257..bc9ef763d 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -81,6 +81,7 @@ public class DeviceProfile { boolean isTablet; boolean isLargeTablet; boolean isLayoutRtl; + boolean transposeLayoutWithOrientation; int desiredWorkspaceLeftRightMarginPx; @@ -699,6 +700,10 @@ public class DeviceProfile { return isLargeTablet; } + /** + * When {@code true}, hotseat is on the bottom row when in landscape mode. + * If {@code false}, hotseat is on the right column when in landscape mode. + */ boolean isVerticalBarLayout() { return isLandscape && transposeLayoutWithOrientation; } diff --git a/src/com/android/launcher3/FocusHelper.java b/src/com/android/launcher3/FocusHelper.java index b090a7c3f..fc6895201 100644 --- a/src/com/android/launcher3/FocusHelper.java +++ b/src/com/android/launcher3/FocusHelper.java @@ -207,12 +207,13 @@ public class FocusHelper { if (e.getAction() == KeyEvent.ACTION_UP || !consume) { return consume; } - int orientation = v.getResources().getConfiguration().orientation; + LauncherAppState app = LauncherAppState.getInstance(); + DeviceProfile profile = app.getDynamicGrid().getDeviceProfile(); if (DEBUG) { Log.v(TAG, String.format( - "Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, orientation=%d", - KeyEvent.keyCodeToString(keyCode), orientation)); + "Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, isVertical=%s", + KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout())); } // Initialize the variables. @@ -226,6 +227,8 @@ public class FocusHelper { int countX = -1; int countY = -1; int iconIndex = findIndexOfView(hotseatParent, v); + int iconRank = ((CellLayout.LayoutParams) hotseatLayout.getShortcutsAndWidgets() + .getChildAt(iconIndex).getLayoutParams()).cellX; final CellLayout iconLayout = (CellLayout) workspace.getChildAt(pageIndex); final ViewGroup iconParent = iconLayout.getShortcutsAndWidgets(); @@ -234,23 +237,25 @@ public class FocusHelper { int[][] matrix = null; if (keyCode == KeyEvent.KEYCODE_DPAD_UP && - orientation == Configuration.ORIENTATION_PORTRAIT) { - matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation, - hotseat.getAllAppsButtonRank(), true /* include all apps icon */); + !profile.isVerticalBarLayout()) { + matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, + true /* hotseat horizontal */, hotseat.getAllAppsButtonRank(), + iconRank == hotseat.getAllAppsButtonRank() /* include all apps icon */); iconIndex += iconParent.getChildCount(); countX = iconLayout.getCountX(); countY = iconLayout.getCountY() + hotseatLayout.getCountY(); parent = iconParent; } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && - orientation == Configuration.ORIENTATION_LANDSCAPE) { - matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation, - hotseat.getAllAppsButtonRank(), true /* include all apps icon */); + profile.isVerticalBarLayout()) { + matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, + false /* hotseat horizontal */, hotseat.getAllAppsButtonRank(), + iconRank == hotseat.getAllAppsButtonRank() /* include all apps icon */); iconIndex += iconParent.getChildCount(); countX = iconLayout.getCountX() + hotseatLayout.getCountX(); countY = iconLayout.getCountY(); parent = iconParent; } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && - orientation == Configuration.ORIENTATION_LANDSCAPE) { + profile.isVerticalBarLayout()) { keyCode = KeyEvent.KEYCODE_PAGE_DOWN; }else { // For other KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT navigation, do not use the @@ -296,10 +301,13 @@ public class FocusHelper { if (e.getAction() == KeyEvent.ACTION_UP || !consume) { return consume; } - int orientation = v.getResources().getConfiguration().orientation; + + LauncherAppState app = LauncherAppState.getInstance(); + DeviceProfile profile = app.getDynamicGrid().getDeviceProfile(); + if (DEBUG) { - Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] orientation=%d", - KeyEvent.keyCodeToString(keyCode), orientation)); + Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s", + KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout())); } // Initialize the variables. @@ -322,14 +330,13 @@ public class FocusHelper { // KEYCODE_DPAD_DOWN in portrait (KEYCODE_DPAD_RIGHT in landscape) is the only key allowed // to take a user to the hotseat. For other dpad navigation, do not use the matrix extended // with the hotseat. - if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && - orientation == Configuration.ORIENTATION_PORTRAIT) { - matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation, + if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) { + matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, true /* horizontal */, hotseat.getAllAppsButtonRank(), false /* all apps icon is ignored */); countY = countY + 1; } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && - orientation == Configuration.ORIENTATION_LANDSCAPE) { - matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation, + profile.isVerticalBarLayout()) { + matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, false /* horizontal */, hotseat.getAllAppsButtonRank(), false /* all apps icon is ignored */); countX = countX + 1; } else if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) { diff --git a/src/com/android/launcher3/util/FocusLogic.java b/src/com/android/launcher3/util/FocusLogic.java index 0c6bfbf35..6e80c2f21 100644 --- a/src/com/android/launcher3/util/FocusLogic.java +++ b/src/com/android/launcher3/util/FocusLogic.java @@ -184,21 +184,18 @@ public class FocusLogic { */ // TODO: get rid of the dynamic matrix creation public static int[][] createSparseMatrix(CellLayout iconLayout, CellLayout hotseatLayout, - int orientation, int allappsiconRank, boolean includeAllappsicon) { + boolean isHorizontal, int allappsiconRank, boolean includeAllappsicon) { ViewGroup iconParent = iconLayout.getShortcutsAndWidgets(); ViewGroup hotseatParent = hotseatLayout.getShortcutsAndWidgets(); int m, n; - if (orientation == Configuration.ORIENTATION_PORTRAIT) { + if (isHorizontal) { m = iconLayout.getCountX(); n = iconLayout.getCountY() + hotseatLayout.getCountY(); - } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + } else { m = iconLayout.getCountX() + hotseatLayout.getCountX(); n = iconLayout.getCountY(); - } else { - throw new IllegalStateException(String.format( - "orientation type=%d is not supported for key board events.", orientation)); } int[][] matrix = createFullMatrix(m, n, false /* set all cell to empty */); @@ -215,7 +212,7 @@ public class FocusLogic { // is truncated. If it is negative, then all apps icon index is not inserted. for(int i = hotseatParent.getChildCount() - 1; i >= (includeAllappsicon ? 0 : 1); i--) { int delta = 0; - if (orientation == Configuration.ORIENTATION_PORTRAIT) { + if (isHorizontal) { int cx = ((CellLayout.LayoutParams) hotseatParent.getChildAt(i).getLayoutParams()).cellX; if ((includeAllappsicon && cx >= allappsiconRank) || @@ -223,7 +220,7 @@ public class FocusLogic { delta = -1; } matrix[cx + delta][iconLayout.getCountY()] = iconParent.getChildCount() + i; - } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + } else { int cy = ((CellLayout.LayoutParams) hotseatParent.getChildAt(i).getLayoutParams()).cellY; if ((includeAllappsicon && cy >= allappsiconRank) || |