diff options
author | Michael Jurka <mikejurka@google.com> | 2010-12-02 13:43:52 -0800 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2010-12-02 13:44:08 -0800 |
commit | 8e414ee3cb67112f191304a9b10d63b28057d9f3 (patch) | |
tree | 774b5d57195800533c0739f227b3a986e56cc520 /src/com/android/launcher2/CacheableTextView.java | |
parent | c4ebd819711e85d0430fea0fe855fd56b4154840 (diff) | |
download | packages_apps_trebuchet-8e414ee3cb67112f191304a9b10d63b28057d9f3.zip packages_apps_trebuchet-8e414ee3cb67112f191304a9b10d63b28057d9f3.tar.gz packages_apps_trebuchet-8e414ee3cb67112f191304a9b10d63b28057d9f3.tar.bz2 |
Fixing crash in CacheableTextView
Not caching text view if the width/height of the text is 0
Diffstat (limited to 'src/com/android/launcher2/CacheableTextView.java')
-rw-r--r-- | src/com/android/launcher2/CacheableTextView.java | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/com/android/launcher2/CacheableTextView.java b/src/com/android/launcher2/CacheableTextView.java index 084810e..eba29ec 100644 --- a/src/com/android/launcher2/CacheableTextView.java +++ b/src/com/android/launcher2/CacheableTextView.java @@ -90,22 +90,26 @@ public class CacheableTextView extends TextView { Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft) + hPadding; final float textCacheBottom = top + layout.getLineBottom(0) + mPaddingV + vPadding; - mCache = Bitmap.createBitmap((int) (textCacheRight - mTextCacheLeft), - (int) (textCacheBottom - mTextCacheTop), Config.ARGB_8888); - mCacheCanvas.setBitmap(mCache); - mCacheCanvas.translate(-mTextCacheLeft, -mTextCacheTop); - - mIsBuildingCache = true; - setAlpha(1.0f); - draw(mCacheCanvas); - setAlpha(prevAlpha); - mIsBuildingCache = false; - - // 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 - // doesn't draw it anymore, since it's been cached. We have to manually rebuild - // the cache whenever the text is changed (which is never in Launcher) - setText(" "); + int width = (int) (textCacheRight - mTextCacheLeft); + int height = (int) (textCacheBottom - mTextCacheTop); + + if (width != 0 && height != 0) { + mCache = Bitmap.createBitmap(width, height, Config.ARGB_8888); + mCacheCanvas.setBitmap(mCache); + mCacheCanvas.translate(-mTextCacheLeft, -mTextCacheTop); + + mIsBuildingCache = true; + setAlpha(1.0f); + draw(mCacheCanvas); + setAlpha(prevAlpha); + mIsBuildingCache = false; + + // 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 + // doesn't draw it anymore, since it's been cached. We have to manually rebuild + // the cache whenever the text is changed (which is never in Launcher) + setText(" "); + } } public void draw(Canvas canvas) { |