diff options
author | Tony Wickham <twickham@google.com> | 2015-11-09 17:51:08 -0800 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2015-11-10 11:40:58 -0800 |
commit | 6cbd22279e5e033c67863a3db851e0f43be9ddff (patch) | |
tree | 299cb5d5398a0e504072524665b89f5cbd756b45 /tests/src/com/android/launcher3 | |
parent | 3cfa97d4c14fa4af3ee3613e44ba7b7128141e31 (diff) | |
download | android_packages_apps_Trebuchet-6cbd22279e5e033c67863a3db851e0f43be9ddff.tar.gz android_packages_apps_Trebuchet-6cbd22279e5e033c67863a3db851e0f43be9ddff.tar.bz2 android_packages_apps_Trebuchet-6cbd22279e5e033c67863a3db851e0f43be9ddff.zip |
Add special column for All Apps button in FocusLogic's sparse matrix.
The All Apps button creates a number of edge cases, mainly because it
causes the hotseat to sometimes have an extra column than the workspace.
Previously, we sort of swept these problems under the rug by simply
ignoring the All Apps button if other icons were present in the hotseat,
with the assumption that those other icons should get focus instead of
the All Apps button. (If possible, we want to stay in the same column
when moving from the workspace to the hotseat.) But this doesn't always
work, as in the attached bug where the hotseat doesn't get focus at all
when the All Apps button is an obvious candidate for it.
By adding a specialized column in the focus matrix for the All Apps
button, we ensure that moving down to the hotseat stays within the
original column when possible, while also allowing the focus to switch
to the All Apps button if appropriate. Furthermore, we take care to skip
over the All Apps column when necessary in order to maintain all
previous functionality.
Bug: 25590522
Change-Id: I5d6a8ee69de8834314c4689246fe7d54329b2eef
Diffstat (limited to 'tests/src/com/android/launcher3')
-rw-r--r-- | tests/src/com/android/launcher3/util/FocusLogicTest.java | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/tests/src/com/android/launcher3/util/FocusLogicTest.java b/tests/src/com/android/launcher3/util/FocusLogicTest.java index 2c2f0d3df..f93e91313 100644 --- a/tests/src/com/android/launcher3/util/FocusLogicTest.java +++ b/tests/src/com/android/launcher3/util/FocusLogicTest.java @@ -19,6 +19,7 @@ package com.android.launcher3; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.view.KeyEvent; +import android.view.View; import com.android.launcher3.util.FocusLogic; @@ -82,6 +83,155 @@ public final class FocusLogicTest extends AndroidTestCase { assertEquals(0, i); } + public void testMoveIntoHotseatWithEqualHotseatAndWorkspaceColumns() { + // Test going from an icon right above the All Apps button to the All Apps button. + int[][] map = transpose(new int[][] { + {-1, -1, -1, -1, -1}, + {-1, -1, -1, -1, -1}, + {-1, -1, -1, -1, -1}, + {-1, -1, 0, -1, -1}, + { 2, 3, 1, 4, 5}, + }); + int i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 5, 5, map, 0, 1, 1, true); + assertEquals(1, i); + // Test going from an icon above and to the right of the All Apps + // button to an icon to the right of the All Apps button. + map = transpose(new int[][] { + {-1, -1, -1, -1, -1}, + {-1, -1, -1, -1, -1}, + {-1, -1, -1, -1, -1}, + {-1, -1, -1, 0, -1}, + { 2, 3, 1, 4, 5}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 5, 5, map, 0, 1, 1, true); + assertEquals(4, i); + } + + public void testMoveIntoHotseatWithExtraColumnForAllApps() { + // Test going from an icon above and to the left + // of the All Apps button to the All Apps button. + int[][] map = transpose(new int[][] { + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, 0,-11, -1, -1, -1}, + {-1, -1, -1, 1, 1, -1, -1}, + }); + int i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 0, 1, 1, true); + assertEquals(1, i); + // Test going from an icon above and to the right + // of the All Apps button to the All Apps button. + map = transpose(new int[][] { + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, 0, -1, -1}, + {-1, -1, -1, 1, -1, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 0, 1, 1, true); + assertEquals(1, i); + // Test going from the All Apps button to an icon + // above and to the right of the All Apps button. + map = transpose(new int[][] { + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, 0, -1, -1}, + {-1, -1, -1, 1, -1, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_UP, 7, 6, map, 1, 1, 1, true); + assertEquals(0, i); + // Test going from an icon above and to the left of the + // All Apps button in landscape to the All Apps button. + map = transpose(new int[][] { + { -1, -1, -1, -1, -1}, + { -1, -1, -1, 0, -1}, + {-11,-11,-11,-11, 1}, + { -1, -1, -1, -1, -1}, + { -1, -1, -1, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_RIGHT, 5, 5, map, 0, 1, 1, true); + assertEquals(1, i); + // Test going from the All Apps button in landscape to + // an icon above and to the left of the All Apps button. + map = transpose(new int[][] { + { -1, -1, -1, -1, -1}, + { -1, -1, -1, 0, -1}, + {-11,-11,-11,-11, 1}, + { -1, -1, -1, -1, -1}, + { -1, -1, -1, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT, 5, 5, map, 1, 1, 1, true); + assertEquals(0, i); + // Test that going to the hotseat always goes to the same row as the original icon. + map = transpose(new int[][]{ + { 0, 1, 2,-11, 3, 4, 5}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + {-1, -1, -1,-11, -1, -1, -1}, + { 7, 8, 9, 6, 10, 11, 12}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 0, 1, 1, true); + assertEquals(7, i); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 1, 1, 1, true); + assertEquals(8, i); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 2, 1, 1, true); + assertEquals(9, i); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 3, 1, 1, true); + assertEquals(10, i); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 4, 1, 1, true); + assertEquals(11, i); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 7, 6, map, 5, 1, 1, true); + assertEquals(12, i); + } + + public void testCrossingAllAppsColumn() { + // Test crossing from left to right in portrait. + int[][] map = transpose(new int[][] { + {-1, -1,-11, -1, -1}, + {-1, 0,-11, -1, -1}, + {-1, -1,-11, 1, -1}, + {-1, -1,-11, -1, -1}, + {-1, -1, 2, -1, -1}, + }); + int i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 5, 5, map, 0, 1, 1, true); + assertEquals(1, i); + // Test crossing from right to left in portrait. + map = transpose(new int[][] { + {-1, -1,-11, -1, -1}, + {-1, -1,-11, 0, -1}, + {-1, 1,-11, -1, -1}, + {-1, -1,-11, -1, -1}, + {-1, -1, 2, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, 5, 5, map, 0, 1, 1, true); + assertEquals(1, i); + // Test crossing from left to right in landscape. + map = transpose(new int[][] { + { -1, -1, -1, -1, -1}, + { -1, -1, -1, 0, -1}, + {-11,-11,-11,-11, 2}, + { -1, 1, -1, -1, -1}, + { -1, -1, -1, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT, 5, 5, map, 0, 1, 1, true); + assertEquals(1, i); + // Test crossing from right to left in landscape. + map = transpose(new int[][] { + { -1, -1, -1, -1, -1}, + { -1, 0, -1, -1, -1}, + {-11,-11,-11,-11, 2}, + { -1, -1, 1, -1, -1}, + { -1, -1, -1, -1, -1}, + }); + i = FocusLogic.handleKeyEvent(KeyEvent.KEYCODE_DPAD_RIGHT, 5, 5, map, 0, 1, 1, true); + assertEquals(1, i); + } + /** Transposes the matrix so that we can write it in human-readable format in the tests. */ private int[][] transpose(int[][] m) { int[][] t = new int[m[0].length][m.length]; |