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