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

This commit is contained in:
Michael Jurka
2011-02-03 20:23:44 -08:00
committed by Android (Google) Code Review
6 changed files with 54 additions and 4 deletions
@@ -425,6 +425,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
// add any necessary pages
for (int i = curNumPages; i < numPages; ++i) {
PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
layout.enableHardwareLayers();
layout.setCellCount(mCellCountX, mCellCountY);
layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
@@ -47,6 +47,7 @@ public class CachedTextView extends TextView {
private float mPaddingH = 0;
private float mPaddingV = 0;
private CharSequence mText;
private boolean mEnabled = true;
public CachedTextView(Context context) {
super(context);
@@ -73,6 +74,10 @@ public class CachedTextView extends TextView {
return 0;
}
public void disableCache() {
mEnabled = false;
}
public void setText(CharSequence text, BufferType type) {
super.setText(text, type);
mIsTextCacheDirty = true;
@@ -138,7 +143,7 @@ public class CachedTextView extends TextView {
}
public void draw(Canvas canvas) {
if (mIsTextCacheDirty && !mIsBuildingCache) {
if (mEnabled && mIsTextCacheDirty && !mIsBuildingCache) {
buildAndUpdateCache();
mIsTextCacheDirty = false;
}
+14
View File
@@ -596,7 +596,21 @@ public abstract class PagedView extends ViewGroup {
canvas.clipRect(mScrollX, mScrollY, mScrollX + mRight - mLeft,
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++) {
View child = getChildAt(i);
if (child != null && child instanceof PagedViewCellLayout) {
((PagedViewCellLayout)child).createHardwareLayers();
}
drawChild(canvas, getChildAt(i), drawingTime);
}
canvas.restore();
@@ -40,6 +40,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
private static int sDefaultCellDimensions = 96;
protected PagedViewCellLayoutChildren mChildren;
private PagedViewCellLayoutChildren mHolographicChildren;
private boolean mUseHardwareLayers = false;
public PagedViewCellLayout(Context context) {
this(context, null);
@@ -73,12 +74,29 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
addView(mHolographicChildren);
}
public void enableHardwareLayers() {
mUseHardwareLayers = true;
}
@Override
public void setAlpha(float alpha) {
mChildren.setAlpha(alpha);
mHolographicChildren.setAlpha(1.0f - alpha);
}
void destroyHardwareLayers() {
if (mUseHardwareLayers) {
mChildren.destroyHardwareLayer();
mHolographicChildren.destroyHardwareLayer();
}
}
void createHardwareLayers() {
if (mUseHardwareLayers) {
mChildren.createHardwareLayer();
mHolographicChildren.createHardwareLayer();
}
}
@Override
public void cancelLongPress() {
super.cancelLongPress();
@@ -109,6 +127,9 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
if (child instanceof PagedViewIcon) {
PagedViewIcon pagedViewIcon = (PagedViewIcon) child;
if (mUseHardwareLayers) {
pagedViewIcon.disableCache();
}
mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(), index, lp);
}
return true;
@@ -18,7 +18,6 @@ package com.android.launcher2;
import android.content.Context;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -39,7 +38,6 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
public PagedViewCellLayoutChildren(Context context) {
super(context);
setLayerType(LAYER_TYPE_HARDWARE, null);
}
@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) {
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
* drawables on the top).
*/
public class PagedViewIcon extends TextView implements Checkable {
public class PagedViewIcon extends CachedTextView implements Checkable {
private static final String TAG = "PagedViewIcon";
// holographic outline