Add keyboard navigation for all large tiles

Currently large tiles are excluded from adding into collection which is used for keyboard navigation. This cl adds them if desktop windowing tile is enabled.

Test: TaskGridNavHelperTest
BUG: 361070854
Flag: com.android.launcher3.enable_large_desktop_windowing_tile
Change-Id: I63fbb6867c34bbd80df926d750a7a392860b70a0
This commit is contained in:
vinayjoglekar
2024-09-05 14:35:51 +01:00
parent 05084e2ef3
commit 941a9e4f98
5 changed files with 658 additions and 527 deletions

View File

@@ -1,510 +0,0 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep.util;
import static com.android.quickstep.util.TaskGridNavHelper.CLEAR_ALL_PLACEHOLDER_ID;
import static com.android.quickstep.util.TaskGridNavHelper.INVALID_FOCUSED_TASK_ID;
import static org.junit.Assert.assertEquals;
import com.android.launcher3.util.IntArray;
import org.junit.Test;
public class TaskGridNavHelperTest {
@Test
public void equalLengthRows_noFocused_onTop_pressDown_goesToBottom() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 1;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_DOWN;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 2, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_pressUp_goesToBottom() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 1;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_UP;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 2, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_pressDown_goesToTop() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 2;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_DOWN;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 1, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_pressUp_goesToTop() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 2;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_UP;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 1, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_pressLeft_goesLeft() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 1;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 3, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_pressLeft_goesLeft() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 2;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 4, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_secondItem_pressRight_goesRight() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 3;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 1, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_secondItem_pressRight_goesRight() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 4;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 2, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_pressRight_cycleToClearAll() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 1;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", CLEAR_ALL_PLACEHOLDER_ID, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_pressRight_cycleToClearAll() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 2;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", CLEAR_ALL_PLACEHOLDER_ID, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_lastItem_pressLeft_toClearAll() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 5;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", CLEAR_ALL_PLACEHOLDER_ID, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_lastItem_pressLeft_toClearAll() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 6;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", CLEAR_ALL_PLACEHOLDER_ID, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onClearAll_pressLeft_cycleToFirst() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 1, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onClearAll_pressRight_toLastInBottom() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 6, nextGridPage);
}
@Test
public void equalLengthRows_withFocused_onFocused_pressLeft_toTop() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int focusedTaskId = 99;
int currentPageTaskViewId = focusedTaskId;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, focusedTaskId);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 1, nextGridPage);
}
@Test
public void equalLengthRows_withFocused_onFocused_pressUp_stayOnFocused() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int focusedTaskId = 99;
int currentPageTaskViewId = focusedTaskId;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_UP;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, focusedTaskId);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", focusedTaskId, nextGridPage);
}
@Test
public void equalLengthRows_withFocused_onFocused_pressDown_stayOnFocused() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int focusedTaskId = 99;
int currentPageTaskViewId = focusedTaskId;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_DOWN;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, focusedTaskId);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", focusedTaskId, nextGridPage);
}
@Test
public void equalLengthRows_withFocused_onFocused_pressRight_cycleToClearAll() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int focusedTaskId = 99;
int currentPageTaskViewId = focusedTaskId;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, focusedTaskId);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", CLEAR_ALL_PLACEHOLDER_ID, nextGridPage);
}
@Test
public void equalLengthRows_withFocused_onClearAll_pressLeft_cycleToFocusedTask() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int focusedTaskId = 99;
int currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, focusedTaskId);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", focusedTaskId, nextGridPage);
}
@Test
public void longerTopRow_noFocused_atEndTopBeyondBottom_pressDown_stayTop() {
IntArray topIds = IntArray.wrap(1, 3, 5, 7);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 7;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_DOWN;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 7, nextGridPage);
}
@Test
public void longerTopRow_noFocused_atEndTopBeyondBottom_pressUp_stayTop() {
IntArray topIds = IntArray.wrap(1, 3, 5, 7);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 7;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_UP;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 7, nextGridPage);
}
@Test
public void longerTopRow_noFocused_atEndBottom_pressLeft_goToTop() {
IntArray topIds = IntArray.wrap(1, 3, 5, 7);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 6;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_LEFT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 7, nextGridPage);
}
@Test
public void longerTopRow_noFocused_atClearAll_pressRight_goToLonger() {
IntArray topIds = IntArray.wrap(1, 3, 5, 7);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 7, nextGridPage);
}
@Test
public void longerBottomRow_noFocused_atClearAll_pressRight_goToLonger() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6, 7);
int currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_RIGHT;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 7, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_pressTab_goesToBottom() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 1;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_TAB;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 2, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_pressTab_goesToNextTop() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 2;
int delta = 1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_TAB;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 3, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onTop_pressTabWithShift_goesToPreviousBottom() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 3;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_TAB;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 2, nextGridPage);
}
@Test
public void equalLengthRows_noFocused_onBottom_pressTabWithShift_goesToTop() {
IntArray topIds = IntArray.wrap(1, 3, 5);
IntArray bottomIds = IntArray.wrap(2, 4, 6);
int currentPageTaskViewId = 2;
int delta = -1;
@TaskGridNavHelper.TASK_NAV_DIRECTION int direction = TaskGridNavHelper.DIRECTION_TAB;
boolean cycle = true;
TaskGridNavHelper taskGridNavHelper =
new TaskGridNavHelper(topIds, bottomIds, INVALID_FOCUSED_TASK_ID);
int nextGridPage =
taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, cycle);
assertEquals("Wrong next page returned.", 1, nextGridPage);
}
}

