From 6a70e9fc3c62cc83d6abe59323d622dc6cd224a7 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 17 May 2011 16:24:49 -0700 Subject: Fixing issue where holographic icons could get out of sync in AllApps (when number of pages changes). Change-Id: I1a63d4837c5b726a90229430f5fc698aa1db5550 --- src/com/android/launcher2/AllAppsPagedView.java | 10 +++++---- .../android/launcher2/AppsCustomizePagedView.java | 3 +-- src/com/android/launcher2/CustomizePagedView.java | 6 ++---- src/com/android/launcher2/PagedViewCellLayout.java | 23 +++++++++++--------- .../launcher2/PagedViewCellLayoutChildren.java | 22 +++++++++++++++++++ src/com/android/launcher2/PagedViewIcon.java | 25 ++++++++++++++-------- 6 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index d9a503fbe..c812a4698 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -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(); } diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 14e051c64..87be63efa 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -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)); } } /* diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index e5bc8b8a5..b2e308d76 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -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)); } } diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 6a3c84d03..9022cac18 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -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 diff --git a/src/com/android/launcher2/PagedViewCellLayoutChildren.java b/src/com/android/launcher2/PagedViewCellLayoutChildren.java index 92ff46184..6333f7f2e 100644 --- a/src/com/android/launcher2/PagedViewCellLayoutChildren.java +++ b/src/com/android/launcher2/PagedViewCellLayoutChildren.java @@ -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(); + } + } + } } diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java index e23f1c6d1..306ff9e7b 100644 --- a/src/com/android/launcher2/PagedViewIcon.java +++ b/src/com/android/launcher2/PagedViewIcon.java @@ -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; } -- cgit v1.2.3