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