diff options
Diffstat (limited to 'tests/src/com/android/launcher3/util')
-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]; |