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