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