Improving performance of state transitions

- Caching CellLayouts to bitmaps when they're small again
- Enabling hardware layers on customize tray/all apps during transition

Change-Id: Ia4f5f7b608a9d013ed48b990551fd1b9de503b32
This commit is contained in:
Michael Jurka
2011-01-28 15:20:01 -08:00
parent e1dc51bce0
commit cf6125c2d3
4 changed files with 18 additions and 20 deletions
+11 -7
View File
@@ -26,6 +26,7 @@ import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
@@ -52,6 +53,15 @@ public class CachedViewGroup extends ViewGroup implements VisibilityChangedListe
public CachedViewGroup(Context context) {
super(context);
init();
}
public CachedViewGroup(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mBackgroundRect = new Rect();
mCacheRect = new Rect();
final Resources res = getResources();
@@ -124,14 +134,13 @@ public class CachedViewGroup extends ViewGroup implements VisibilityChangedListe
float alpha = getAlpha();
setAlpha(1.0f);
isUpdatingCache = true;
draw(mCacheCanvas);
drawChildren(mCacheCanvas);
isUpdatingCache = false;
setAlpha(alpha);
mIsCacheDirty = false;
}
public void drawChildren(Canvas canvas) {
super.dispatchDraw(canvas);
}
@@ -148,11 +157,6 @@ public class CachedViewGroup extends ViewGroup implements VisibilityChangedListe
invalidateCache();
}
public void removeViewWithoutMarkingCells(View view) {
super.removeView(view);
invalidateCache();
}
@Override
public void removeView(View view) {
super.removeView(view);
+2 -10
View File
@@ -50,7 +50,7 @@ import android.view.animation.LayoutAnimationController;
import java.util.Arrays;
public class CellLayout extends ViewGroup {
public class CellLayout extends CachedViewGroup {
static final String TAG = "CellLayout";
private int mCellWidth;
@@ -363,14 +363,6 @@ public class CellLayout extends ViewGroup {
}
}
public void disableCacheUpdates() {
mChildren.disableCacheUpdates();
}
public void enableCacheUpdates() {
mChildren.enableCacheUpdates();
}
@Override
protected void onDraw(Canvas canvas) {
// When we're large, we are either drawn in a "hover" state (ie when dragging an item to
@@ -542,7 +534,7 @@ public class CellLayout extends ViewGroup {
}
public void removeViewWithoutMarkingCells(View view) {
mChildren.removeViewWithoutMarkingCells(view);
mChildren.removeView(view);
}
@Override
@@ -18,11 +18,12 @@ package com.android.launcher2;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.MeasureSpec;
public class CellLayoutChildren extends CachedViewGroup {
public class CellLayoutChildren extends ViewGroup {
static final String TAG = "CellLayoutChildren";
// These are temporary variables to prevent having to allocate a new object just to
@@ -94,7 +95,6 @@ public class CellLayoutChildren extends CachedViewGroup {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
+2
View File
@@ -2783,10 +2783,12 @@ public final class Launcher extends Activity
PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f));
alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime));
alphaAnim.setInterpolator(new DecelerateInterpolator(2.0f));
fromView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
alphaAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
fromView.setVisibility(View.GONE);
fromView.setLayerType(View.LAYER_TYPE_NONE, null);
}
});