OSDN Git Service

Fixing issue where holographic icons could get out of sync in AllApps (when number...
authorWinson Chung <winsonc@google.com>
Tue, 17 May 2011 23:24:49 +0000 (16:24 -0700)
committerWinson Chung <winsonc@google.com>
Wed, 18 May 2011 00:06:59 +0000 (17:06 -0700)
Change-Id: I1a63d4837c5b726a90229430f5fc698aa1db5550

src/com/android/launcher2/AllAppsPagedView.java
src/com/android/launcher2/AppsCustomizePagedView.java
src/com/android/launcher2/CustomizePagedView.java
src/com/android/launcher2/PagedViewCellLayout.java
src/com/android/launcher2/PagedViewCellLayoutChildren.java
src/com/android/launcher2/PagedViewIcon.java

index d9a503f..c812a46 100644 (file)
@@ -517,6 +517,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
         if (!mFilteredApps.isEmpty()) {
             int curNumPageItems = layout.getPageChildCount();
             int numPageItems = endIndex - startIndex;
+            boolean createHolographicOutlines = (numPages > 1);
 
             // If we were previously an empty page, then restart anew
             boolean wasEmptyPage = false;
@@ -541,7 +542,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
 
             // Add any necessary items
             for (int i = curNumPageItems; i < numPageItems; ++i) {
-                final boolean createHolographicOutlines = (numPages > 1);
                 TextView text = (TextView) mInflater.inflate(
                         R.layout.all_apps_paged_view_application, layout, false);
                 text.setOnClickListener(this);
@@ -549,14 +549,13 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
                 text.setOnTouchListener(this);
 
                 layout.addViewToCellLayout(text, -1, i,
-                    new PagedViewCellLayout.LayoutParams(0, 0, 1, 1), createHolographicOutlines);
+                    new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
             }
 
             // Actually reapply to the existing text views
             for (int i = startIndex; i < endIndex; ++i) {
                 final int index = i - startIndex;
                 final ApplicationInfo info = mFilteredApps.get(i);
-                final boolean createHolographicOutlines = (numPages > 1);
                 PagedViewIcon icon = (PagedViewIcon) layout.getChildOnPageAt(index);
                 icon.applyFromApplicationInfo(
                         info, mPageViewIconCache, true, createHolographicOutlines);
@@ -567,6 +566,9 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
                 params.cellY = index / mCellCountX;
             }
 
+            // We should try and sync all the holographic icons after adding/removing new items
+            layout.reloadHolographicIcons(createHolographicOutlines);
+
             // Default to left-aligned icons
             layout.enableCenteredContent(false);
         } else {
@@ -585,7 +587,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
             layout.enableCenteredContent(true);
             layout.removeAllViewsOnPage();
             layout.addViewToCellLayout(icon, -1, 0,
-                    new PagedViewCellLayout.LayoutParams(0, 0, 4, 1), createHolographicOutlines);
+                    new PagedViewCellLayout.LayoutParams(0, 0, 4, 1));
         }
         layout.createHardwareLayers();
     }
index 14e051c..87be63e 100644 (file)
@@ -561,8 +561,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
             int index = i - startIndex;
             int x = index % mCellCountX;
             int y = index / mCellCountX;
