am e6abe6c6: Merge "Reducing memory impact of hardware layers in Launcher" into honeycomb

* commit 'e6abe6c6a70c1e26b7765217e94b1d46b5388079':
  Reducing memory impact of hardware layers in Launcher
This commit is contained in:
Michael Jurka authored and Android Git Automerger committed 2011-02-03 20:25:39 -08:00
commit d7ecd3d70d
6 files changed
+54 -4

No files matched your search

@@ -425,6 +425,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
// add any necessary pages // add any necessary pages
for (int i = curNumPages; i < numPages; ++i) { for (int i = curNumPages; i < numPages; ++i) {
PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
layout.enableHardwareLayers();
layout.setCellCount(mCellCountX, mCellCountY); layout.setCellCount(mCellCountX, mCellCountY);
layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
mPageLayoutPaddingRight, mPageLayoutPaddingBottom); mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
@@ -47,6 +47,7 @@ public class CachedTextView extends TextView {
private float mPaddingH = 0; private float mPaddingH = 0;
private float mPaddingV = 0; private float mPaddingV = 0;
private CharSequence mText; private CharSequence mText;
private boolean mEnabled = true;
public CachedTextView(Context context) { public CachedTextView(Context context) {
super(context); super(context);
@@ -73,6 +74,10 @@ public class CachedTextView extends TextView {
return 0; return 0;
} }
public void disableCache() {
mEnabled = false;
}
public void setText(CharSequence text, BufferType type) { public void setText(CharSequence text, BufferType type) {
super.setText(text, type); super.setText(text, type);
mIsTextCacheDirty = true; mIsTextCacheDirty = true;
@@ -138,7 +143,7 @@ public class CachedTextView extends TextView {
} }
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
if (mIsTextCacheDirty && !mIsBuildingCache) { if (mEnabled && mIsTextCacheDirty && !mIsBuildingCache) {
buildAndUpdateCache(); buildAndUpdateCache();
mIsTextCacheDirty = false; mIsTextCacheDirty = false;
} }
+14
View File
@@ -596,7 +596,21 @@ public abstract class PagedView extends ViewGroup {
canvas.clipRect(mScrollX, mScrollY, mScrollX + mRight - mLeft, canvas.clipRect(mScrollX, mScrollY, mScrollX + mRight - mLeft,
mScrollY + mBottom - mTop); mScrollY + mBottom - mTop);
for (int i = 0; i < pageCount; i++) {
View child = getChildAt(i);
if (child != null && child instanceof PagedViewCellLayout) {
boolean willBeDrawn = i >= leftScreen && i <= rightScreen;
if (!willBeDrawn) {
((PagedViewCellLayout)child).destroyHardwareLayers();
}
}
}
for (int i = leftScreen; i <= rightScreen; i++) { for (int i = leftScreen; i <= rightScreen; i++) {
View child = getChildAt(i);
if (child != null && child instanceof PagedViewCellLayout) {
((PagedViewCellLayout)child).createHardwareLayers();
}
drawChild(canvas, getChildAt(i), drawingTime); drawChild(canvas, getChildAt(i), drawingTime);
} }
canvas.restore(); canvas.restore();
@@ -40,6 +40,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
private static int sDefaultCellDimensions = 96; private static int sDefaultCellDimensions = 96;
protected PagedViewCellLayoutChildren mChildren; protected PagedViewCellLayoutChildren mChildren;
private PagedViewCellLayoutChildren mHolographicChildren; private PagedViewCellLayoutChildren mHolographicChildren;
private boolean mUseHardwareLayers = false;
public PagedViewCellLayout(Context context) { public PagedViewCellLayout(Context context) {
this(context, null); this(context, null);
@@ -73,12 +74,29 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
addView(mHolographicChildren); addView(mHolographicChildren);
} }
public void enableHardwareLayers() {
mUseHardwareLayers = true;
}
@Override @Override
public void setAlpha(float alpha) { public void setAlpha(float alpha) {
mChildren.setAlpha(alpha); mChildren.setAlpha(alpha);
mHolographicChildren.setAlpha(1.0f - alpha); mHolographicChildren.setAlpha(1.0f - alpha);
} }
void destroyHardwareLayers() {
if (mUseHardwareLayers) {
mChildren.destroyHardwareLayer();
mHolographicChildren.destroyHardwareLayer();
}
}
void createHardwareLayers() {
if (mUseHardwareLayers) {
mChildren.createHardwareLayer();
mHolographicChildren.createHardwareLayer();
}
}
@Override @Override
public void cancelLongPress() { public void cancelLongPress() {
super.cancelLongPress(); super.cancelLongPress();
@@ -109,6 +127,9 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
if (child instanceof PagedViewIcon) { if (child instanceof PagedViewIcon) {
PagedViewIcon pagedViewIcon = (PagedViewIcon) child; PagedViewIcon pagedViewIcon = (PagedViewIcon) child;
if (mUseHardwareLayers) {
pagedViewIcon.disableCache();
}
mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(), index, lp); mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(), index, lp);
} }
return true; return true;
@@ -18,7 +18,6 @@ package com.android.launcher2;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -39,7 +38,6 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
public PagedViewCellLayoutChildren(Context context) { public PagedViewCellLayoutChildren(Context context) {
super(context); super(context);
setLayerType(LAYER_TYPE_HARDWARE, null);
} }
@Override @Override
@@ -140,6 +138,17 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
} }
} }
void destroyHardwareLayer() {
if (getLayerType() == LAYER_TYPE_HARDWARE) {
setLayerType(LAYER_TYPE_NONE, null);
}
}
void createHardwareLayer() {
if (getLayerType() == LAYER_TYPE_NONE) {
setLayerType(LAYER_TYPE_HARDWARE, null);
}
}
public void enableCenteredContent(boolean enabled) { public void enableCenteredContent(boolean enabled) {
mCenterContent = enabled; mCenterContent = enabled;
} }
+1 -1
View File
@@ -40,7 +40,7 @@ import android.widget.TextView;
* An icon on a PagedView, specifically for items in the launcher's paged view (with compound * An icon on a PagedView, specifically for items in the launcher's paged view (with compound
* drawables on the top). * drawables on the top).
*/ */
public class PagedViewIcon extends TextView implements Checkable { public class PagedViewIcon extends CachedTextView implements Checkable {
private static final String TAG = "PagedViewIcon"; private static final String TAG = "PagedViewIcon";
// holographic outline // holographic outline