Improve focus restore on orientation change.
Change-Id: If405c60f4a45aeb4079aa4dcd96b684fd6ea819c
diff --git a/src/com/android/launcher2/AllApps3D.java b/src/com/android/launcher2/AllApps3D.java
index 5f8e9f6..6d0655e 100644
--- a/src/com/android/launcher2/AllApps3D.java
+++ b/src/com/android/launcher2/AllApps3D.java
@@ -127,6 +127,8 @@
private int mRowsPerPage;
private boolean mSurrendered;
+ private int mRestoreFocusIndex = -1;
+
@SuppressWarnings({"UnusedDeclaration"})
static class Defines {
public static final int ALLOC_PARAMS = 0;
@@ -767,6 +769,13 @@
if (mRollo != null && reload) {
mRollo.setApps(list);
}
+
+ if (hasFocus() && mRestoreFocusIndex != -1) {
+ mRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
+ mRollo.mState.save();
+ mRestoreFocusIndex = -1;
+ }
+
mLocks &= ~LOCK_ICONS_PENDING;
}
@@ -1251,8 +1260,10 @@
}
private void setZoom(float zoom, boolean animate) {
- mRollo.clearSelectedIcon();
- mRollo.setHomeSelected(SELECTED_NONE);
+ if (animate) {
+ mRollo.clearSelectedIcon();
+ mRollo.setHomeSelected(SELECTED_NONE);
+ }
if (zoom > 0.001f) {
mRollo.mState.zoomTarget = zoom;
} else {
@@ -1464,6 +1475,9 @@
void selectIcon(int index, int pressed) {
final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
if (appsList == null || index < 0 || index >= appsList.size()) {
+ if (mAllApps != null) {
+ mAllApps.mRestoreFocusIndex = index;
+ }
mState.selectedIconIndex = -1;
if (mAllApps.mLastSelection == SELECTION_ICONS) {
mAllApps.mLastSelection = SELECTION_NONE;
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index f7cb749..1f48f5f 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -551,9 +551,9 @@
mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
mAllAppsGrid.setLauncher(this);
mAllAppsGrid.setDragController(dragController);
- ((View)mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
+ ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
// Manage focusability manually since this thing is always visible
- ((View)mAllAppsGrid).setFocusable(false);
+ ((View) mAllAppsGrid).setFocusable(false);
mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
final Workspace workspace = mWorkspace;
@@ -1707,8 +1707,8 @@
void showAllApps(boolean animated) {
mAllAppsGrid.zoom(1.0f, animated);
- ((View)mAllAppsGrid).setFocusable(true);
- ((View)mAllAppsGrid).requestFocus();
+ ((View) mAllAppsGrid).setFocusable(true);
+ ((View) mAllAppsGrid).requestFocus();
// TODO: fade these two too
mDeleteZone.setVisibility(View.GONE);