-            layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1),
-                    isHardwareAccelerated() && (numPages > 1));
+            layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
         }
     }
     /*
index e5bc8b8..b2e308d 100644 (file)
@@ -1042,8 +1042,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
             final int x = index % mCellCountX;
             final int y = index / mCellCountX;
             setupPage(layout);
-            layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1),
-                    createHolographicOutlines);
+            layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
         }
     }
 
@@ -1088,8 +1087,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
             final int x = index % mCellCountX;
             final int y = index / mCellCountX;
             setupPage(layout);
-            layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1),
-                    createHolographicOutlines);
+            layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
         }
     }
 
index 6a3c84d..9022cac 100644 (file)
@@ -128,8 +128,17 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
         }
     }
 
+    /** Syncs the holographic icon views to the child icon views */
+    public void reloadHolographicIcons(boolean createHolographicOutlines) {
+        if (createHolographicOutlines) {
+            mChildren.loadHolographicOutlines();
+        } else {
+            mChildren.clearHolographicOutlines();
+        }
+    }
+
     public boolean addViewToCellLayout(View child, int index, int childId,
-            PagedViewCellLayout.LayoutParams params, boolean createHolographicOutlines) {
+            PagedViewCellLayout.LayoutParams params) {
         final PagedViewCellLayout.LayoutParams lp = params;
 
         // Generate an id for each view, this assumes we have at most 256x256 cells
@@ -149,10 +158,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
                 if (mAllowHardwareLayerCreation) {
                     pagedViewIcon.disableCache();
                 }
-                if (createHolographicOutlines) {
-                    mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(),
-                            index, lp);
-                }
+                mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(),
+                        index, lp);
             }
             return true;
         }
@@ -169,11 +176,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
     @Override
     public void removeViewOnPageAt(int index) {
         mChildren.removeViewAt(index);
-        // Holographic icons are disabled in certain cases (on lower hardware, or if there is only
-        // one page), so check before we try and remove the view at a specified index.
-        if (mHolographicChildren.getChildAt(index) != null) {
-            mHolographicChildren.removeViewAt(index);
-        }
+        mHolographicChildren.removeViewAt(index);
     }
 
     @Override
index 92ff461..6333f7f 100644 (file)
@@ -165,4 +165,26 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
             }
         }
     }
+
+    public void loadHolographicOutlines() {
+        int count = getChildCount();
+        for (int i = 0; i < count; i++) {
+            View view = getChildAt(i);
+            if (view instanceof PagedViewIcon) {
+                PagedViewIcon icon = (PagedViewIcon) view;
+                icon.loadHolographicIcon();
+            }
+        }
+    }
+
+    public void clearHolographicOutlines() {
+        int count = getChildCount();
+        for (int i = 0; i < count; i++) {
+            View view = getChildAt(i);
+            if (view instanceof PagedViewIcon) {
+                PagedViewIcon icon = (PagedViewIcon) view;
+                icon.clearHolographicIcon();
+            }
+        }
+    }
 }
index e23f1c6..306ff9e 100644 (file)
@@ -153,16 +153,29 @@ public class PagedViewIcon extends CachedTextView implements Checkable {
         return false;
     }
 
+    public void loadHolographicIcon() {
+        if (mHolographicOutline == null) {
+            mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
+            if (!queueHolographicOutlineCreation()) {
+                getHolographicOutlineView().invalidate();
+            }
+        }
+    }
+    public void clearHolographicIcon() {
+        mHolographicOutline = null;
+        getHolographicOutlineView().invalidate();
+    }
+
     public void applyFromApplicationInfo(ApplicationInfo info, PagedViewIconCache cache,
             boolean scaleUp, boolean createHolographicOutlines) {
+        mIconCache = cache;
+        mIconCacheKey = new PagedViewIconCache.Key(info);
         mIcon = info.iconBitmap;
         setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
         setText(info.title);
         setTag(info);
 
         if (createHolographicOutlines) {
-            mIconCache = cache;
-            mIconCacheKey = new PagedViewIconCache.Key(info);
             mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
             if (!queueHolographicOutlineCreation()) {
                 getHolographicOutlineView().invalidate();
@@ -217,13 +230,7 @@ public class PagedViewIcon extends CachedTextView implements Checkable {
         Bitmap overlay = null;
 
         // draw any blended overlays
-        if (mCheckedOutline == null) {
-            if (canvas.isHardwareAccelerated() && mHolographicOutline != null
-                    && mHolographicAlpha > 0) {
-                mPaint.setAlpha(mHolographicAlpha);
-                overlay = mHolographicOutline;
-            }
-        } else {
+        if (mCheckedOutline != null) {
             mPaint.setAlpha(255);
             overlay = mCheckedOutline;
         }