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