summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-04-09 18:48:21 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-04-16 14:53:58 -0700
commitfc3c1edf7bbc3f7cb23e79520731d13ccc2da046 (patch)
treeddfd32647942c6dcd2ebab624cf8dea5660fb73a /src/com/android/launcher3/util
parentdf41097194b0ea490513c2a4e85bd9adc54637e8 (diff)
downloadandroid_packages_apps_Trebuchet-fc3c1edf7bbc3f7cb23e79520731d13ccc2da046.tar.gz
android_packages_apps_Trebuchet-fc3c1edf7bbc3f7cb23e79520731d13ccc2da046.tar.bz2
android_packages_apps_Trebuchet-fc3c1edf7bbc3f7cb23e79520731d13ccc2da046.zip
Fixing folder focus logic
> Folder items no longer remain in a linear order when a folder gets rearranged, and se we need to use createSparseMatrix instead of createFullArray. Also because of this we need to use getChildAt(x, y) instead of getChildAt(index) > Removing traces of AppsCustomizePage (all apps) from FocusHelper Change-Id: I9007f6b95cb823e27ef4a43ce725fda8ef1b7cf8
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r--src/com/android/launcher3/util/FocusLogic.java74
1 files changed, 31 insertions, 43 deletions
diff --git a/src/com/android/launcher3/util/FocusLogic.java b/src/com/android/launcher3/util/FocusLogic.java
index 8a08a4e72..a84e7df03 100644
--- a/src/com/android/launcher3/util/FocusLogic.java
+++ b/src/com/android/launcher3/util/FocusLogic.java
@@ -18,11 +18,15 @@ package com.android.launcher3.util;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.View;
import android.view.ViewGroup;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.ShortcutAndWidgetContainer;
+
+import java.util.Arrays;
/**
* Calculates the next item that a {@link KeyEvent} should change the focus to.
@@ -69,14 +73,11 @@ public class FocusLogic {
* Returns true only if this utility class handles the key code.
*/
public static boolean shouldConsume(int keyCode) {
- if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
+ return (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END ||
keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN ||
- keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) {
- return true;
- }
- return false;
+ keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL);
}
public static int handleKeyEvent(int keyCode, int cntX, int cntY, int [][] map,
@@ -138,33 +139,17 @@ public class FocusLogic {
}
/**
- * Returns a matrix of size (m x n) that has been initialized with incremental index starting
- * with 0 or a matrix where all the values are initialized to {@link #EMPTY}.
+ * Returns a matrix of size (m x n) that has been initialized with {@link #EMPTY}.
*
* @param m number of columns in the matrix
* @param n number of rows in the matrix
- * @param incrementOrder {@code true} if the matrix contents should increment in reading
- * order with 0 indexing. {@code false} if each cell should be
- * initialized to {@link #EMPTY};
*/
// TODO: get rid of dynamic matrix creation.
- public static int[][] createFullMatrix(int m, int n, boolean incrementOrder) {
- DeviceProfile profile = LauncherAppState.getInstance().getDynamicGrid()
- .getDeviceProfile();
+ private static int[][] createFullMatrix(int m, int n) {
int[][] matrix = new int [m][n];
for (int i=0; i < m;i++) {
- for (int j=0; j < n; j++) {
- if (incrementOrder) {
- if (!profile.isLayoutRtl) {
- matrix[i][j] = j * m + i;
- } else {
- matrix[i][j] = j * m + m - i -1;
- }
- } else {
- matrix[i][j] = EMPTY;
- }
- }
+ Arrays.fill(matrix[i], EMPTY);
}
return matrix;
}
@@ -175,17 +160,18 @@ public class FocusLogic {
*/
// TODO: get rid of the dynamic matrix creation
public static int[][] createSparseMatrix(CellLayout layout) {
- ViewGroup parent = layout.getShortcutsAndWidgets();
+ ShortcutAndWidgetContainer parent = layout.getShortcutsAndWidgets();
final int m = layout.getCountX();
final int n = layout.getCountY();
+ final boolean invert = parent.invertLayoutHorizontally();
- int[][] matrix = createFullMatrix(m, n, false /* initialize to #EMPTY */);
+ int[][] matrix = createFullMatrix(m, n);
// Iterate thru the children.
for (int i = 0; i < parent.getChildCount(); i++ ) {
int cx = ((CellLayout.LayoutParams) parent.getChildAt(i).getLayoutParams()).cellX;
int cy = ((CellLayout.LayoutParams) parent.getChildAt(i).getLayoutParams()).cellY;
- matrix[cx][cy] = i;
+ matrix[invert ? (m - cx - 1) : cx][cy] = i;
}
if (DEBUG) {
printMatrix(matrix);
@@ -213,7 +199,7 @@ public class FocusLogic {
m = iconLayout.getCountX() + hotseatLayout.getCountX();
n = iconLayout.getCountY();
}
- int[][] matrix = createFullMatrix(m, n, false /* set all cell to empty */);
+ int[][] matrix = createFullMatrix(m, n);
// Iterate thru the children of the top parent.
for (int i = 0; i < iconParent.getChildCount(); i++) {
@@ -267,8 +253,7 @@ public class FocusLogic {
ViewGroup iconParent = iconLayout.getShortcutsAndWidgets();
- int[][] matrix = createFullMatrix(iconLayout.getCountX() + 1, iconLayout.getCountY(),
- false /* set all cell to empty */);
+ int[][] matrix = createFullMatrix(iconLayout.getCountX() + 1, iconLayout.getCountY());
// Iterate thru the children of the top parent.
for (int i = 0; i < iconParent.getChildCount(); i++) {
@@ -499,22 +484,25 @@ public class FocusLogic {
}
/**
- * Figure out the location of the icon.
- *
+ * @param edgeColumn the column of the new icon. either {@link #NEXT_PAGE_LEFT_COLUMN} or
+ * {@link #NEXT_PAGE_RIGHT_COLUMN}
+ * @return the view adjacent to {@param oldView} in the {@param nextPage}.
*/
- //TODO(hyunyoungs): this helper method should move to CellLayout class while removing the
- // dynamic matrix creation all together.
- public static int findRow(int[][] matrix, int iconIndex) {
- int cntX = matrix.length;
- int cntY = matrix[0].length;
-
- for (int i = 0; i < cntX; i++) {
- for (int j = 0; j < cntY; j++) {
- if (matrix[i][j] == iconIndex) {
- return j;
+ public static View getAdjacentChildInNextPage(
+ ShortcutAndWidgetContainer nextPage, View oldView, int edgeColumn) {
+ final int newRow = ((CellLayout.LayoutParams) oldView.getLayoutParams()).cellY;
+
+ int column = (edgeColumn == NEXT_PAGE_LEFT_COLUMN) ^ nextPage.invertLayoutHorizontally()
+ ? 0 : (((CellLayout) nextPage.getParent()).getCountX() - 1);
+
+ for (; column >= 0; column--) {
+ for (int row = newRow; row >= 0; row--) {
+ View newView = nextPage.getChildAt(column, row);
+ if (newView != null) {
+ return newView;
}
}
}
- return -1;
+ return null;
}
}