The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 20 | import android.content.res.Resources; |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | import android.graphics.Canvas; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 23 | import android.graphics.Color; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.graphics.Paint; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 25 | import android.graphics.Rect; |
Michael Jurka | 137142e | 2011-01-05 20:57:04 -0800 | [diff] [blame] | 26 | import android.graphics.Region; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 27 | import android.graphics.Region.Op; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 29 | import android.util.AttributeSet; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 30 | import android.view.MotionEvent; |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 31 | import android.widget.TextView; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 32 | |
Michael Jurka | 92f3d46 | 2011-11-22 21:02:29 -0800 | [diff] [blame] | 33 | import com.android.launcher.R; |
| 34 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | /** |
| 36 | * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan |
| 37 | * because we want to make the bubble taller than the text and TextView's clip is |
| 38 | * too aggressive. |
| 39 | */ |
Michael Jurka | 08ee770 | 2011-08-11 16:53:35 -0700 | [diff] [blame] | 40 | public class BubbleTextView extends TextView { |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 41 | static final float CORNER_RADIUS = 4.0f; |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 42 | static final float SHADOW_LARGE_RADIUS = 4.0f; |
| 43 | static final float SHADOW_SMALL_RADIUS = 1.75f; |
| 44 | static final float SHADOW_Y_OFFSET = 2.0f; |
Winson Chung | c7aef8c | 2011-09-15 18:53:04 -0700 | [diff] [blame] | 45 | static final int SHADOW_LARGE_COLOUR = 0xDD000000; |
| 46 | static final int SHADOW_SMALL_COLOUR = 0xCC000000; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 47 | static final float PADDING_H = 8.0f; |
| 48 | static final float PADDING_V = 3.0f; |
| 49 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | private Paint mPaint; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 51 | private float mBubbleColorAlpha; |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 52 | private int mPrevAlpha = -1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 54 | private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper(); |
| 55 | private final Canvas mTempCanvas = new Canvas(); |
| 56 | private final Rect mTempRect = new Rect(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 57 | private boolean mDidInvalidateForPressedState; |
| 58 | private Bitmap mPressedOrFocusedBackground; |
| 59 | private int mFocusedOutlineColor; |
| 60 | private int mFocusedGlowColor; |
| 61 | private int mPressedOutlineColor; |
| 62 | private int mPressedGlowColor; |
| 63 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 64 | private boolean mBackgroundSizeChanged; |
| 65 | private Drawable mBackground; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 66 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 67 | private boolean mStayPressed; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame^] | 68 | private CheckLongPressHelper mLongPressHelper; |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 69 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | public BubbleTextView(Context context) { |
| 71 | super(context); |
| 72 | init(); |
| 73 | } |
| 74 | |
| 75 | public BubbleTextView(Context context, AttributeSet attrs) { |
| 76 | super(context, attrs); |
| 77 | init(); |
| 78 | } |
| 79 | |
| 80 | public BubbleTextView(Context context, AttributeSet attrs, int defStyle) { |
| 81 | super(context, attrs, defStyle); |
| 82 | init(); |
| 83 | } |
| 84 | |
| 85 | private void init() { |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame^] | 86 | mLongPressHelper = new CheckLongPressHelper(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 87 | mBackground = getBackground(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 88 | |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 89 | final Resources res = getContext().getResources(); |
| 90 | int bubbleColor = res.getColor(R.color.bubble_dark_background); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 91 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 92 | mPaint.setColor(bubbleColor); |
| 93 | mBubbleColorAlpha = Color.alpha(bubbleColor) / 255.0f; |
Winson Chung | 7d3810d | 2011-10-07 13:11:56 -0700 | [diff] [blame] | 94 | mFocusedOutlineColor = mFocusedGlowColor = mPressedOutlineColor = mPressedGlowColor = |
| 95 | res.getColor(android.R.color.holo_blue_light); |
Michael Jurka | e7e3f6c | 2011-02-01 21:08:29 -0800 | [diff] [blame] | 96 | |
| 97 | setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 100 | public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) { |
| 101 | Bitmap b = info.getIcon(iconCache); |
| 102 | |
| 103 | setCompoundDrawablesWithIntrinsicBounds(null, |
| 104 | new FastBitmapDrawable(b), |
| 105 | null, null); |
| 106 | setText(info.title); |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 107 | setTag(info); |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 108 | } |
| 109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | @Override |
| 111 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 112 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 113 | mBackgroundSizeChanged = true; |
| 114 | } |
| 115 | return super.setFrame(left, top, right, bottom); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | protected boolean verifyDrawable(Drawable who) { |
| 120 | return who == mBackground || super.verifyDrawable(who); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | protected void drawableStateChanged() { |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 125 | if (isPressed()) { |
| 126 | // In this case, we have already created the pressed outline on ACTION_DOWN, |
| 127 | // so we just need to do an invalidate to trigger draw |
| 128 | if (!mDidInvalidateForPressedState) { |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 129 | setCellLayoutPressedOrFocusedIcon(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 130 | } |
| 131 | } else { |
| 132 | // Otherwise, either clear the pressed/focused background, or create a background |
| 133 | // for the focused state |
| 134 | final boolean backgroundEmptyBefore = mPressedOrFocusedBackground == null; |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 135 | if (!mStayPressed) { |
| 136 | mPressedOrFocusedBackground = null; |
| 137 | } |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 138 | if (isFocused()) { |
Gilles Debunne | c786952 | 2011-11-28 18:03:56 -0800 | [diff] [blame] | 139 | if (getLayout() == null) { |
Patrick Dubroy | a017c03 | 2011-03-09 15:58:32 -0800 | [diff] [blame] | 140 | // In some cases, we get focus before we have been layed out. Set the |
| 141 | // background to null so that it will get created when the view is drawn. |
| 142 | mPressedOrFocusedBackground = null; |
| 143 | } else { |
| 144 | mPressedOrFocusedBackground = createGlowingOutline( |
| 145 | mTempCanvas, mFocusedGlowColor, mFocusedOutlineColor); |
| 146 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 147 | mStayPressed = false; |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 148 | setCellLayoutPressedOrFocusedIcon(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 149 | } |
| 150 | final boolean backgroundEmptyNow = mPressedOrFocusedBackground == null; |
| 151 | if (!backgroundEmptyBefore && backgroundEmptyNow) { |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 152 | setCellLayoutPressedOrFocusedIcon(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 156 | Drawable d = mBackground; |
| 157 | if (d != null && d.isStateful()) { |
| 158 | d.setState(getDrawableState()); |
| 159 | } |
| 160 | super.drawableStateChanged(); |
| 161 | } |
| 162 | |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 163 | /** |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 164 | * Draw this BubbleTextView into the given Canvas. |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 165 | * |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 166 | * @param destCanvas the canvas to draw on |
| 167 | * @param padding the horizontal and vertical padding to use when drawing |
| 168 | */ |
| 169 | private void drawWithPadding(Canvas destCanvas, int padding) { |
| 170 | final Rect clipRect = mTempRect; |
| 171 | getDrawingRect(clipRect); |
| 172 | |
| 173 | // adjust the clip rect so that we don't include the text label |
| 174 | clipRect.bottom = |
| 175 | getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + getLayout().getLineTop(0); |
| 176 | |
| 177 | // Draw the View into the bitmap. |
| 178 | // The translate of scrollX and scrollY is necessary when drawing TextViews, because |
| 179 | // they set scrollX and scrollY to large values to achieve centered text |
| 180 | destCanvas.save(); |
| 181 | destCanvas.translate(-getScrollX() + padding / 2, -getScrollY() + padding / 2); |
| 182 | destCanvas.clipRect(clipRect, Op.REPLACE); |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 183 | draw(destCanvas); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 184 | destCanvas.restore(); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 189 | * Responsibility for the bitmap is transferred to the caller. |
| 190 | */ |
| 191 | private Bitmap createGlowingOutline(Canvas canvas, int outlineColor, int glowColor) { |
| 192 | final int padding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS; |
| 193 | final Bitmap b = Bitmap.createBitmap( |
| 194 | getWidth() + padding, getHeight() + padding, Bitmap.Config.ARGB_8888); |
| 195 | |
| 196 | canvas.setBitmap(b); |
| 197 | drawWithPadding(canvas, padding); |
| 198 | mOutlineHelper.applyExtraThickExpensiveOutlineWithBlur(b, canvas, glowColor, outlineColor); |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 199 | canvas.setBitmap(null); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 200 | |
| 201 | return b; |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public boolean onTouchEvent(MotionEvent event) { |
| 206 | // Call the superclass onTouchEvent first, because sometimes it changes the state to |
| 207 | // isPressed() on an ACTION_UP |
| 208 | boolean result = super.onTouchEvent(event); |
| 209 | |
| 210 | switch (event.getAction()) { |
| 211 | case MotionEvent.ACTION_DOWN: |
| 212 | // So that the pressed outline is visible immediately when isPressed() is true, |
| 213 | // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time |
| 214 | // to create it) |
| 215 | if (mPressedOrFocusedBackground == null) { |
| 216 | mPressedOrFocusedBackground = createGlowingOutline( |
| 217 | mTempCanvas, mPressedGlowColor, mPressedOutlineColor); |
| 218 | } |
| 219 | // Invalidate so the pressed state is visible, or set a flag so we know that we |
| 220 | // have to call invalidate as soon as the state is "pressed" |
| 221 | if (isPressed()) { |
| 222 | mDidInvalidateForPressedState = true; |
Michael Jurka | e6235dd | 2011-10-04 15:02:05 -0700 | [diff] [blame] | 223 | setCellLayoutPressedOrFocusedIcon(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 224 | } else { |
| 225 | mDidInvalidateForPressedState = false; |
| 226 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame^] | 227 | |
| 228 | mLongPressHelper.postCheckForLongPress(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 229 | break; |
| 230 | case MotionEvent.ACTION_CANCEL: |
| 231 | case MotionEvent.ACTION_UP: |
| 232 | // If we've touched down and up on an item, and it's still not "pressed", then |
| 233 | // destroy the pressed outline |
| 234 | if (!isPressed()) { |
| 235 | mPressedOrFocusedBackground = null; |
| 236 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame^] | 237 | |
| 238 | mLongPressHelper.cancelLongPress(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 239 | break; |
| 240 | } |
| 241 | return result; |
| 242 | } |
| 243 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 244 | void setStayPressed(boolean stayPressed) { |
| 245 | mStayPressed = stayPressed; |
| 246 | if (!stayPressed) { |
| 247 | mPressedOrFocusedBackground = null; |
| 248 | } |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 249 | setCellLayoutPressedOrFocusedIcon(); |
| 250 | } |
| 251 | |
| 252 | void setCellLayoutPressedOrFocusedIcon() { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 253 | if (getParent() instanceof CellLayoutChildren) { |
| 254 | CellLayoutChildren parent = (CellLayoutChildren) getParent(); |
| 255 | if (parent != null) { |
| 256 | CellLayout layout = (CellLayout) parent.getParent(); |
| 257 | layout.setPressedOrFocusedIcon((mPressedOrFocusedBackground != null) ? this : null); |
| 258 | } |
Patrick Dubroy | d69e113 | 2011-03-15 10:29:01 -0700 | [diff] [blame] | 259 | } |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 262 | void clearPressedOrFocusedBackground() { |
| 263 | mPressedOrFocusedBackground = null; |
| 264 | setCellLayoutPressedOrFocusedIcon(); |
| 265 | } |
| 266 | |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 267 | Bitmap getPressedOrFocusedBackground() { |
| 268 | return mPressedOrFocusedBackground; |
| 269 | } |
| 270 | |
| 271 | int getPressedOrFocusedBackgroundPadding() { |
| 272 | return HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS / 2; |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 273 | } |
Patrick Dubroy | a017c03 | 2011-03-09 15:58:32 -0800 | [diff] [blame] | 274 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 275 | @Override |
| 276 | public void draw(Canvas canvas) { |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 277 | final Drawable background = mBackground; |
| 278 | if (background != null) { |
| 279 | final int scrollX = mScrollX; |
| 280 | final int scrollY = mScrollY; |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 281 | |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 282 | if (mBackgroundSizeChanged) { |
| 283 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 284 | mBackgroundSizeChanged = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 285 | } |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 286 | |
| 287 | if ((scrollX | scrollY) == 0) { |
| 288 | background.draw(canvas); |
| 289 | } else { |
| 290 | canvas.translate(scrollX, scrollY); |
| 291 | background.draw(canvas); |
| 292 | canvas.translate(-scrollX, -scrollY); |
| 293 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 294 | } |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 295 | // We enhance the shadow by drawing the shadow twice |
Michael Jurka | e7e3f6c | 2011-02-01 21:08:29 -0800 | [diff] [blame] | 296 | getPaint().setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR); |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 297 | super.draw(canvas); |
| 298 | canvas.save(Canvas.CLIP_SAVE_FLAG); |
| 299 | canvas.clipRect(mScrollX, mScrollY + getExtendedPaddingTop(), mScrollX + getWidth(), |
Winson Chung | 0969300 | 2011-02-03 23:56:47 -0800 | [diff] [blame] | 300 | mScrollY + getHeight(), Region.Op.INTERSECT); |
Michael Jurka | e7e3f6c | 2011-02-01 21:08:29 -0800 | [diff] [blame] | 301 | getPaint().setShadowLayer(SHADOW_SMALL_RADIUS, 0.0f, 0.0f, SHADOW_SMALL_COLOUR); |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 302 | super.draw(canvas); |
| 303 | canvas.restore(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 304 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 305 | |
| 306 | @Override |
| 307 | protected void onAttachedToWindow() { |
| 308 | super.onAttachedToWindow(); |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 309 | if (mBackground != null) mBackground.setCallback(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | @Override |
| 313 | protected void onDetachedFromWindow() { |
| 314 | super.onDetachedFromWindow(); |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 315 | if (mBackground != null) mBackground.setCallback(null); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 316 | } |
Winson Chung | affd7b4 | 2010-08-20 15:11:56 -0700 | [diff] [blame] | 317 | |
| 318 | @Override |
| 319 | protected boolean onSetAlpha(int alpha) { |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 320 | if (mPrevAlpha != alpha) { |
| 321 | mPrevAlpha = alpha; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 322 | mPaint.setAlpha((int) (alpha * mBubbleColorAlpha)); |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 323 | super.onSetAlpha(alpha); |
| 324 | } |
| 325 | return true; |
Winson Chung | affd7b4 | 2010-08-20 15:11:56 -0700 | [diff] [blame] | 326 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame^] | 327 | |
| 328 | @Override |
| 329 | public void cancelLongPress() { |
| 330 | super.cancelLongPress(); |
| 331 | |
| 332 | mLongPressHelper.cancelLongPress(); |
| 333 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 334 | } |