View File

@@ -0,0 +1,638 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep.util
import com.android.launcher3.util.IntArray
import com.android.quickstep.util.TaskGridNavHelper.CLEAR_ALL_PLACEHOLDER_ID
import com.android.quickstep.util.TaskGridNavHelper.DIRECTION_DOWN
import com.android.quickstep.util.TaskGridNavHelper.DIRECTION_LEFT
import com.android.quickstep.util.TaskGridNavHelper.DIRECTION_RIGHT
import com.android.quickstep.util.TaskGridNavHelper.DIRECTION_TAB
import com.android.quickstep.util.TaskGridNavHelper.DIRECTION_UP
import com.google.common.truth.Truth.assertThat
import org.junit.Test
class TaskGridNavHelperTest {
/*
5 3 1
CLEAR_ALL ↓
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_pressDown_goesToBottom() {
assertThat(getNextGridPage(currentPageTaskViewId = 1, DIRECTION_DOWN, delta = 1))
.isEqualTo(2)
}
/* ↑----→
5 3 1 |
CLEAR_ALL |
6 4 2←---|
*/
@Test
fun equalLengthRows_noFocused_onTop_pressUp_goesToBottom() {
assertThat(getNextGridPage(currentPageTaskViewId = 1, DIRECTION_UP, delta = 1)).isEqualTo(2)
}
/* ↓----↑
5 3 1 |
CLEAR_ALL |
6 4 2 |
↓----→
*/
@Test
fun equalLengthRows_noFocused_onBottom_pressDown_goesToTop() {
assertThat(getNextGridPage(currentPageTaskViewId = 2, DIRECTION_DOWN, delta = 1))
.isEqualTo(1)
}
/*
5 3 1
CLEAR_ALL ↑
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onBottom_pressUp_goesToTop() {
assertThat(getNextGridPage(currentPageTaskViewId = 2, DIRECTION_UP, delta = 1)).isEqualTo(1)
}
/*
5 3<--1
CLEAR_ALL
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_pressLeft_goesLeft() {
assertThat(getNextGridPage(currentPageTaskViewId = 1, DIRECTION_LEFT, delta = 1))
.isEqualTo(3)
}
/*
5 3 1
CLEAR_ALL
6 4<--2
*/
@Test
fun equalLengthRows_noFocused_onBottom_pressLeft_goesLeft() {
assertThat(getNextGridPage(currentPageTaskViewId = 2, DIRECTION_LEFT, delta = 1))
.isEqualTo(4)
}
/*
5 3-->1
CLEAR_ALL
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_secondItem_pressRight_goesRight() {
assertThat(getNextGridPage(currentPageTaskViewId = 3, DIRECTION_RIGHT, delta = -1))
.isEqualTo(1)
}
/*
5 3 1
CLEAR_ALL
6 4-->2
*/
@Test
fun equalLengthRows_noFocused_onBottom_secondItem_pressRight_goesRight() {
assertThat(getNextGridPage(currentPageTaskViewId = 4, DIRECTION_RIGHT, delta = -1))
.isEqualTo(2)
}
/*
↓------------------←
| |
↓ 5 3 1---→
CLEAR_ALL
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_pressRight_cycleToClearAll() {
assertThat(getNextGridPage(currentPageTaskViewId = 1, DIRECTION_RIGHT, delta = -1))
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
/*
↓------------------←
| ↑
↓ 5 3 1 |
CLEAR_ALL ↑
6 4 2---→
*/
@Test
fun equalLengthRows_noFocused_onBottom_pressRight_cycleToClearAll() {
assertThat(getNextGridPage(currentPageTaskViewId = 2, DIRECTION_RIGHT, delta = -1))
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
/*
←----5 3 1
CLEAR_ALL
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_lastItem_pressLeft_toClearAll() {
assertThat(getNextGridPage(currentPageTaskViewId = 5, DIRECTION_LEFT, delta = 1))
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
/*
5 3 1
CLEAR_ALL
←---6 4 2
*/
@Test
fun equalLengthRows_noFocused_onBottom_lastItem_pressLeft_toClearAll() {
assertThat(getNextGridPage(currentPageTaskViewId = 6, DIRECTION_LEFT, delta = 1))
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
/*
|→-----------------------|
| ↓
↑ 5 3 1
←------CLEAR_ALL
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onClearAll_pressLeft_cycleToFirst() {
assertThat(
getNextGridPage(
currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID,
DIRECTION_LEFT,
delta = 1,
)
)
.isEqualTo(1)
}
/*
5 3 1
CLEAR_ALL--↓
|
|--→6 4 2
*/
@Test
fun equalLengthRows_noFocused_onClearAll_pressRight_toLastInBottom() {
assertThat(
getNextGridPage(
currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID,
DIRECTION_RIGHT,
delta = -1,
)
)
.isEqualTo(6)
}
/*
5 3 1←---
CLEAR_ALL ←--FOCUSED_TASK
6 4 2
*/
@Test
fun equalLengthRows_withFocused_onFocused_pressLeft_toTop() {
assertThat(
getNextGridPage(
currentPageTaskViewId = FOCUSED_TASK_ID,
DIRECTION_LEFT,
delta = 1,
largeTileIds = listOf(FOCUSED_TASK_ID),
)
)
.isEqualTo(1)
}
/*
5 3 1
←--↑
CLEAR_ALL ↓-→FOCUSED_TASK
6 4 2
*/
@Test
fun equalLengthRows_withFocused_onFocused_pressUp_stayOnFocused() {
assertThat(
getNextGridPage(
currentPageTaskViewId = FOCUSED_TASK_ID,
DIRECTION_UP,
delta = 1,
largeTileIds = listOf(FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
5 3 1
CLEAR_ALL ↑--→FOCUSED_TASK
↑←--↓
6 4 2
*/
@Test
fun equalLengthRows_withFocused_onFocused_pressDown_stayOnFocused() {
assertThat(
getNextGridPage(
currentPageTaskViewId = FOCUSED_TASK_ID,
DIRECTION_DOWN,
delta = 1,
largeTileIds = listOf(FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
↓-------------------------------←|
| ↑
↓ 5 3 1 |
CLEAR_ALL FOCUSED_TASK--→
6 4 2
*/
@Test
fun equalLengthRows_withFocused_onFocused_pressRight_cycleToClearAll() {
assertThat(
getNextGridPage(
currentPageTaskViewId = FOCUSED_TASK_ID,
DIRECTION_RIGHT,
delta = -1,
largeTileIds = listOf(FOCUSED_TASK_ID),
)
)
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
/*
|→---------------------------|
| |
↑ 5 3 1 ↓
←------CLEAR_ALL FOCUSED_TASK
6 4 2
*/
@Test
fun equalLengthRows_withFocused_onClearAll_pressLeft_cycleToFocusedTask() {
assertThat(
getNextGridPage(
currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID,
DIRECTION_LEFT,
delta = 1,
largeTileIds = listOf(FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
7←-↑ 5 3 1
↓--→
CLEAR_ALL
6 4 2
*/
@Test
fun longerTopRow_noFocused_atEndTopBeyondBottom_pressDown_stayTop() {
assertThat(
getNextGridPage(
currentPageTaskViewId = 7,
DIRECTION_DOWN,
delta = 1,
topIds = IntArray.wrap(1, 3, 5, 7),
)
)
.isEqualTo(7)
}
/*
←--↑
↓-→7 5 3 1
CLEAR_ALL
6 4 2
*/
@Test
fun longerTopRow_noFocused_atEndTopBeyondBottom_pressUp_stayTop() {
assertThat(
getNextGridPage(
/* topIds = */ currentPageTaskViewId = 7,
DIRECTION_UP,
delta = 1,
topIds = IntArray.wrap(1, 3, 5, 7),
)
)
.isEqualTo(7)
}
/*
7 5 3 1
CLEAR_ALL ↑
←----6 4 2
*/
@Test
fun longerTopRow_noFocused_atEndBottom_pressLeft_goToTop() {
assertThat(
getNextGridPage(
/* topIds = */ currentPageTaskViewId = 6,
DIRECTION_LEFT,
delta = 1,
topIds = IntArray.wrap(1, 3, 5, 7),
)
)
.isEqualTo(7)
}
/*
7 5 3 1
CLEAR_ALL-----→
6 4 2
*/
@Test
fun longerTopRow_noFocused_atClearAll_pressRight_goToLonger() {
assertThat(
getNextGridPage(
/* topIds = */ currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID,
DIRECTION_RIGHT,
delta = -1,
topIds = IntArray.wrap(1, 3, 5, 7),
)
)
.isEqualTo(7)
}
/*
5 3 1
CLEAR_ALL-----→
7 6 4 2
*/
@Test
fun longerBottomRow_noFocused_atClearAll_pressRight_goToLonger() {
assertThat(
getNextGridPage(
currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID,
DIRECTION_RIGHT,
delta = -1,
bottomIds = IntArray.wrap(2, 4, 6, 7),
)
)
.isEqualTo(7)
}
/*
5 3 1
CLEAR_ALL ↓
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_pressTab_goesToBottom() {
assertThat(getNextGridPage(currentPageTaskViewId = 1, DIRECTION_TAB, delta = 1))
.isEqualTo(2)
}
/*
5 3 1
CLEAR_ALL ↑
←---↑
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onBottom_pressTab_goesToNextTop() {
assertThat(getNextGridPage(currentPageTaskViewId = 2, DIRECTION_TAB, delta = 1))
.isEqualTo(3)
}
/*
5 3 1
CLEAR_ALL ↓
----→
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onTop_pressTabWithShift_goesToPreviousBottom() {
assertThat(getNextGridPage(currentPageTaskViewId = 3, DIRECTION_TAB, delta = -1))
.isEqualTo(2)
}
/*
5 3 1
CLEAR_ALL ↑
6 4 2
*/
@Test
fun equalLengthRows_noFocused_onBottom_pressTabWithShift_goesToTop() {
assertThat(getNextGridPage(currentPageTaskViewId = 2, DIRECTION_TAB, delta = -1))
.isEqualTo(1)
}
/*
5 3 1
CLEAR_ALL FOCUSED_TASK←--DESKTOP
6 4 2
*/
@Test
fun withLargeTile_pressLeftFromDesktopTask_goesToFocusedTask() {
assertThat(
getNextGridPage(
currentPageTaskViewId = DESKTOP_TASK_ID,
DIRECTION_LEFT,
delta = 1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
5 3 1
CLEAR_ALL FOCUSED_TASK--→DESKTOP
6 4 2
*/
@Test
fun withLargeTile_pressRightFromFocusedTask_goesToDesktopTask() {
assertThat(
getNextGridPage(
currentPageTaskViewId = FOCUSED_TASK_ID,
DIRECTION_RIGHT,
delta = -1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(DESKTOP_TASK_ID)
}
/*
↓-----------------------------------------←|
| |
↓ 5 3 1 ↑
CLEAR_ALL FOCUSED_TASK DESKTOP--→
6 4 2
*/
@Test
fun withLargeTile_pressRightFromDesktopTask_goesToClearAll() {
assertThat(
getNextGridPage(
currentPageTaskViewId = DESKTOP_TASK_ID,
DIRECTION_RIGHT,
delta = -1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
/*
|→-------------------------------------------|
| |
↑ 5 3 1 ↓
←------CLEAR_ALL FOCUSED_TASK DESKTOP
6 4 2
*/
@Test
fun withLargeTile_pressLeftFromClearAll_goesToDesktopTask() {
assertThat(
getNextGridPage(
currentPageTaskViewId = CLEAR_ALL_PLACEHOLDER_ID,
DIRECTION_LEFT,
delta = 1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(DESKTOP_TASK_ID)
}
/*
5 3 1
CLEAR_ALL FOCUSED_TASK DESKTOP
6 4 2→----↑
*/
@Test
fun withLargeTile_pressRightFromBottom_goesToLargeTile() {
assertThat(
getNextGridPage(
currentPageTaskViewId = 2,
DIRECTION_RIGHT,
delta = -1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
5 3 1→----|
CLEAR_ALL FOCUSED_TASK DESKTOP
6 4 2
*/
@Test
fun withLargeTile_pressRightFromTop_goesToLargeTile() {
assertThat(
getNextGridPage(
currentPageTaskViewId = 1,
DIRECTION_RIGHT,
delta = -1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
5 3 1
CLEAR_ALL FOCUSED_TASK←---DESKTOP
6 4 2
*/
@Test
fun withLargeTile_pressTabFromDeskTop_goesToFocusedTask() {
assertThat(
getNextGridPage(
currentPageTaskViewId = DESKTOP_TASK_ID,
DIRECTION_TAB,
delta = 1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(FOCUSED_TASK_ID)
}
/*
CLEAR_ALL FOCUSED_TASK DESKTOP
2←----↓
*/
@Test
fun withLargeTile_pressLeftFromLargeTile_goesToBottom() {
assertThat(
getNextGridPage(
currentPageTaskViewId = FOCUSED_TASK_ID,
DIRECTION_LEFT,
delta = 1,
topIds = IntArray(),
bottomIds = IntArray.wrap(2),
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(2)
}
/*
↓-----------------------------------------←|
| |
↓ 5 3 1 ↑
CLEAR_ALL FOCUSED_TASK DESKTOP--→
6 4 2
*/
@Test
fun withLargeTile_pressShiftTabFromDeskTop_goesToClearAll() {
assertThat(
getNextGridPage(
currentPageTaskViewId = DESKTOP_TASK_ID,
DIRECTION_TAB,
delta = -1,
largeTileIds = listOf(DESKTOP_TASK_ID, FOCUSED_TASK_ID),
)
)
.isEqualTo(CLEAR_ALL_PLACEHOLDER_ID)
}
private fun getNextGridPage(
currentPageTaskViewId: Int,
direction: Int,
delta: Int,
topIds: IntArray = IntArray.wrap(1, 3, 5),
bottomIds: IntArray = IntArray.wrap(2, 4, 6),
largeTileIds: List<Int> = emptyList(),
): Int {
val taskGridNavHelper = TaskGridNavHelper(topIds, bottomIds, largeTileIds)
return taskGridNavHelper.getNextGridPage(currentPageTaskViewId, delta, direction, true)
}
private companion object {
const val FOCUSED_TASK_ID = 99
const val DESKTOP_TASK_ID = 100
}
}