From 499902463bb16aad036a57b9e02b34cb74548acf Mon Sep 17 00:00:00 2001 From: cretin45 Date: Tue, 10 May 2016 13:36:09 -0700 Subject: Trebuchet: Index folder contents screen and cells on first load Issue-id: CYNGNOS-2755 Change-Id: I260d1b098e7759a0134bc40f892b8783452c9528 --- src/com/android/launcher3/FolderPagedView.java | 32 +++------------------- src/com/android/launcher3/LauncherModel.java | 37 +++++++++++++++++++++++--- src/com/android/launcher3/Utilities.java | 34 +++++++++++++++++++++++ 3 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/com/android/launcher3/FolderPagedView.java b/src/com/android/launcher3/FolderPagedView.java index 5d5ac3d5a..9134dc93e 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 687e56563..5e2a64184 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 bf11aa19e..8ffc471a3 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)); } -- cgit v1.2.3