summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2016-05-10 20:36:09 (GMT)
committercretin45 <cretin45@gmail.com>2016-05-10 21:48:32 (GMT)
commit499902463bb16aad036a57b9e02b34cb74548acf (patch)
treec7aff077b09b069f732982b33182443ae98adf6f
parentba9f5508210d6534fa3d8c24679c153be638bf08 (diff)
downloadandroid_packages_apps_Trebuchet-499902463bb16aad036a57b9e02b34cb74548acf.zip
android_packages_apps_Trebuchet-499902463bb16aad036a57b9e02b34cb74548acf.tar.gz
android_packages_apps_Trebuchet-499902463bb16aad036a57b9e02b34cb74548acf.tar.bz2
Trebuchet: Index folder contents screen and cells on first load
Issue-id: CYNGNOS-2755 Change-Id: I260d1b098e7759a0134bc40f892b8783452c9528
-rw-r--r--src/com/android/launcher3/FolderPagedView.java32
-rw-r--r--src/com/android/launcher3/LauncherModel.java37
-rw-r--r--src/com/android/launcher3/Utilities.java34
3 files changed, 72 insertions, 31 deletions
diff --git a/src/com/android/launcher3/FolderPagedView.java b/src/com/android/launcher3/FolderPagedView.java
index 5d5ac3d..9134dc9 100644
--- a/src/com/android/launcher3/FolderPagedView.java
+++ b/src/com/android/launcher3/FolderPagedView.java
@@ -18,6 +18,7 @@ package com.android.launcher3;
import android.annotation.SuppressLint;
import android.content.Context;
+import android.graphics.Point;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
@@ -116,34 +117,9 @@ public class FolderPagedView extends PagedView {
*/
public void setupContentDimensions(int count) {
mAllocatedContentSize = count;
- boolean done;
- if (count >= mMaxItemsPerPage) {
- mGridCountX = mMaxCountX;
- mGridCountY = mMaxCountY;
- done = true;
- } else {
- done = false;
- }
-
- while (!done) {
- int oldCountX = mGridCountX;
- int oldCountY = mGridCountY;
- if (mGridCountX * mGridCountY < count) {
- // Current grid is too small, expand it
- if ((mGridCountX <= mGridCountY || mGridCountY == mMaxCountY) && mGridCountX < mMaxCountX) {
- mGridCountX++;
- } else if (mGridCountY < mMaxCountY) {
- mGridCountY++;
- }
- if (mGridCountY == 0) mGridCountY++;
- } else if ((mGridCountY - 1) * mGridCountX >= count && mGridCountY >= mGridCountX) {
- mGridCountY = Math.max(0, mGridCountY - 1);
- } else if ((mGridCountX - 1) * mGridCountY >= count) {
- mGridCountX = Math.max(0, mGridCountX - 1);
- }
- done = mGridCountX == oldCountX && mGridCountY == oldCountY;
- }
-
+ Point point = Utilities.caluclateFolderContentDimensions(count, mMaxCountX, mMaxCountY);
+ mGridCountX = point.x;
+ mGridCountY = point.y;
// Update grid size
for (int i = getPageCount() - 1; i >= 0; i--) {
getPageAt(i).setGridSize(mGridCountX, mGridCountY);
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 687e565..5e2a641 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -34,6 +34,7 @@ import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
+import android.graphics.Point;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
@@ -2451,13 +2452,43 @@ public class LauncherModel extends BroadcastReceiver
for (FolderInfo folder : sBgFolders) {
Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR);
int pos = 0;
+ int needIndexing = 0;
for (ShortcutInfo info : folder.contents) {
- if (info.usingLowResIcon) {
+ if (info.usingLowResIcon && pos < FolderIcon.NUM_ITEMS_IN_PREVIEW) {
info.updateIcon(mIconCache, false);
}
pos ++;
- if (pos >= FolderIcon.NUM_ITEMS_IN_PREVIEW) {
- break;
+ needIndexing += info.screenId + info.cellX + info.cellY;
+ }
+ // If all screenId, cellX, and cellY are 0, then we assume they were all null.
+ if (needIndexing == 0) {
+ synchronized (sBgLock) {
+ int curX = 0;
+ int curY = 0;
+ int folderScreenId = 0;
+ int folderCount = folder.contents.size();
+ Point point = Utilities
+ .caluclateFolderContentDimensions(folderCount, countX, countY);
+ int maxX = point.x;
+ int maxY = point.y;
+ for (ShortcutInfo info : folder.contents) {
+ ItemInfo itemInfo = sBgItemsIdMap.get(info.id);
+ if (curY == maxY) { // New screen
+ curX = 0;
+ curY = 0;
+ folderScreenId++;
+ }
+ itemInfo.screenId = folderScreenId;
+ itemInfo.cellX = curX;
+ itemInfo.cellY = curY;
+ LauncherModel.updateItemInDatabase(context, itemInfo);
+ if (curX == maxX - 1) {
+ curX = 0;
+ curY++;
+ } else {
+ curX++;
+ }
+ }
}
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index bf11aa1..8ffc471 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -39,6 +39,7 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
+import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -706,6 +707,39 @@ public final class Utilities {
size, metrics));
}
+ public static Point caluclateFolderContentDimensions(int count, int maxCountX, int maxCountY) {
+ final Point point = new Point();
+ final int maxItemsPerPage = maxCountX * maxCountY;
+ boolean done;
+ if (count >= maxItemsPerPage) {
+ point.x = maxCountX;
+ point.y = maxCountY;
+ done = true;
+ } else {
+ done = false;
+ }
+
+ while (!done) {
+ int oldCountX = point.x;
+ int oldCountY = point.y;
+ if (point.x * point.y < count) {
+ // Current grid is too small, expand it
+ if ((point.x <= point.y || point.y == maxCountY) && point.x < maxCountX) {
+ point.x++;
+ } else if (point.y < maxCountY) {
+ point.y++;
+ }
+ if (point.y == 0) point.y++;
+ } else if ((point.y - 1) * point.x >= count && point.y >= point.x) {
+ point.y = Math.max(0, point.y - 1);
+ } else if ((point.x - 1) * point.y >= count) {
+ point.x = Math.max(0, point.x - 1);
+ }
+ done = point.x == oldCountX && point.y == oldCountY;
+ }
+ return point;
+ }
+
public static String createDbSelectionQuery(String columnName, Iterable<?> values) {
return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, TextUtils.join(", ", values));
}