Potential fix for garbled text in All Apps

- now redrawing the cache for CacheableTextView every time setText is called
This commit is contained in:
Michael Jurka
2011-01-12 11:59:23 -08:00
parent f5675decc9
commit c9c548eb10
3 changed files with 10 additions and 21 deletions
@@ -118,7 +118,6 @@ public class BubbleTextView extends CacheableTextView implements VisibilityChang
new FastBitmapDrawable(b), new FastBitmapDrawable(b),
null, null); null, null);
setText(info.title); setText(info.title);
buildAndEnableCache();
setTag(info); setTag(info);
} }
@@ -18,10 +18,9 @@ package com.android.launcher2;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.text.Layout; import android.text.Layout;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.TextView; import android.widget.TextView;
@@ -39,7 +38,7 @@ public class CacheableTextView extends TextView {
private int mPrevAlpha = -1; private int mPrevAlpha = -1;
private boolean mIsBuildingCache; private boolean mIsBuildingCache;
boolean mWaitingToGenerateCache; boolean mIsTextCacheDirty;
float mTextCacheLeft; float mTextCacheLeft;
float mTextCacheTop; float mTextCacheTop;
float mTextCacheScrollX; float mTextCacheScrollX;
@@ -73,18 +72,12 @@ public class CacheableTextView extends TextView {
return 0; return 0;
} }
public void buildAndEnableCache() { public void setText(CharSequence text, BufferType type) {
// Defers building the cache until the next draw to allow measuring super.setText(text, type);
// and laying out. mIsTextCacheDirty = true;
buildAndEnableCache(false);
} }
public void buildAndEnableCache(boolean isImmediate) { private void buildAndUpdateCache() {
if (getLayout() == null || !isImmediate) {
mWaitingToGenerateCache = true;
return;
}
final Layout layout = getLayout(); final Layout layout = getLayout();
final int left = getCompoundPaddingLeft(); final int left = getCompoundPaddingLeft();
final int top = getExtendedPaddingTop(); final int top = getExtendedPaddingTop();
@@ -133,8 +126,7 @@ public class CacheableTextView extends TextView {
// A hack-- we set the text to be one space (we don't make it empty just to avoid any // A hack-- we set the text to be one space (we don't make it empty just to avoid any
// potential issues with text measurement, like line height, etc.) so that the text view // potential issues with text measurement, like line height, etc.) so that the text view
// doesn't draw it anymore, since it's been cached. We have to manually rebuild // doesn't draw it anymore, since it's been cached.
// the cache whenever the text is changed (which is never in Launcher)
mText = getText(); mText = getText();
setText(" "); setText(" ");
} }
@@ -145,9 +137,9 @@ public class CacheableTextView extends TextView {
} }
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
if (mWaitingToGenerateCache && !mIsBuildingCache) { if (mIsTextCacheDirty && !mIsBuildingCache) {
buildAndEnableCache(true); buildAndUpdateCache();
mWaitingToGenerateCache = false; mIsTextCacheDirty = false;
} }
if (mCache != null && !mIsBuildingCache) { if (mCache != null && !mIsBuildingCache) {
canvas.drawBitmap(mCache, mTextCacheLeft - mTextCacheScrollX + mScrollX, canvas.drawBitmap(mCache, mTextCacheLeft - mTextCacheScrollX + mScrollX,
@@ -143,7 +143,6 @@ public class PagedViewIcon extends CacheableTextView implements Checkable {
mIcon = info.iconBitmap; mIcon = info.iconBitmap;
setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null); setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
setText(info.title); setText(info.title);
buildAndEnableCache();
setTag(info); setTag(info);
if (createHolographicOutlines) { if (createHolographicOutlines) {
@@ -160,7 +159,6 @@ public class PagedViewIcon extends CacheableTextView implements Checkable {
modelIconCache.getFullResIcon(info, packageManager), mContext); modelIconCache.getFullResIcon(info, packageManager), mContext);
setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null); setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
setText(info.loadLabel(packageManager)); setText(info.loadLabel(packageManager));
buildAndEnableCache();
setTag(info); setTag(info);
if (createHolographicOutlines) { if (createHolographicOutlines) {