2D recents: fix layout to show 3 tasks on a single line

Make the computation easier to read.

Bug: 34750498
Tested: Checked layout for n tasks for n between 0 and 8
Change-Id: I6d801f9f7d3839ed4a985233c82d93ab0823d6b0
This commit is contained in:
Manu Cornet
2017-01-27 16:21:38 +09:00
parent 56d29925ac
commit 776f6bacd6

View File

@@ -74,11 +74,8 @@ public class TaskGridLayoutAlgorithm {
yOffsets = new int[taskCount];
int layoutTaskCount = Math.min(MAX_LAYOUT_TASK_COUNT, taskCount);
tasksPerLine = layoutTaskCount < 2 ? 1 : (
layoutTaskCount < 5 ? 2 : (
layoutTaskCount < 7 ? 3 : 4));
lines = layoutTaskCount < 3 ? 1 : 2;
tasksPerLine = getTasksPerLine(layoutTaskCount);
lines = layoutTaskCount < 4 ? 1 : 2;
// A couple of special cases.
boolean landscapeWindow = mWindowRect.width() > mWindowRect.height();
@@ -131,6 +128,27 @@ public class TaskGridLayoutAlgorithm {
emptySpaceY / 2 + mPaddingTopBottom + (taskHeight + mPaddingTaskView) * yIndex;
}
}
private int getTasksPerLine(int taskCount) {
switch(taskCount) {
case 0:
return 0;
case 1:
return 1;
case 2:
case 4:
return 2;
case 3:
case 5:
case 6:
return 3;
case 7:
case 8:
return 4;
default:
throw new IllegalArgumentException("Unsupported task count " + taskCount);
}
}
}
/**