summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/FocusHelper.java
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2011-07-28 10:45:09 -0700
committerWinson Chung <winsonc@google.com>2011-07-28 10:45:39 -0700
commit3b0b46af5dd09ae00cd0ff7fcce6cff17447acad (patch)
tree75191ec4dc4496543eca1f257072ac17539b009d /src/com/android/launcher2/FocusHelper.java
parent365055f289bc9c3c730f1dcf26c99afc6d8b31c5 (diff)
downloadandroid_packages_apps_Trebuchet-3b0b46af5dd09ae00cd0ff7fcce6cff17447acad.tar.gz
android_packages_apps_Trebuchet-3b0b46af5dd09ae00cd0ff7fcce6cff17447acad.tar.bz2
android_packages_apps_Trebuchet-3b0b46af5dd09ae00cd0ff7fcce6cff17447acad.zip
Adding workaround for crashes (5087036, 4556344) now that widget previews are loaded asynchronously.
Change-Id: I2cfc0760bb563360434c7a8ecf4b198c20d15be6
Diffstat (limited to 'src/com/android/launcher2/FocusHelper.java')
-rw-r--r--src/com/android/launcher2/FocusHelper.java28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/com/android/launcher2/FocusHelper.java b/src/com/android/launcher2/FocusHelper.java
index 3783d566c..f97492bd6 100644
--- a/src/com/android/launcher2/FocusHelper.java
+++ b/src/com/android/launcher2/FocusHelper.java
@@ -139,6 +139,9 @@ public class FocusHelper {
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
PagedViewGridLayout newParent = null;
+ // Now that we load items in the bg asynchronously, we can't just focus
+ // child siblings willy-nilly
+ View child = null;
boolean wasHandled = false;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
@@ -150,7 +153,8 @@ public class FocusHelper {
if (pageIndex > 0) {
newParent = (PagedViewGridLayout)
container.getChildAt(pageIndex - 1);
- newParent.getChildAt(newParent.getChildCount() - 1).requestFocus();
+ child = newParent.getChildAt(newParent.getChildCount() - 1);
+ if (child != null) child.requestFocus();
}
}
}
@@ -165,7 +169,8 @@ public class FocusHelper {
if (pageIndex < (pageCount - 1)) {
newParent = (PagedViewGridLayout)
container.getChildAt(pageIndex + 1);
- newParent.getChildAt(0).requestFocus();
+ child = newParent.getChildAt(0);
+ if (child != null) child.requestFocus();
}
}
}
@@ -176,7 +181,8 @@ public class FocusHelper {
// Select the closest icon in the previous row, otherwise select the tab bar
if (y > 0) {
int newWidgetIndex = ((y - 1) * cellCountX) + x;
- parent.getChildAt(newWidgetIndex).requestFocus();
+ child = parent.getChildAt(newWidgetIndex);
+ if (child != null) child.requestFocus();
} else {
tabs.requestFocus();
}
@@ -188,7 +194,8 @@ public class FocusHelper {
// Select the closest icon in the previous row, otherwise do nothing
if (y < (cellCountY - 1)) {
int newWidgetIndex = Math.min(widgetCount - 1, ((y + 1) * cellCountX) + x);
- parent.getChildAt(newWidgetIndex).requestFocus();
+ child = parent.getChildAt(newWidgetIndex);
+ if (child != null) child.requestFocus();
}
}
wasHandled = true;
@@ -208,10 +215,11 @@ public class FocusHelper {
// if there is no previous page
if (pageIndex > 0) {
newParent = (PagedViewGridLayout) container.getChildAt(pageIndex - 1);
- newParent.getChildAt(0).requestFocus();
+ child = newParent.getChildAt(0);
} else {
- parent.getChildAt(0).requestFocus();
+ child = parent.getChildAt(0);
}
+ if (child != null) child.requestFocus();
}
wasHandled = true;
break;
@@ -221,17 +229,19 @@ public class FocusHelper {
// if there is no next page
if (pageIndex < (pageCount - 1)) {
newParent = (PagedViewGridLayout) container.getChildAt(pageIndex + 1);
- newParent.getChildAt(0).requestFocus();
+ child = newParent.getChildAt(0);
} else {
- parent.getChildAt(widgetCount - 1).requestFocus();
+ child = parent.getChildAt(widgetCount - 1);
}
+ if (child != null) child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_HOME:
if (handleKeyEvent) {
// Select the first item on this page
- parent.getChildAt(0).requestFocus();
+ child = parent.getChildAt(0);
+ if (child != null) child.requestFocus();
}
wasHandled = true;
break;