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 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 19 | import android.annotation.TargetApi; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 21 | import android.content.res.ColorStateList; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 22 | import android.content.res.Resources; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 23 | import android.content.res.Resources.Theme; |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 24 | import android.content.res.TypedArray; |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Michael Jurka | 137142e | 2011-01-05 20:57:04 -0800 | [diff] [blame] | 27 | import android.graphics.Region; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 29 | import android.os.Build; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 31 | import android.util.SparseArray; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 32 | import android.util.TypedValue; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 33 | import android.view.KeyEvent; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 34 | import android.view.MotionEvent; |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 35 | import android.view.View; |
Jason Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 36 | import android.view.ViewConfiguration; |
Sunny Goyal | 4b6eb26 | 2015-05-14 19:24:40 -0700 | [diff] [blame] | 37 | import android.view.ViewParent; |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 38 | import android.widget.TextView; |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 39 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 40 | import com.android.launcher3.IconCache.IconLoadRequest; |
Hyunyoung Song | 2bd3d7d | 2015-05-21 13:04:53 -0700 | [diff] [blame] | 41 | import com.android.launcher3.model.PackageItemInfo; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 42 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | /** |
| 44 | * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan |
| 45 | * because we want to make the bubble taller than the text and TextView's clip is |
| 46 | * too aggressive. |
| 47 | */ |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 48 | public class BubbleTextView extends TextView |
| 49 | implements BaseRecyclerViewFastScrollBar.FastScrollFocusableView { |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 50 | |
Sameer Padala | 8fd7483 | 2014-09-08 16:00:29 -0700 | [diff] [blame] | 51 | private static SparseArray<Theme> sPreloaderThemes = new SparseArray<Theme>(2); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 52 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 53 | private static final float SHADOW_LARGE_RADIUS = 4.0f; |
| 54 | private static final float SHADOW_SMALL_RADIUS = 1.75f; |
| 55 | private static final float SHADOW_Y_OFFSET = 2.0f; |
| 56 | private static final int SHADOW_LARGE_COLOUR = 0xDD000000; |
| 57 | private static final int SHADOW_SMALL_COLOUR = 0xCC000000; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 58 | |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 59 | private static final int DISPLAY_WORKSPACE = 0; |
| 60 | private static final int DISPLAY_ALL_APPS = 1; |
| 61 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 62 | private final Launcher mLauncher; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 63 | private Drawable mIcon; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 64 | private final Drawable mBackground; |
| 65 | private final CheckLongPressHelper mLongPressHelper; |
| 66 | private final HolographicOutlineHelper mOutlineHelper; |
Mady Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 67 | private final StylusEventHelper mStylusEventHelper; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 68 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 69 | private boolean mBackgroundSizeChanged; |
| 70 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 71 | private Bitmap mPressedBackground; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 72 | |
Jason Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 73 | private float mSlop; |
| 74 | |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 75 | private final boolean mDeferShadowGenerationOnTouch; |
Sunny Goyal | 15872da | 2014-07-08 15:43:54 -0700 | [diff] [blame] | 76 | private final boolean mCustomShadowsEnabled; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 77 | private final boolean mLayoutHorizontal; |
| 78 | private final int mIconSize; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 79 | private int mTextColor; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 80 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 81 | private boolean mStayPressed; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 82 | private boolean mIgnorePressedStateChange; |
Sunny Goyal | 69b7564 | 2015-05-15 17:00:24 -0700 | [diff] [blame] | 83 | private boolean mDisableRelayout = false; |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 84 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 85 | private IconLoadRequest mIconLoadRequest; |
| 86 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 87 | public BubbleTextView(Context context) { |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 88 | this(context, null, 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | public BubbleTextView(Context context, AttributeSet attrs) { |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 92 | this(context, attrs, 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | public BubbleTextView(Context context, AttributeSet attrs, int defStyle) { |
| 96 | super(context, attrs, defStyle); |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 97 | mLauncher = (Launcher) context; |
| 98 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 99 | |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 100 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 101 | R.styleable.BubbleTextView, defStyle, 0); |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 102 | mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 103 | mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false); |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 104 | mDeferShadowGenerationOnTouch = |
| 105 | a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false); |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 106 | |
| 107 | int display = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE); |
| 108 | int defaultIconSize = grid.iconSizePx; |
| 109 | if (display == DISPLAY_WORKSPACE) { |
Winson Chung | 44d0aac | 2015-05-11 18:02:55 -0700 | [diff] [blame] | 110 | setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx); |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 111 | } else if (display == DISPLAY_ALL_APPS) { |
Winson Chung | 44d0aac | 2015-05-11 18:02:55 -0700 | [diff] [blame] | 112 | setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx); |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 113 | defaultIconSize = grid.allAppsIconSizePx; |
| 114 | } |
| 115 | |
| 116 | mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride, |
| 117 | defaultIconSize); |
| 118 | |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 119 | a.recycle(); |
| 120 | |
Sunny Goyal | 15872da | 2014-07-08 15:43:54 -0700 | [diff] [blame] | 121 | if (mCustomShadowsEnabled) { |
| 122 | // Draw the background itself as the parent is drawn twice. |
| 123 | mBackground = getBackground(); |
| 124 | setBackground(null); |
| 125 | } else { |
| 126 | mBackground = null; |
| 127 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 128 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 129 | mLongPressHelper = new CheckLongPressHelper(this); |
Mady Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 130 | mStylusEventHelper = new StylusEventHelper(this); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 131 | |
| 132 | mOutlineHelper = HolographicOutlineHelper.obtain(getContext()); |
| 133 | if (mCustomShadowsEnabled) { |
| 134 | setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR); |
| 135 | } |
| 136 | |
| 137 | setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 140 | public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) { |
| 141 | applyFromShortcutInfo(info, iconCache, false); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 144 | public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache, |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 145 | boolean promiseStateChanged) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 146 | Bitmap b = info.getIcon(iconCache); |
| 147 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 148 | FastBitmapDrawable iconDrawable = mLauncher.createIconDrawable(b); |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 149 | if (info.isDisabled != 0) { |
| 150 | iconDrawable.setState(FastBitmapDrawable.State.DISABLED); |
| 151 | } |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 152 | setIcon(iconDrawable, mIconSize); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 153 | if (info.contentDescription != null) { |
| 154 | setContentDescription(info.contentDescription); |
| 155 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 156 | setText(info.title); |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 157 | setTag(info); |
Sunny Goyal | 3484638 | 2014-07-09 00:09:28 -0700 | [diff] [blame] | 158 | |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 159 | if (promiseStateChanged || info.isPromise()) { |
| 160 | applyState(promiseStateChanged); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 161 | } |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 164 | public void applyFromApplicationInfo(AppInfo info) { |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 165 | setIcon(mLauncher.createIconDrawable(info.iconBitmap), mIconSize); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 166 | setText(info.title); |
| 167 | if (info.contentDescription != null) { |
| 168 | setContentDescription(info.contentDescription); |
| 169 | } |
Winson Chung | 888b3a1 | 2015-03-13 11:14:16 -0700 | [diff] [blame] | 170 | // We don't need to check the info since it's not a ShortcutInfo |
| 171 | super.setTag(info); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 172 | |
| 173 | // Verify high res immediately |
| 174 | verifyHighRes(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Sunny Goyal | 0e08f16 | 2015-05-12 11:32:39 -0700 | [diff] [blame] | 177 | public void applyFromPackageItemInfo(PackageItemInfo info) { |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 178 | setIcon(mLauncher.createIconDrawable(info.iconBitmap), mIconSize); |
Sunny Goyal | 0e08f16 | 2015-05-12 11:32:39 -0700 | [diff] [blame] | 179 | setText(info.title); |
| 180 | if (info.contentDescription != null) { |
| 181 | setContentDescription(info.contentDescription); |
| 182 | } |
| 183 | // We don't need to check the info since it's not a ShortcutInfo |
| 184 | super.setTag(info); |
| 185 | |
| 186 | // Verify high res immediately |
| 187 | verifyHighRes(); |
| 188 | } |
| 189 | |
Winson Chung | 7501adf | 2015-06-02 11:24:28 -0700 | [diff] [blame] | 190 | /** |
| 191 | * Overrides the default long press timeout. |
| 192 | */ |
| 193 | public void setLongPressTimeout(int longPressTimeout) { |
| 194 | mLongPressHelper.setLongPressTimeout(longPressTimeout); |
| 195 | } |
Sunny Goyal | 0e08f16 | 2015-05-12 11:32:39 -0700 | [diff] [blame] | 196 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 197 | @Override |
| 198 | protected boolean setFrame(int left, int top, int right, int bottom) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 199 | if (getLeft() != left || getRight() != right || getTop() != top || getBottom() != bottom) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 200 | mBackgroundSizeChanged = true; |
| 201 | } |
| 202 | return super.setFrame(left, top, right, bottom); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | protected boolean verifyDrawable(Drawable who) { |
| 207 | return who == mBackground || super.verifyDrawable(who); |
| 208 | } |
| 209 | |
| 210 | @Override |
Michael Jurka | 816474f | 2012-06-25 14:49:02 -0700 | [diff] [blame] | 211 | public void setTag(Object tag) { |
| 212 | if (tag != null) { |
| 213 | LauncherModel.checkItemInfo((ItemInfo) tag); |
| 214 | } |
| 215 | super.setTag(tag); |
| 216 | } |
| 217 | |
| 218 | @Override |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 219 | public void setPressed(boolean pressed) { |
| 220 | super.setPressed(pressed); |
| 221 | |
| 222 | if (!mIgnorePressedStateChange) { |
| 223 | updateIconState(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 224 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 225 | } |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 226 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 227 | /** Returns the icon for this view. */ |
| 228 | public Drawable getIcon() { |
| 229 | return mIcon; |
| 230 | } |
| 231 | |
| 232 | /** Returns whether the layout is horizontal. */ |
| 233 | public boolean isLayoutHorizontal() { |
| 234 | return mLayoutHorizontal; |
| 235 | } |
| 236 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 237 | private void updateIconState() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 238 | if (mIcon instanceof FastBitmapDrawable) { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 239 | FastBitmapDrawable d = (FastBitmapDrawable) mIcon; |
| 240 | if (isPressed() || mStayPressed) { |
| 241 | d.animateState(FastBitmapDrawable.State.PRESSED); |
| 242 | } else { |
| 243 | d.animateState(FastBitmapDrawable.State.NORMAL); |
| 244 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 245 | } |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public boolean onTouchEvent(MotionEvent event) { |
| 250 | // Call the superclass onTouchEvent first, because sometimes it changes the state to |
| 251 | // isPressed() on an ACTION_UP |
| 252 | boolean result = super.onTouchEvent(event); |
| 253 | |
Mady Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 254 | // Check for a stylus button press, if it occurs cancel any long press checks. |
| 255 | if (mStylusEventHelper.checkAndPerformStylusEvent(event)) { |
| 256 | mLongPressHelper.cancelLongPress(); |
| 257 | result = true; |
| 258 | } |
| 259 | |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 260 | switch (event.getAction()) { |
| 261 | case MotionEvent.ACTION_DOWN: |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 262 | // So that the pressed outline is visible immediately on setStayPressed(), |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 263 | // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time |
| 264 | // to create it) |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 265 | if (!mDeferShadowGenerationOnTouch && mPressedBackground == null) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 266 | mPressedBackground = mOutlineHelper.createMediumDropShadow(this); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 267 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 268 | |
Mady Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 269 | // If we're in a stylus button press, don't check for long press. |
| 270 | if (!mStylusEventHelper.inStylusButtonPressed()) { |
| 271 | mLongPressHelper.postCheckForLongPress(); |
| 272 | } |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 273 | break; |
| 274 | case MotionEvent.ACTION_CANCEL: |
| 275 | case MotionEvent.ACTION_UP: |
| 276 | // If we've touched down and up on an item, and it's still not "pressed", then |
| 277 | // destroy the pressed outline |
| 278 | if (!isPressed()) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 279 | mPressedBackground = null; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 280 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 281 | |
| 282 | mLongPressHelper.cancelLongPress(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 283 | break; |
Jason Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 284 | case MotionEvent.ACTION_MOVE: |
| 285 | if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) { |
| 286 | mLongPressHelper.cancelLongPress(); |
| 287 | } |
| 288 | break; |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 289 | } |
| 290 | return result; |
| 291 | } |
| 292 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 293 | void setStayPressed(boolean stayPressed) { |
| 294 | mStayPressed = stayPressed; |
| 295 | if (!stayPressed) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 296 | mPressedBackground = null; |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 297 | } else { |
| 298 | if (mPressedBackground == null) { |
| 299 | mPressedBackground = mOutlineHelper.createMediumDropShadow(this); |
| 300 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 301 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 302 | |
| 303 | // Only show the shadow effect when persistent pressed state is set. |
Sunny Goyal | 4b6eb26 | 2015-05-14 19:24:40 -0700 | [diff] [blame] | 304 | ViewParent parent = getParent(); |
| 305 | if (parent != null && parent.getParent() instanceof BubbleTextShadowHandler) { |
| 306 | ((BubbleTextShadowHandler) parent.getParent()).setPressedIcon( |
| 307 | this, mPressedBackground); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | updateIconState(); |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 313 | void clearPressedBackground() { |
| 314 | setPressed(false); |
| 315 | setStayPressed(false); |
| 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 320 | if (super.onKeyDown(keyCode, event)) { |
| 321 | // Pre-create shadow so show immediately on click. |
| 322 | if (mPressedBackground == null) { |
| 323 | mPressedBackground = mOutlineHelper.createMediumDropShadow(this); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 324 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 325 | return true; |
Patrick Dubroy | d69e113 | 2011-03-15 10:29:01 -0700 | [diff] [blame] | 326 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 327 | return false; |
Patrick Dubroy | 3499d8c | 2011-03-10 17:17:23 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 330 | @Override |
| 331 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 332 | // Unlike touch events, keypress event propagate pressed state change immediately, |
| 333 | // without waiting for onClickHandler to execute. Disable pressed state changes here |
| 334 | // to avoid flickering. |
| 335 | mIgnorePressedStateChange = true; |
| 336 | boolean result = super.onKeyUp(keyCode, event); |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 337 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 338 | mPressedBackground = null; |
| 339 | mIgnorePressedStateChange = false; |
| 340 | updateIconState(); |
| 341 | return result; |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 342 | } |
Patrick Dubroy | a017c03 | 2011-03-09 15:58:32 -0800 | [diff] [blame] | 343 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 344 | @Override |
| 345 | public void draw(Canvas canvas) { |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 346 | if (!mCustomShadowsEnabled) { |
Adam Cohen | 477828c | 2013-09-20 12:05:49 -0700 | [diff] [blame] | 347 | super.draw(canvas); |
| 348 | return; |
| 349 | } |
| 350 | |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 351 | final Drawable background = mBackground; |
| 352 | if (background != null) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 353 | final int scrollX = getScrollX(); |
| 354 | final int scrollY = getScrollY(); |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 355 | |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 356 | if (mBackgroundSizeChanged) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 357 | background.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop()); |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 358 | mBackgroundSizeChanged = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 359 | } |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 360 | |
| 361 | if ((scrollX | scrollY) == 0) { |
| 362 | background.draw(canvas); |
| 363 | } else { |
| 364 | canvas.translate(scrollX, scrollY); |
| 365 | background.draw(canvas); |
| 366 | canvas.translate(-scrollX, -scrollY); |
| 367 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 368 | } |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 369 | |
| 370 | // If text is transparent, don't draw any shadow |
Andrew Flynn | bc239a1 | 2012-03-06 11:39:49 -0800 | [diff] [blame] | 371 | if (getCurrentTextColor() == getResources().getColor(android.R.color.transparent)) { |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 372 | getPaint().clearShadowLayer(); |
| 373 | super.draw(canvas); |
| 374 | return; |
| 375 | } |
| 376 | |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 377 | // We enhance the shadow by drawing the shadow twice |
Michael Jurka | e7e3f6c | 2011-02-01 21:08:29 -0800 | [diff] [blame] | 378 | 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] | 379 | super.draw(canvas); |
| 380 | canvas.save(Canvas.CLIP_SAVE_FLAG); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 381 | canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(), |
| 382 | getScrollX() + getWidth(), |
| 383 | getScrollY() + getHeight(), Region.Op.INTERSECT); |
Michael Jurka | e7e3f6c | 2011-02-01 21:08:29 -0800 | [diff] [blame] | 384 | getPaint().setShadowLayer(SHADOW_SMALL_RADIUS, 0.0f, 0.0f, SHADOW_SMALL_COLOUR); |
Michael Jurka | bdb5c53 | 2011-02-01 15:05:06 -0800 | [diff] [blame] | 385 | super.draw(canvas); |
| 386 | canvas.restore(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 387 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 388 | |
| 389 | @Override |
| 390 | protected void onAttachedToWindow() { |
| 391 | super.onAttachedToWindow(); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 392 | |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 393 | if (mBackground != null) mBackground.setCallback(this); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 394 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 395 | if (mIcon instanceof PreloadIconDrawable) { |
| 396 | ((PreloadIconDrawable) mIcon).applyPreloaderTheme(getPreloaderTheme()); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 397 | } |
Jason Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 398 | mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | @Override |
| 402 | protected void onDetachedFromWindow() { |
| 403 | super.onDetachedFromWindow(); |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 404 | if (mBackground != null) mBackground.setCallback(null); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 405 | } |
Winson Chung | affd7b4 | 2010-08-20 15:11:56 -0700 | [diff] [blame] | 406 | |
Adam Cohen | 477828c | 2013-09-20 12:05:49 -0700 | [diff] [blame] | 407 | @Override |
| 408 | public void setTextColor(int color) { |
| 409 | mTextColor = color; |
| 410 | super.setTextColor(color); |
| 411 | } |
| 412 | |
Adam Cohen | 96bb798 | 2014-07-07 11:58:56 -0700 | [diff] [blame] | 413 | @Override |
| 414 | public void setTextColor(ColorStateList colors) { |
| 415 | mTextColor = colors.getDefaultColor(); |
| 416 | super.setTextColor(colors); |
Adam Cohen | 477828c | 2013-09-20 12:05:49 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 419 | public void setTextVisibility(boolean visible) { |
| 420 | Resources res = getResources(); |
| 421 | if (visible) { |
Adam Cohen | 477828c | 2013-09-20 12:05:49 -0700 | [diff] [blame] | 422 | super.setTextColor(mTextColor); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 423 | } else { |
Adam Cohen | 477828c | 2013-09-20 12:05:49 -0700 | [diff] [blame] | 424 | super.setTextColor(res.getColor(android.R.color.transparent)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 425 | } |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Winson Chung | affd7b4 | 2010-08-20 15:11:56 -0700 | [diff] [blame] | 428 | @Override |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 429 | public void cancelLongPress() { |
| 430 | super.cancelLongPress(); |
| 431 | |
| 432 | mLongPressHelper.cancelLongPress(); |
| 433 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 434 | |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 435 | public void applyState(boolean promiseStateChanged) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 436 | if (getTag() instanceof ShortcutInfo) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 437 | ShortcutInfo info = (ShortcutInfo) getTag(); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 438 | final boolean isPromise = info.isPromise(); |
| 439 | final int progressLevel = isPromise ? |
| 440 | ((info.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE) ? |
| 441 | info.getInstallProgress() : 0)) : 100; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 442 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 443 | if (mIcon != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 444 | final PreloadIconDrawable preloadDrawable; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 445 | if (mIcon instanceof PreloadIconDrawable) { |
| 446 | preloadDrawable = (PreloadIconDrawable) mIcon; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 447 | } else { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 448 | preloadDrawable = new PreloadIconDrawable(mIcon, getPreloaderTheme()); |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 449 | setIcon(preloadDrawable, mIconSize); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | preloadDrawable.setLevel(progressLevel); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 453 | if (promiseStateChanged) { |
| 454 | preloadDrawable.maybePerformFinishedAnimation(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 455 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 456 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 457 | } |
| 458 | } |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 459 | |
| 460 | private Theme getPreloaderTheme() { |
| 461 | Object tag = getTag(); |
| 462 | int style = ((tag != null) && (tag instanceof ShortcutInfo) && |
| 463 | (((ShortcutInfo) tag).container >= 0)) ? R.style.PreloadIcon_Folder |
| 464 | : R.style.PreloadIcon; |
| 465 | Theme theme = sPreloaderThemes.get(style); |
| 466 | if (theme == null) { |
| 467 | theme = getResources().newTheme(); |
| 468 | theme.applyStyle(style, true); |
| 469 | sPreloaderThemes.put(style, theme); |
| 470 | } |
| 471 | return theme; |
| 472 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 473 | |
| 474 | /** |
| 475 | * Sets the icon for this view based on the layout direction. |
| 476 | */ |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 477 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 478 | private Drawable setIcon(Drawable icon, int iconSize) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 479 | mIcon = icon; |
| 480 | if (iconSize != -1) { |
| 481 | mIcon.setBounds(0, 0, iconSize, iconSize); |
| 482 | } |
| 483 | if (mLayoutHorizontal) { |
Sunny Goyal | 9fc953b | 2015-08-17 12:24:25 -0700 | [diff] [blame] | 484 | if (Utilities.ATLEAST_JB_MR1) { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 485 | setCompoundDrawablesRelative(mIcon, null, null, null); |
| 486 | } else { |
| 487 | setCompoundDrawables(mIcon, null, null, null); |
| 488 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 489 | } else { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 490 | setCompoundDrawables(null, mIcon, null, null); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 491 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 492 | return icon; |
| 493 | } |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 494 | |
Sunny Goyal | 69b7564 | 2015-05-15 17:00:24 -0700 | [diff] [blame] | 495 | @Override |
| 496 | public void requestLayout() { |
| 497 | if (!mDisableRelayout) { |
| 498 | super.requestLayout(); |
| 499 | } |
| 500 | } |
| 501 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 502 | /** |
| 503 | * Applies the item info if it is same as what the view is pointing to currently. |
| 504 | */ |
| 505 | public void reapplyItemInfo(final ItemInfo info) { |
| 506 | if (getTag() == info) { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 507 | FastBitmapDrawable.State prevState = FastBitmapDrawable.State.NORMAL; |
| 508 | if (mIcon instanceof FastBitmapDrawable) { |
| 509 | prevState = ((FastBitmapDrawable) mIcon).getCurrentState(); |
| 510 | } |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 511 | mIconLoadRequest = null; |
Sunny Goyal | 69b7564 | 2015-05-15 17:00:24 -0700 | [diff] [blame] | 512 | mDisableRelayout = true; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 513 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 514 | if (info instanceof AppInfo) { |
| 515 | applyFromApplicationInfo((AppInfo) info); |
| 516 | } else if (info instanceof ShortcutInfo) { |
| 517 | applyFromShortcutInfo((ShortcutInfo) info, |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 518 | LauncherAppState.getInstance().getIconCache()); |
Sunny Goyal | 317698b | 2015-07-29 11:45:41 -0700 | [diff] [blame] | 519 | if ((info.rank < FolderIcon.NUM_ITEMS_IN_PREVIEW) && (info.container >= 0)) { |
| 520 | View folderIcon = |
| 521 | mLauncher.getWorkspace().getHomescreenIconByItemId(info.container); |
| 522 | if (folderIcon != null) { |
| 523 | folderIcon.invalidate(); |
| 524 | } |
| 525 | } |
Sunny Goyal | 0e08f16 | 2015-05-12 11:32:39 -0700 | [diff] [blame] | 526 | } else if (info instanceof PackageItemInfo) { |
| 527 | applyFromPackageItemInfo((PackageItemInfo) info); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 528 | } |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 529 | |
| 530 | // If we are reapplying over an old icon, then we should update the new icon to the same |
| 531 | // state as the old icon |
| 532 | if (mIcon instanceof FastBitmapDrawable) { |
| 533 | ((FastBitmapDrawable) mIcon).setState(prevState); |
| 534 | } |
| 535 | |
Sunny Goyal | 69b7564 | 2015-05-15 17:00:24 -0700 | [diff] [blame] | 536 | mDisableRelayout = false; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Verifies that the current icon is high-res otherwise posts a request to load the icon. |
| 542 | */ |
| 543 | public void verifyHighRes() { |
| 544 | if (mIconLoadRequest != null) { |
| 545 | mIconLoadRequest.cancel(); |
| 546 | mIconLoadRequest = null; |
| 547 | } |
| 548 | if (getTag() instanceof AppInfo) { |
| 549 | AppInfo info = (AppInfo) getTag(); |
| 550 | if (info.usingLowResIcon) { |
| 551 | mIconLoadRequest = LauncherAppState.getInstance().getIconCache() |
| 552 | .updateIconInBackground(BubbleTextView.this, info); |
| 553 | } |
| 554 | } else if (getTag() instanceof ShortcutInfo) { |
| 555 | ShortcutInfo info = (ShortcutInfo) getTag(); |
| 556 | if (info.usingLowResIcon) { |
| 557 | mIconLoadRequest = LauncherAppState.getInstance().getIconCache() |
| 558 | .updateIconInBackground(BubbleTextView.this, info); |
| 559 | } |
Sunny Goyal | 0e08f16 | 2015-05-12 11:32:39 -0700 | [diff] [blame] | 560 | } else if (getTag() instanceof PackageItemInfo) { |
| 561 | PackageItemInfo info = (PackageItemInfo) getTag(); |
| 562 | if (info.usingLowResIcon) { |
| 563 | mIconLoadRequest = LauncherAppState.getInstance().getIconCache() |
| 564 | .updateIconInBackground(BubbleTextView.this, info); |
| 565 | } |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
Sunny Goyal | 4b6eb26 | 2015-05-14 19:24:40 -0700 | [diff] [blame] | 568 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 569 | @Override |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 570 | public void setFastScrollFocusState(final FastBitmapDrawable.State focusState, boolean animated) { |
| 571 | // We can only set the fast scroll focus state on a FastBitmapDrawable |
| 572 | if (!(mIcon instanceof FastBitmapDrawable)) { |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 573 | return; |
| 574 | } |
| 575 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 576 | FastBitmapDrawable d = (FastBitmapDrawable) mIcon; |
| 577 | if (animated) { |
| 578 | FastBitmapDrawable.State prevState = d.getCurrentState(); |
| 579 | if (d.animateState(focusState)) { |
| 580 | // If the state was updated, then update the view accordingly |
| 581 | animate().scaleX(focusState.viewScale) |
| 582 | .scaleY(focusState.viewScale) |
| 583 | .setStartDelay(getStartDelayForStateChange(prevState, focusState)) |
| 584 | .setDuration(d.getDurationForStateChange(prevState, focusState)) |
| 585 | .start(); |
| 586 | } |
| 587 | } else { |
| 588 | if (d.setState(focusState)) { |
| 589 | // If the state was updated, then update the view accordingly |
| 590 | animate().cancel(); |
| 591 | setScaleX(focusState.viewScale); |
| 592 | setScaleY(focusState.viewScale); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
Sunny Goyal | 4b6eb26 | 2015-05-14 19:24:40 -0700 | [diff] [blame] | 597 | /** |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 598 | * Returns the start delay when animating between certain {@link FastBitmapDrawable} states. |
| 599 | */ |
| 600 | private static int getStartDelayForStateChange(final FastBitmapDrawable.State fromState, |
| 601 | final FastBitmapDrawable.State toState) { |
| 602 | switch (toState) { |
| 603 | case NORMAL: |
| 604 | switch (fromState) { |
| 605 | case FAST_SCROLL_HIGHLIGHTED: |
| 606 | return FastBitmapDrawable.FAST_SCROLL_INACTIVE_DURATION / 4; |
| 607 | } |
| 608 | } |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | /** |
Sunny Goyal | 4b6eb26 | 2015-05-14 19:24:40 -0700 | [diff] [blame] | 613 | * Interface to be implemented by the grand parent to allow click shadow effect. |
| 614 | */ |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame^] | 615 | public interface BubbleTextShadowHandler { |
Sunny Goyal | 4b6eb26 | 2015-05-14 19:24:40 -0700 | [diff] [blame] | 616 | void setPressedIcon(BubbleTextView icon, Bitmap background); |
| 617 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 618 | } |