am 307f0b4d: am 12dd20d5: Merge "Fixing issue where we were not always invalidating the page data when setting apps. (Bug 6549598)" into jb-dev
* commit '307f0b4d4d6a49e87342a66bb9bb0adb4a36352a':
Fixing issue where we were not always invalidating the page data when setting apps. (Bug 6549598)
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 30d3cf8..a255466 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -430,16 +430,6 @@
}
}
- /**
- * This differs from isDataReady as this is the test done if isDataReady is not set.
- */
- private boolean testDataReady() {
- // We only do this test once, and we default to the Applications page, so we only really
- // have to wait for there to be apps.
- // TODO: What if one of them is validly empty
- return !mApps.isEmpty() && !mWidgets.isEmpty();
- }
-
/** Restores the page for an item at the specified index */
void restorePageForIndex(int index) {
if (index < 0) return;
@@ -511,7 +501,7 @@
}
void showAllAppsCling() {
- if (!mHasShownAllAppsCling && isDataReady() && testDataReady()) {
+ if (!mHasShownAllAppsCling && isDataReady()) {
mHasShownAllAppsCling = true;
// Calculate the position for the cling punch through
int[] offset = new int[2];
@@ -530,7 +520,7 @@
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (!isDataReady()) {
- if (testDataReady()) {
+ if (!mApps.isEmpty() && !mWidgets.isEmpty()) {
setDataIsReady();
setMeasuredDimension(width, height);
onDataReady(width, height);
@@ -557,7 +547,6 @@
public void updatePackages() {
// Get the list of widgets and shortcuts
- boolean wasEmpty = mWidgets.isEmpty();
mWidgets.clear();
List<AppWidgetProviderInfo> widgets =
AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
@@ -585,17 +574,9 @@
mWidgets.addAll(shortcuts);
Collections.sort(mWidgets,
new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
- Log.d(TAG, "6549598 updatePackages mWidgets.size(): " + mWidgets.size() + " wasEmpty: " + wasEmpty);
+ Log.d(TAG, "6549598 updatePackages mWidgets.size(): " + mWidgets.size());
updatePageCounts();
-
- if (wasEmpty) {
- // The next layout pass will trigger data-ready if both widgets and apps are set, so request
- // a layout to do this test and invalidate the page data when ready.
- if (testDataReady()) requestLayout();
- } else {
- cancelAllTasks();
- invalidatePageData();
- }
+ invalidateOnDataChange();
}
@Override
@@ -1734,16 +1715,31 @@
public boolean isAnimating() {
return false;
}
+
+ /**
+ * We should call thise method whenever the core data changes (mApps, mWidgets) so that we can
+ * appropriately determine when to invalidate the PagedView page data. In cases where the data
+ * has yet to be set, we can requestLayout() and wait for onDataReady() to be called in the
+ * next onMeasure() pass, which will trigger an invalidatePageData() itself.
+ */
+ private void invalidateOnDataChange() {
+ if (!isDataReady()) {
+ // The next layout pass will trigger data-ready if both widgets and apps are set, so
+ // request a layout to trigger the page data when ready.
+ requestLayout();
+ } else {
+ cancelAllTasks();
+ invalidatePageData();
+ }
+ }
+
@Override
public void setApps(ArrayList<ApplicationInfo> list) {
mApps = list;
Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Log.d(TAG, "6549598 setApps mApps.size(): " + mApps.size());
updatePageCounts();
-
- // The next layout pass will trigger data-ready if both widgets and apps are set, so
- // request a layout to do this test and invalidate the page data when ready.
- if (testDataReady()) requestLayout();
+ invalidateOnDataChange();
}
private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
// We add it in place, in alphabetical order
@@ -1761,7 +1757,7 @@
addAppsWithoutInvalidate(list);
Log.d(TAG, "6549598 addApps mApps.size(): " + mApps.size() + " list.size(): " + list.size());
updatePageCounts();
- invalidatePageData();
+ invalidateOnDataChange();
Log.d(TAG, "6549598 addApps mNumAppsPages: " + mNumAppsPages);
}
private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) {
@@ -1791,7 +1787,7 @@
removeAppsWithoutInvalidate(list);
Log.d(TAG, "6549598 removeApps mApps.size(): " + mApps.size() + " list.size(): " + list.size());
updatePageCounts();
- invalidatePageData();
+ invalidateOnDataChange();
Log.d(TAG, "6549598 removeApps mNumAppsPages: " + mNumAppsPages);
}
@Override
@@ -1803,7 +1799,7 @@
addAppsWithoutInvalidate(list);
Log.d(TAG, "6549598 updateApps mApps.size(): " + mApps.size() + " list.size(): " + list.size());
updatePageCounts();
- invalidatePageData();
+ invalidateOnDataChange();
Log.d(TAG, "6549598 updateApps mNumAppsPages: " + mNumAppsPages);
}