summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2011-08-18 10:55:17 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-18 10:55:17 -0700
commited718b18a9c9633be9543b59c0a81ca12c509550 (patch)
treebf07125078062744c647fbc9c2cc5f52b223ff7d /src
parentb0fa3529edf7c4f6ce088d23d80461dcad43aa15 (diff)
parent5afbf7bdd6f6879124c9b8283e005fe57f310d02 (diff)
downloadandroid_packages_apps_Trebuchet-ed718b18a9c9633be9543b59c0a81ca12c509550.tar.gz
android_packages_apps_Trebuchet-ed718b18a9c9633be9543b59c0a81ca12c509550.tar.bz2
android_packages_apps_Trebuchet-ed718b18a9c9633be9543b59c0a81ca12c509550.zip
Merge "Saving/restoring current page in AppsCustomize. (5050168)"
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AppsCustomizePagedView.java77
-rw-r--r--src/com/android/launcher2/Launcher.java6
-rw-r--r--src/com/android/launcher2/PagedView.java2
-rw-r--r--src/com/android/launcher2/PagedViewCellLayout.java4
4 files changed, 85 insertions, 4 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 81586249f..949d87266 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -164,6 +164,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
private final LayoutInflater mLayoutInflater;
private final PackageManager mPackageManager;
+ // Save and Restore
+ private int mSaveInstanceStateItemIndex = -1;
+ private int mRestorePage = -1;
+
// Content
private ContentType mContentType;
private ArrayList<ApplicationInfo> mApps;
@@ -253,6 +257,58 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
}
+ /** Returns the item index of the center item on this page so that we can restore to this
+ * item index when we rotate. */
+ private int getMiddleComponentIndexOnCurrentPage() {
+ int i = -1;
+ if (getPageCount() > 0) {
+ int currentPage = getCurrentPage();
+ switch (mContentType) {
+ case Applications: {
+ PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(currentPage);
+ PagedViewCellLayoutChildren childrenLayout = layout.getChildrenLayout();
+ int numItemsPerPage = mCellCountX * mCellCountY;
+ int childCount = childrenLayout.getChildCount();
+ if (childCount > 0) {
+ i = (currentPage * numItemsPerPage) + (childCount / 2);
+ }}
+ break;
+ case Widgets: {
+ PagedViewGridLayout layout = (PagedViewGridLayout) getChildAt(currentPage);
+ int numItemsPerPage = mWidgetCountX * mWidgetCountY;
+ int childCount = layout.getChildCount();
+ if (childCount > 0) {
+ i = (currentPage * numItemsPerPage) + (childCount / 2);
+ }}
+ break;
+ }
+ }
+ return i;
+ }
+
+ /** Get the index of the item to restore to if we need to restore the current page. */
+ int getSaveInstanceStateIndex() {
+ if (mSaveInstanceStateItemIndex == -1) {
+ mSaveInstanceStateItemIndex = getMiddleComponentIndexOnCurrentPage();
+ }
+ return mSaveInstanceStateItemIndex;
+ }
+
+ /** Returns the page in the current orientation which is expected to contain the specified
+ * item index. */
+ int getPageForComponent(int index) {
+ switch (mContentType) {
+ case Applications: {
+ int numItemsPerPage = mCellCountX * mCellCountY;
+ return (index / numItemsPerPage);
+ }
+ case Widgets: {
+ int numItemsPerPage = mWidgetCountX * mWidgetCountY;
+ return (index / numItemsPerPage);
+ }}
+ return -1;
+ }
+
/**
* This differs from isDataReady as this is the test done if isDataReady is not set.
*/
@@ -262,6 +318,20 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
return !mApps.isEmpty();
}
+ /** Restores the page for an item at the specified index */
+ void restorePageForIndex(int index) {
+ if (index < 0) return;
+
+ int page = getPageForComponent(index);
+ if (page > -1) {
+ if (getChildCount() > 0) {
+ invalidatePageData(page);
+ } else {
+ mRestorePage = page;
+ }
+ }
+ }
+
protected void onDataReady(int width, int height) {
// Note that we transpose the counts in portrait so that we get a similar layout
boolean isLandscape = getResources().getConfiguration().orientation ==
@@ -289,7 +359,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
mWidgetSpacingLayout.measure(widthSpec, heightSpec);
mContentWidth = mWidgetSpacingLayout.getContentWidth();
- invalidatePageData();
+ invalidatePageData(Math.max(0, mRestorePage));
+ mRestorePage = -1;
}
@Override
@@ -1076,6 +1147,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
setChildrenDrawnWithCacheEnabled(false);
*/
super.onPageEndMoving();
+
+ // We reset the save index when we change pages so that it will be recalculated on next
+ // rotation
+ mSaveInstanceStateItemIndex = -1;
}
/*
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index dc0120bb2..a0601e004 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -673,8 +673,8 @@ public final class Launcher extends Activity
mAppsCustomizeContent.getCurrentPage());
}
- // Note: currently we do not restore the page for the AppsCustomize pane because the
- // change in layout can drastically affect the saved page index
+ int currentIndex = savedState.getInt("apps_customize_currentIndex");
+ mAppsCustomizeContent.restorePageForIndex(currentIndex);
}
}
@@ -1145,6 +1145,8 @@ public final class Launcher extends Activity
if (currentTabTag != null) {
outState.putString("apps_customize_currentTab", currentTabTag);
}
+ int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
+ outState.putInt("apps_customize_currentIndex", currentIndex);
}
}
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 6e2636354..40e23286e 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -1649,7 +1649,7 @@ public abstract class PagedView extends ViewGroup {
// Set a new page as the current page if necessary
if (currentPage > -1) {
- setCurrentPage(currentPage);
+ setCurrentPage(Math.min(getPageCount() - 1, currentPage));
}
// Mark each of the pages as dirty
diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java
index 63cf9e8bf..803e70060 100644
--- a/src/com/android/launcher2/PagedViewCellLayout.java
+++ b/src/com/android/launcher2/PagedViewCellLayout.java
@@ -192,6 +192,10 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
return mChildren.getChildCount();
}
+ public PagedViewCellLayoutChildren getChildrenLayout() {
+ return mChildren;
+ }
+
@Override
public View getChildOnPageAt(int i) {
return mChildren.getChildAt(i);