OSDN Git Service

Trebuchet: Index folder contents screen and cells on first load
authorcretin45 <cretin45@gmail.com>
Tue, 10 May 2016 20:36:09 +0000 (13:36 -0700)
committercretin45 <cretin45@gmail.com>
Tue, 10 May 2016 21:48:32 +0000 (14:48 -0700)
Issue-id: CYNGNOS-2755

Change-Id: I260d1b098e7759a0134bc40f892b8783452c9528

src/com/android/launcher3/FolderPagedView.java
src/com/android/launcher3/LauncherModel.java
src/com/android/launcher3/Utilities.java

index 5d5ac3d..9134dc9 100644 (file)
@@ -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);
index 687e565..5e2a641 100644 (file)
@@ -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++;
+                                }
+                            }
                         }
                     }
                 }
index bf11aa1..8ffc471 100644 (file)
@@ -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));
     }