summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2011-01-14 15:50:07 -0800
committerMichael Jurka <mikejurka@google.com>2011-01-14 15:50:07 -0800
commit002bd928bf57f21ad8e937ca465a975835e851cb (patch)
treefece13a7de442b27548315d2cbc5758a8ebd6323 /src/com/android
parent2a9e70655f5885549acfdb6e770d2516bc8c87e3 (diff)
downloadandroid_packages_apps_Trebuchet-002bd928bf57f21ad8e937ca465a975835e851cb.tar.gz
android_packages_apps_Trebuchet-002bd928bf57f21ad8e937ca465a975835e851cb.tar.bz2
android_packages_apps_Trebuchet-002bd928bf57f21ad8e937ca465a975835e851cb.zip
renaming CacheableTextView -> CachedTextView
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/launcher2/BubbleTextView.java2
-rw-r--r--src/com/android/launcher2/CacheableTextView.java165
-rw-r--r--src/com/android/launcher2/PagedViewIcon.java2
3 files changed, 2 insertions, 167 deletions
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
index 9f0e5fb98..f3aa3426d 100644
--- a/src/com/android/launcher2/BubbleTextView.java
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -37,7 +37,7 @@ import android.view.View;
* because we want to make the bubble taller than the text and TextView's clip is
* too aggressive.
*/
-public class BubbleTextView extends CacheableTextView implements VisibilityChangedBroadcaster {
+public class BubbleTextView extends CachedTextView implements VisibilityChangedBroadcaster {
static final float CORNER_RADIUS = 4.0f;
static final float SHADOW_LARGE_RADIUS = 4.0f;
static final float SHADOW_SMALL_RADIUS = 1.75f;
diff --git a/src/com/android/launcher2/CacheableTextView.java b/src/com/android/launcher2/CacheableTextView.java
deleted file mode 100644
index 136ce21a2..000000000
--- a/src/com/android/launcher2/CacheableTextView.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher2;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Bitmap.Config;
-import android.graphics.PorterDuff.Mode;
-import android.text.Layout;
-import android.util.AttributeSet;
-import android.widget.TextView;
-
-/*
- * This class is a bit of a hack, designed to speed up long text labels in Launcher. It caches the
- * text in a TextView to a bitmap and then just draws that Bitmap instead afterward, speeding up
- * rendering. Marquee scrolling is not currently supported.
- *
- */
-public class CacheableTextView extends TextView {
- private Bitmap mCache;
- private final Paint mCachePaint = new Paint();
- private final Canvas mCacheCanvas = new Canvas();
-
- private int mPrevAlpha = -1;
- private boolean mIsBuildingCache;
- boolean mIsTextCacheDirty;
- float mTextCacheLeft;
- float mTextCacheTop;
- float mTextCacheScrollX;
- float mRectLeft, mRectTop;
- private float mPaddingH = 0;
- private float mPaddingV = 0;
- private CharSequence mText;
-
- public CacheableTextView(Context context) {
- super(context);
- }
-
- public CacheableTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public CacheableTextView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- protected int getCacheTopPadding() {
- return 0;
- }
- protected int getCacheLeftPadding() {
- return 0;
- }
- protected int getCacheRightPadding() {
- return 0;
- }
- protected int getCacheBottomPadding() {
- return 0;
- }
-
- public void setText(CharSequence text, BufferType type) {
- super.setText(text, type);
- mIsTextCacheDirty = true;
- }
-
- private void buildAndUpdateCache() {
- final Layout layout = getLayout();
- final int left = getCompoundPaddingLeft();
- final int top = getExtendedPaddingTop();
- final float prevAlpha = getAlpha();
-
- mTextCacheLeft = layout.getLineLeft(0) - getCacheLeftPadding();
- mTextCacheTop = top + layout.getLineTop(0) - mPaddingV - getCacheTopPadding();
-
- mRectLeft = mScrollX + getLeft();
- mRectTop = 0;
- mTextCacheScrollX = mScrollX;
-
- final float textCacheRight =
- Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft) +
- getCacheRightPadding();
- final float textCacheBottom = top + layout.getLineBottom(0) + mPaddingV +
- getCacheBottomPadding();
- final float xCharWidth = getPaint().measureText("x");
-
- int width = (int) (textCacheRight - mTextCacheLeft + (2 * xCharWidth));
- int height = (int) (textCacheBottom - mTextCacheTop);
-
- if (width != 0 && height != 0) {
- if (mCache != null) {
- if (mCache.getWidth() != width || mCache.getHeight() != height) {
- mCache.recycle();
- mCache = null;
- }
- }
- if (mCache == null) {
- mCache = Bitmap.createBitmap(width, height, Config.ARGB_8888);
- mCacheCanvas.setBitmap(mCache);
- } else {
- mCacheCanvas.drawColor(0, Mode.CLEAR);
- }
-
- mCacheCanvas.save();
- mCacheCanvas.translate(-mTextCacheLeft, -mTextCacheTop);
-
- mIsBuildingCache = true;
- setAlpha(1.0f);
- draw(mCacheCanvas);
- setAlpha(prevAlpha);
- mIsBuildingCache = false;
- mCacheCanvas.restore();
-
- // 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.
- mText = getText();
- setText(" ");
- }
- }
-
- public CharSequence getText() {
- return (mText == null) ? super.getText() : mText;
- }
-
- public void draw(Canvas canvas) {
- if (mIsTextCacheDirty && !mIsBuildingCache) {
- buildAndUpdateCache();
- mIsTextCacheDirty = false;
- }
- if (mCache != null && !mIsBuildingCache) {
- canvas.drawBitmap(mCache, mTextCacheLeft - mTextCacheScrollX + mScrollX,
- mTextCacheTop, mCachePaint);
- }
- super.draw(canvas);
- }
-
- protected boolean isBuildingCache() {
- return mIsBuildingCache;
- }
-
- @Override
- protected boolean onSetAlpha(int alpha) {
- if (mPrevAlpha != alpha) {
- mPrevAlpha = alpha;
- mCachePaint.setAlpha(alpha);
- super.onSetAlpha(alpha);
- }
- return true;
- }
-}
diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java
index 90cff97d6..0af7b8aa3 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -39,7 +39,7 @@ import com.android.launcher.R;
* An icon on a PagedView, specifically for items in the launcher's paged view (with compound
* drawables on the top).
*/
-public class PagedViewIcon extends CacheableTextView implements Checkable {
+public class PagedViewIcon extends CachedTextView implements Checkable {
private static final String TAG = "PagedViewIcon";
// holographic outline