修改文件为Launcher2\src\com\android\launcher2\AppTextView.java
修改前
package com.android.launcher2; import android.content.ComponentName; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.TextView; /** * TextView that draws a bubble behind the text. We cannot use a * LineBackgroundSpan because we want to make the bubble taller than the text * and TextView's clip is too aggressive. */ public class AppTextView extends TextView { private static Paint tPaint = new Paint(); private static final Canvas sCanvas = new Canvas(); public static final String DEFAULTCOLOR = "#ffffffff"; private boolean isNeedDraw = false; private static final String INFINITY_UNICODE = "\u221e"; private static float mFewTextSize; private static float mManytextSize; public boolean isNeedDraw() { return isNeedDraw; } public void setNeedDraw(boolean isNeedDraw) { this.isNeedDraw = isNeedDraw; } private int mCount = 0; public int getCount() { return mCount; } public void setCount(int mCount) { this.mCount = mCount; } public AppTextView(Context context) { super(context); init(); } public AppTextView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public AppTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { setFocusable(true); tPaint.setAntiAlias(true); tPaint.setColor(Color.WHITE); } private ComponentName getComponent(Object info) { if (info instanceof ComponentName) { return (ComponentName)info; } else if (info instanceof ApplicationInfo) { return ((ApplicationInfo) info).componentName; } else if (info instanceof ShortcutInfo) { return ((ShortcutInfo) info).intent.getComponent(); } else { return null; } } }
修改后
package com.android.launcher2; import com.android.launcher.R; import android.content.ComponentName; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.text.Layout; import android.util.AttributeSet; import android.widget.TextView; /** * TextView that draws a bubble behind the text. We cannot use a * LineBackgroundSpan because we want to make the bubble taller than the text * and TextView's clip is too aggressive. */ public class AppTextView extends TextView { private static Paint tPaint = new Paint(); private static final Canvas sCanvas = new Canvas(); public static final String DEFAULTCOLOR = "#ffffffff"; private boolean isNeedDraw = false; private static final String INFINITY_UNICODE = "\u221e"; private static float mFewTextSize; private static float mManytextSize; static final float CORNER_RADIUS = 8.0f; static final float PADDING_H = 5.0f; static final float PADDING_V = 1.0f; private final RectF mRect = new RectF(); private Paint mPaint; private boolean mBackgroundSizeChanged; private Drawable mBackground; private float mCornerRadius; private float mPaddingH; private float mPaddingV; public boolean isNeedDraw() { return isNeedDraw; } public void setNeedDraw(boolean isNeedDraw) { this.isNeedDraw = isNeedDraw; } private int mCount = 0; public int getCount() { return mCount; } public void setCount(int mCount) { this.mCount = mCount; } public AppTextView(Context context) { super(context); init(); } public AppTextView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public AppTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { setFocusable(true); tPaint.setAntiAlias(true); tPaint.setColor(Color.WHITE); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(getContext().getResources().getColor(R.color.bubble_dark_background)); final float scale = getContext().getResources().getDisplayMetrics().density; mCornerRadius = CORNER_RADIUS * scale; mPaddingH = PADDING_H * scale; //noinspection PointlessArithmeticExpression mPaddingV = PADDING_V * scale; } public void draw(Canvas canvas) { final Layout layout = getLayout(); final RectF rect = mRect; final int left = getCompoundPaddingLeft(); final int top = getExtendedPaddingTop(); rect.set(left + layout.getLineLeft(0) - mPaddingH, top + layout.getLineTop(0) - mPaddingV, Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft), top + layout.getLineBottom(0) + mPaddingV); canvas.drawRoundRect(rect, mCornerRadius, mCornerRadius, mPaint); super.draw(canvas); } private ComponentName getComponent(Object info) { if (info instanceof ComponentName) { return (ComponentName)info; } else if (info instanceof ApplicationInfo) { return ((ApplicationInfo) info).componentName; } else if (info instanceof ShortcutInfo) { return ((ShortcutInfo) info).intent.getComponent(); } else { return null; } } }