Adding outline cache for PagedViewIcons.

Change-Id: I258740a0323660edd73b5f40d61d509455ae195b
This commit is contained in:
Winson Chung
2010-08-25 16:53:03 -07:00
parent 6b509c1fd6
commit 241c3b451d
4 changed files with 77 additions and 33 deletions

View File

@@ -17,6 +17,8 @@
package com.android.launcher2;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
@@ -31,9 +33,12 @@ import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.Checkable;
import android.widget.TextView;
import com.android.launcher2.PagedView.PagedViewIconCache;
class HolographicOutlineHelper {
private final Paint mHolographicPaint = new Paint();
private final Paint mBlurPaint = new Paint();
@@ -138,6 +143,9 @@ public class PagedViewIcon extends TextView implements Checkable {
private boolean mIsHolographicUpdatePass;
private Rect mDrawableClipRect;
private Object mIconCacheKey;
private PagedViewIconCache mIconCache;
private int mAlpha;
private int mHolographicAlpha;
@@ -166,6 +174,30 @@ public class PagedViewIcon extends TextView implements Checkable {
setBackgroundDrawable(null);
}
public void applyFromApplicationInfo(ApplicationInfo info, PagedViewIconCache cache) {
mIconCache = cache;
mIconCacheKey = info;
mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
setCompoundDrawablesWithIntrinsicBounds(null,
new FastBitmapDrawable(info.iconBitmap), null, null);
setText(info.title);
setTag(info);
}
public void applyFromResolveInfo(ResolveInfo info, PackageManager packageManager,
PagedViewIconCache cache) {
mIconCache = cache;
mIconCacheKey = info;
mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
Drawable image = info.loadIcon(packageManager);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
setCompoundDrawablesWithIntrinsicBounds(null, image, null, null);
setText(info.loadLabel(packageManager));
setTag(info);
}
@Override
public void setAlpha(float alpha) {
final float viewAlpha = sHolographicOutlineHelper.viewAlphaInterpolator(alpha);
@@ -175,21 +207,6 @@ public class PagedViewIcon extends TextView implements Checkable {
super.setAlpha(viewAlpha);
}
@Override
public void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top,
Drawable right, Drawable bottom) {
invalidateHolographicImage();
super.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
}
public void invalidateHolographicImage() {
if (mHolographicOutline != null) {
mHolographicOutline.recycle();
mHolographicOutline = null;
mHolographicOutlineCanvas = null;
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
@@ -215,6 +232,7 @@ public class PagedViewIcon extends TextView implements Checkable {
offset);
sHolographicOutlineHelper.applyBlur(mHolographicOutline, mHolographicOutlineCanvas);
mIsHolographicUpdatePass = false;
mIconCache.addOutline(mIconCacheKey, mHolographicOutline);
}
}