blob: 21a8fd406e210b00acf860f35261d092948ddcf4 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyal14168432019-10-24 15:59:49 -070019import static com.android.launcher3.FastBitmapDrawable.newIcon;
20import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
Sunny Goyal066ace12018-11-05 11:08:31 -080021import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;
22
Tony4043b052018-08-17 13:47:39 -070023import android.animation.Animator;
24import android.animation.AnimatorListenerAdapter;
Tony Wickham1237df02017-02-24 08:59:36 -080025import android.animation.ObjectAnimator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026import android.content.Context;
Adam Cohen96bb7982014-07-07 11:58:56 -070027import android.content.res.ColorStateList;
Adam Cohen96bb7982014-07-07 11:58:56 -070028import android.content.res.TypedArray;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.graphics.Canvas;
Tony17b7f9b2017-05-23 12:19:09 -070030import android.graphics.Color;
Winson1f064272016-07-18 17:18:02 -070031import android.graphics.Paint;
Tony Wickham1237df02017-02-24 08:59:36 -080032import android.graphics.Rect;
Tony17b7f9b2017-05-23 12:19:09 -070033import android.graphics.drawable.ColorDrawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.graphics.drawable.Drawable;
Sunny Goyal66dccad2018-03-19 12:00:51 -070035import android.text.TextUtils.TruncateAt;
Winson Chung656d11c2010-11-29 17:15:47 -080036import android.util.AttributeSet;
Tony Wickham1237df02017-02-24 08:59:36 -080037import android.util.Property;
Winson Chung5f8afe62013-08-12 16:19:28 -070038import android.util.TypedValue;
Sunny Goyal508da152014-08-14 10:53:27 -070039import android.view.KeyEvent;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080040import android.view.MotionEvent;
Sunny Goyal317698b2015-07-29 11:45:41 -070041import android.view.View;
Jason Monk02dd7ae2014-04-15 15:23:31 -040042import android.view.ViewConfiguration;
Sunny Goyal4ffec482016-02-09 11:28:52 -080043import android.view.ViewDebug;
Michael Jurkabdb5c532011-02-01 15:05:06 -080044import android.widget.TextView;
Sunny Goyal317698b2015-07-29 11:45:41 -070045
Sunny Goyal3dce5f32017-10-05 11:40:05 -070046import com.android.launcher3.Launcher.OnResumeCallback;
Adam Cohen29794c52019-06-21 12:50:30 -070047import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Tony Wickhamf34bee82018-12-03 18:11:39 -080048import com.android.launcher3.dot.DotInfo;
Adam Cohen65086992020-02-19 08:40:49 -080049import com.android.launcher3.dragndrop.DraggableView;
Tony7308cde2017-06-27 22:38:33 -070050import com.android.launcher3.folder.FolderIcon;
Tony Wickham1237df02017-02-24 08:59:36 -080051import com.android.launcher3.graphics.IconPalette;
Tony Wickhame1cb93f2019-05-03 11:27:32 -070052import com.android.launcher3.graphics.IconShape;
Sunny Goyal96ac68a2017-02-02 16:37:21 -080053import com.android.launcher3.graphics.PreloadIconDrawable;
Tony Wickham8912b042018-11-29 15:28:53 -080054import com.android.launcher3.icons.DotRenderer;
Sunny Goyalfe8e4a92018-11-13 19:43:57 -080055import com.android.launcher3.icons.IconCache.IconLoadRequest;
56import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -070057import com.android.launcher3.model.PackageItemInfo;
Sunny Goyalfe8e4a92018-11-13 19:43:57 -080058import com.android.launcher3.views.ActivityContext;
Jon Miranda9b78e192019-08-30 18:42:01 -070059import com.android.launcher3.views.IconLabelDotView;
Sunny Goyal34b65272015-03-11 16:56:52 -070060
Sunny Goyalc469aad2015-10-01 11:24:23 -070061import java.text.NumberFormat;
62
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063/**
64 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
65 * because we want to make the bubble taller than the text and TextView's clip is
66 * too aggressive.
67 */
Jon Miranda9b78e192019-08-30 18:42:01 -070068public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, OnResumeCallback,
Adam Cohen65086992020-02-19 08:40:49 -080069 IconLabelDotView, DraggableView {
Sunny Goyal95abbb32014-08-04 10:53:22 -070070
Sunny Goyaldfaccf62015-05-11 16:30:44 -070071 private static final int DISPLAY_WORKSPACE = 0;
72 private static final int DISPLAY_ALL_APPS = 1;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -070073 private static final int DISPLAY_FOLDER = 2;
Sunny Goyaldfaccf62015-05-11 16:30:44 -070074
Sunny Goyal2a76e3f2017-02-16 13:33:15 -080075 private static final int[] STATE_PRESSED = new int[] {android.R.attr.state_pressed};
76
Tony Wickham1237df02017-02-24 08:59:36 -080077
Tony Wickhamf34bee82018-12-03 18:11:39 -080078 private static final Property<BubbleTextView, Float> DOT_SCALE_PROPERTY
79 = new Property<BubbleTextView, Float>(Float.TYPE, "dotScale") {
Tony Wickham1237df02017-02-24 08:59:36 -080080 @Override
81 public Float get(BubbleTextView bubbleTextView) {
Tony Wickham8912b042018-11-29 15:28:53 -080082 return bubbleTextView.mDotParams.scale;
Tony Wickham1237df02017-02-24 08:59:36 -080083 }
84
85 @Override
86 public void set(BubbleTextView bubbleTextView, Float value) {
Tony Wickham8912b042018-11-29 15:28:53 -080087 bubbleTextView.mDotParams.scale = value;
Tony Wickham1237df02017-02-24 08:59:36 -080088 bubbleTextView.invalidate();
89 }
90 };
91
Sunny Goyaled7a6932018-04-13 11:41:50 -070092 public static final Property<BubbleTextView, Float> TEXT_ALPHA_PROPERTY
93 = new Property<BubbleTextView, Float>(Float.class, "textAlpha") {
Tony8f402802017-06-16 17:24:54 -070094 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -070095 public Float get(BubbleTextView bubbleTextView) {
96 return bubbleTextView.mTextAlpha;
Tony8f402802017-06-16 17:24:54 -070097 }
98
99 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700100 public void set(BubbleTextView bubbleTextView, Float alpha) {
Tony8f402802017-06-16 17:24:54 -0700101 bubbleTextView.setTextAlpha(alpha);
102 }
103 };
104
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800105 private final ActivityContext mActivity;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700106 private Drawable mIcon;
Adam Cohen65086992020-02-19 08:40:49 -0800107 private boolean mCenterVertically;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700108
Samuel Fufac96fa242019-09-26 23:06:32 -0700109 private final int mDisplay;
110
Sunny Goyaled7a6932018-04-13 11:41:50 -0700111 private final CheckLongPressHelper mLongPressHelper;
112 private final StylusEventHelper mStylusEventHelper;
113 private final float mSlop;
114
115 private final boolean mLayoutHorizontal;
116 private final int mIconSize;
117
118 @ViewDebug.ExportedProperty(category = "launcher")
119 private boolean mIsIconVisible = true;
120 @ViewDebug.ExportedProperty(category = "launcher")
121 private int mTextColor;
122 @ViewDebug.ExportedProperty(category = "launcher")
123 private float mTextAlpha = 1;
124
Tony4043b052018-08-17 13:47:39 -0700125 @ViewDebug.ExportedProperty(category = "launcher")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800126 private DotInfo mDotInfo;
Tony Wickham8912b042018-11-29 15:28:53 -0800127 private DotRenderer mDotRenderer;
128 @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
129 private DotRenderer.DrawParams mDotParams;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800130 private Animator mDotScaleAnim;
131 private boolean mForceHideDot;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700132
Sunny Goyal4ffec482016-02-09 11:28:52 -0800133 @ViewDebug.ExportedProperty(category = "launcher")
Michael Jurkaddd62e92011-02-16 17:49:14 -0800134 private boolean mStayPressed;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800135 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal508da152014-08-14 10:53:27 -0700136 private boolean mIgnorePressedStateChange;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800137 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal69b75642015-05-15 17:00:24 -0700138 private boolean mDisableRelayout = false;
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500139
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700140 @ViewDebug.ExportedProperty(category = "launcher")
141 private final boolean mIgnorePaddingTouch;
142
Sunny Goyal34b65272015-03-11 16:56:52 -0700143 private IconLoadRequest mIconLoadRequest;
144
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145 public BubbleTextView(Context context) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700146 this(context, null, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 }
148
149 public BubbleTextView(Context context, AttributeSet attrs) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700150 this(context, attrs, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 }
152
153 public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
154 super(context, attrs, defStyle);
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800155 mActivity = ActivityContext.lookupContext(context);
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700156 mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
Adam Cohen96bb7982014-07-07 11:58:56 -0700157
Adam Cohen96bb7982014-07-07 11:58:56 -0700158 TypedArray a = context.obtainStyledAttributes(attrs,
159 R.styleable.BubbleTextView, defStyle, 0);
Winson Chungb745afb2015-03-02 11:51:23 -0800160 mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700161
Samuel Fufac96fa242019-09-26 23:06:32 -0700162 mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700163 final int defaultIconSize;
Samuel Fufac96fa242019-09-26 23:06:32 -0700164 if (mDisplay == DISPLAY_WORKSPACE) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700165 DeviceProfile grid = mActivity.getWallpaperDeviceProfile();
Winson Chung44d0aac2015-05-11 18:02:55 -0700166 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
Jon Miranda09660722017-06-14 14:20:14 -0700167 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700168 defaultIconSize = grid.iconSizePx;
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700169 mIgnorePaddingTouch = true;
Samuel Fufac96fa242019-09-26 23:06:32 -0700170 } else if (mDisplay == DISPLAY_ALL_APPS) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700171 DeviceProfile grid = mActivity.getDeviceProfile();
Winson1f064272016-07-18 17:18:02 -0700172 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
173 setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700174 defaultIconSize = grid.allAppsIconSizePx;
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700175 mIgnorePaddingTouch = true;
Samuel Fufac96fa242019-09-26 23:06:32 -0700176 } else if (mDisplay == DISPLAY_FOLDER) {
Sunny Goyalae6e3182019-04-30 12:04:37 -0700177 DeviceProfile grid = mActivity.getDeviceProfile();
Jon Mirandabf7d8122016-11-03 15:29:29 -0700178 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700179 setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700180 defaultIconSize = grid.folderChildIconSizePx;
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700181 mIgnorePaddingTouch = true;
Sunny Goyalae6e3182019-04-30 12:04:37 -0700182 } else {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700183 // widget_selection or shortcut_popup
Sunny Goyalae6e3182019-04-30 12:04:37 -0700184 defaultIconSize = mActivity.getDeviceProfile().iconSizePx;
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700185 mIgnorePaddingTouch = false;
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700186 }
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700187
Winson1f064272016-07-18 17:18:02 -0700188 mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700189
190 mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
191 defaultIconSize);
Adam Cohen96bb7982014-07-07 11:58:56 -0700192 a.recycle();
193
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800194 mLongPressHelper = new CheckLongPressHelper(this);
Mady Mellorbb835202015-07-15 16:34:34 -0700195 mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800196
Tony Wickham8912b042018-11-29 15:28:53 -0800197 mDotParams = new DotRenderer.DrawParams();
198
Sunny Goyal66dccad2018-03-19 12:00:51 -0700199 setEllipsize(TruncateAt.END);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700200 setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
Sunny Goyaled7a6932018-04-13 11:41:50 -0700201 setTextAlpha(1f);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 }
203
Sunny Goyal66dccad2018-03-19 12:00:51 -0700204 @Override
205 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
206 // Disable marques when not focused to that, so that updating text does not cause relayout.
207 setEllipsize(focused ? TruncateAt.MARQUEE : TruncateAt.END);
208 super.onFocusChanged(focused, direction, previouslyFocusedRect);
209 }
210
Jon Miranda52549442017-10-26 11:28:06 -0700211 /**
212 * Resets the view so it can be recycled.
213 */
214 public void reset() {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800215 mDotInfo = null;
Tony Wickham8912b042018-11-29 15:28:53 -0800216 mDotParams.color = Color.TRANSPARENT;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800217 cancelDotScaleAnim();
Tony Wickham8912b042018-11-29 15:28:53 -0800218 mDotParams.scale = 0f;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800219 mForceHideDot = false;
Samuel Fufaba6b47f2019-11-07 10:27:41 -0800220 setBackground(null);
Jon Miranda52549442017-10-26 11:28:06 -0700221 }
222
Tony Wickhamf34bee82018-12-03 18:11:39 -0800223 private void cancelDotScaleAnim() {
224 if (mDotScaleAnim != null) {
225 mDotScaleAnim.cancel();
Tony4043b052018-08-17 13:47:39 -0700226 }
227 }
228
Tony Wickhamf34bee82018-12-03 18:11:39 -0800229 private void animateDotScale(float... dotScales) {
230 cancelDotScaleAnim();
231 mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales);
232 mDotScaleAnim.addListener(new AnimatorListenerAdapter() {
Tony4043b052018-08-17 13:47:39 -0700233 @Override
234 public void onAnimationEnd(Animator animation) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800235 mDotScaleAnim = null;
Tony4043b052018-08-17 13:47:39 -0700236 }
237 });
Tony Wickhamf34bee82018-12-03 18:11:39 -0800238 mDotScaleAnim.start();
Tony4043b052018-08-17 13:47:39 -0700239 }
240
Sunny Goyal95899162019-03-27 16:03:06 -0700241 public void applyFromWorkspaceItem(WorkspaceItemInfo info) {
242 applyFromWorkspaceItem(info, false);
Winson Chung5f8afe62013-08-12 16:19:28 -0700243 }
244
Adam Cohen29794c52019-06-21 12:50:30 -0700245 @Override
246 public void setAccessibilityDelegate(AccessibilityDelegate delegate) {
247 if (delegate instanceof LauncherAccessibilityDelegate) {
248 super.setAccessibilityDelegate(delegate);
249 } else {
250 // NO-OP
251 // Workaround for b/129745295 where RecyclerView is setting our Accessibility
252 // delegate incorrectly. There are no cases when we shouldn't be using the
253 // LauncherAccessibilityDelegate for BubbleTextView.
254 }
255 }
256
Sunny Goyal95899162019-03-27 16:03:06 -0700257 public void applyFromWorkspaceItem(WorkspaceItemInfo info, boolean promiseStateChanged) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800258 applyIconAndLabel(info);
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800259 setTag(info);
Mario Bertschler8ff9e1d2017-08-08 16:26:18 -0700260 if (promiseStateChanged || (info.hasPromiseIconUi())) {
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800261 applyPromiseState(promiseStateChanged);
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500262 }
Tony Wickham010d2552017-01-20 08:15:28 -0800263
Tony Wickhamf34bee82018-12-03 18:11:39 -0800264 applyDotState(info, false /* animate */);
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800265 }
266
Sunny Goyal508da152014-08-14 10:53:27 -0700267 public void applyFromApplicationInfo(AppInfo info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800268 applyIconAndLabel(info);
Sunny Goyalf4204382016-07-13 10:46:07 -0700269
Sunny Goyal95899162019-03-27 16:03:06 -0700270 // We don't need to check the info since it's not a WorkspaceItemInfo
Winson Chung888b3a12015-03-13 11:14:16 -0700271 super.setTag(info);
Sunny Goyal34b65272015-03-11 16:56:52 -0700272
273 // Verify high res immediately
274 verifyHighRes();
Tony Wickham010d2552017-01-20 08:15:28 -0800275
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700276 if (info instanceof PromiseAppInfo) {
277 PromiseAppInfo promiseAppInfo = (PromiseAppInfo) info;
278 applyProgressLevel(promiseAppInfo.level);
279 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800280 applyDotState(info, false /* animate */);
Sunny Goyal508da152014-08-14 10:53:27 -0700281 }
282
Sunny Goyal0e08f162015-05-12 11:32:39 -0700283 public void applyFromPackageItemInfo(PackageItemInfo info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800284 applyIconAndLabel(info);
Sunny Goyal95899162019-03-27 16:03:06 -0700285 // We don't need to check the info since it's not a WorkspaceItemInfo
Sunny Goyal0e08f162015-05-12 11:32:39 -0700286 super.setTag(info);
287
288 // Verify high res immediately
289 verifyHighRes();
290 }
291
Sunny Goyal179249d2017-12-19 16:49:24 -0800292 private void applyIconAndLabel(ItemInfoWithIcon info) {
Sunny Goyal14168432019-10-24 15:59:49 -0700293 FastBitmapDrawable iconDrawable = newIcon(getContext(), info);
Sunny Goyal3808a692019-10-25 13:41:28 -0700294 mDotParams.color = IconPalette.getMutedColor(info.bitmap.color, 0.54f);
Sunny Goyal179249d2017-12-19 16:49:24 -0800295
Sunny Goyalf4204382016-07-13 10:46:07 -0700296 setIcon(iconDrawable);
297 setText(info.title);
298 if (info.contentDescription != null) {
299 setContentDescription(info.isDisabled()
300 ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
301 : info.contentDescription);
302 }
303 }
304
Winson Chung7501adf2015-06-02 11:24:28 -0700305 /**
306 * Overrides the default long press timeout.
307 */
Tony2ca999c2018-09-24 17:24:51 -0400308 public void setLongPressTimeoutFactor(float longPressTimeoutFactor) {
309 mLongPressHelper.setLongPressTimeoutFactor(longPressTimeoutFactor);
Winson Chung7501adf2015-06-02 11:24:28 -0700310 }
Sunny Goyal0e08f162015-05-12 11:32:39 -0700311
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800312 @Override
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800313 public void refreshDrawableState() {
Sunny Goyal508da152014-08-14 10:53:27 -0700314 if (!mIgnorePressedStateChange) {
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800315 super.refreshDrawableState();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800316 }
Sunny Goyal508da152014-08-14 10:53:27 -0700317 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800318
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800319 @Override
320 protected int[] onCreateDrawableState(int extraSpace) {
321 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
322 if (mStayPressed) {
323 mergeDrawableStates(drawableState, STATE_PRESSED);
324 }
325 return drawableState;
326 }
327
Winson Chungb745afb2015-03-02 11:51:23 -0800328 /** Returns the icon for this view. */
329 public Drawable getIcon() {
330 return mIcon;
331 }
332
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700333 @Override
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800334 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700335 // ignore events if they happen in padding area
336 if (event.getAction() == MotionEvent.ACTION_DOWN && mIgnorePaddingTouch
337 && (event.getY() < getPaddingTop()
338 || event.getX() < getPaddingLeft()
339 || event.getY() > getHeight() - getPaddingBottom()
340 || event.getX() > getWidth() - getPaddingRight())) {
341 return false;
342 }
343
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800344 // Call the superclass onTouchEvent first, because sometimes it changes the state to
345 // isPressed() on an ACTION_UP
346 boolean result = super.onTouchEvent(event);
347
Mady Melloref044dd2015-06-02 15:35:07 -0700348 // Check for a stylus button press, if it occurs cancel any long press checks.
Mady Mellorbb835202015-07-15 16:34:34 -0700349 if (mStylusEventHelper.onMotionEvent(event)) {
Mady Melloref044dd2015-06-02 15:35:07 -0700350 mLongPressHelper.cancelLongPress();
351 result = true;
352 }
353
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800354 switch (event.getAction()) {
355 case MotionEvent.ACTION_DOWN:
Mady Melloref044dd2015-06-02 15:35:07 -0700356 // If we're in a stylus button press, don't check for long press.
357 if (!mStylusEventHelper.inStylusButtonPressed()) {
358 mLongPressHelper.postCheckForLongPress();
359 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800360 break;
361 case MotionEvent.ACTION_CANCEL:
362 case MotionEvent.ACTION_UP:
Winson Chung88f33452012-02-23 15:23:44 -0800363 mLongPressHelper.cancelLongPress();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800364 break;
Jason Monk02dd7ae2014-04-15 15:23:31 -0400365 case MotionEvent.ACTION_MOVE:
366 if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) {
367 mLongPressHelper.cancelLongPress();
368 }
369 break;
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800370 }
371 return result;
372 }
373
Michael Jurkaddd62e92011-02-16 17:49:14 -0800374 void setStayPressed(boolean stayPressed) {
375 mStayPressed = stayPressed;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800376 refreshDrawableState();
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800377 }
378
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700379 @Override
Hyunyoung Songef468d82019-01-03 01:02:43 -0800380 public void onVisibilityAggregated(boolean isVisible) {
381 super.onVisibilityAggregated(isVisible);
382 if (mIcon != null) {
Hyunyoung Songa2373852019-01-04 12:01:32 -0800383 mIcon.setVisible(isVisible, false);
Hyunyoung Songef468d82019-01-03 01:02:43 -0800384 }
385 }
386
387 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700388 public void onLauncherResume() {
389 // Reset the pressed state of icon that was locked in the press state while activity
390 // was launching
391 setStayPressed(false);
392 }
393
Sunny Goyal508da152014-08-14 10:53:27 -0700394 void clearPressedBackground() {
395 setPressed(false);
396 setStayPressed(false);
397 }
398
399 @Override
Sunny Goyal508da152014-08-14 10:53:27 -0700400 public boolean onKeyUp(int keyCode, KeyEvent event) {
401 // Unlike touch events, keypress event propagate pressed state change immediately,
402 // without waiting for onClickHandler to execute. Disable pressed state changes here
403 // to avoid flickering.
404 mIgnorePressedStateChange = true;
405 boolean result = super.onKeyUp(keyCode, event);
Sunny Goyal508da152014-08-14 10:53:27 -0700406 mIgnorePressedStateChange = false;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800407 refreshDrawableState();
Sunny Goyal508da152014-08-14 10:53:27 -0700408 return result;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800409 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800410
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700411 @SuppressWarnings("wrongcall")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800412 protected void drawWithoutDot(Canvas canvas) {
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700413 super.onDraw(canvas);
414 }
415
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416 @Override
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700417 public void onDraw(Canvas canvas) {
418 super.onDraw(canvas);
Tony Wickhamf34bee82018-12-03 18:11:39 -0800419 drawDotIfNecessary(canvas);
Tony Wickham1237df02017-02-24 08:59:36 -0800420 }
421
422 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800423 * Draws the notification dot in the top right corner of the icon bounds.
Tony Wickham1237df02017-02-24 08:59:36 -0800424 * @param canvas The canvas to draw to.
425 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800426 protected void drawDotIfNecessary(Canvas canvas) {
427 if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800428 getIconBounds(mDotParams.iconBounds);
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700429 Utilities.scaleRectAboutCenter(mDotParams.iconBounds, IconShape.getNormalizationScale());
Tony Wickham1237df02017-02-24 08:59:36 -0800430 final int scrollX = getScrollX();
431 final int scrollY = getScrollY();
432 canvas.translate(scrollX, scrollY);
Tony Wickham8912b042018-11-29 15:28:53 -0800433 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham1237df02017-02-24 08:59:36 -0800434 canvas.translate(-scrollX, -scrollY);
435 }
436 }
437
Jon Miranda9b78e192019-08-30 18:42:01 -0700438 @Override
439 public void setForceHideDot(boolean forceHideDot) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800440 if (mForceHideDot == forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800441 return;
442 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800443 mForceHideDot = forceHideDot;
Tony Wickham1237df02017-02-24 08:59:36 -0800444
Tony Wickhamf34bee82018-12-03 18:11:39 -0800445 if (forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800446 invalidate();
Tony Wickhamf34bee82018-12-03 18:11:39 -0800447 } else if (hasDot()) {
448 animateDotScale(0, 1);
Tony Wickham1237df02017-02-24 08:59:36 -0800449 }
450 }
451
Tony Wickhamf34bee82018-12-03 18:11:39 -0800452 private boolean hasDot() {
453 return mDotInfo != null;
Tony Wickham1237df02017-02-24 08:59:36 -0800454 }
455
456 public void getIconBounds(Rect outBounds) {
Tony05d98c22018-07-23 08:01:15 -0700457 getIconBounds(this, outBounds, mIconSize);
458 }
459
460 public static void getIconBounds(View iconView, Rect outBounds, int iconSize) {
461 int top = iconView.getPaddingTop();
462 int left = (iconView.getWidth() - iconSize) / 2;
463 int right = left + iconSize;
464 int bottom = top + iconSize;
Tony Wickham1237df02017-02-24 08:59:36 -0800465 outBounds.set(left, top, right, bottom);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800466 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400467
468 @Override
Winson1f064272016-07-18 17:18:02 -0700469 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
470 if (mCenterVertically) {
471 Paint.FontMetrics fm = getPaint().getFontMetrics();
472 int cellHeightPx = mIconSize + getCompoundDrawablePadding() +
473 (int) Math.ceil(fm.bottom - fm.top);
474 int height = MeasureSpec.getSize(heightMeasureSpec);
475 setPadding(getPaddingLeft(), (height - cellHeightPx) / 2, getPaddingRight(),
476 getPaddingBottom());
477 }
478 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
479 }
480
481 @Override
Adam Cohen477828c2013-09-20 12:05:49 -0700482 public void setTextColor(int color) {
483 mTextColor = color;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700484 super.setTextColor(getModifiedColor());
Adam Cohen477828c2013-09-20 12:05:49 -0700485 }
486
Adam Cohen96bb7982014-07-07 11:58:56 -0700487 @Override
488 public void setTextColor(ColorStateList colors) {
489 mTextColor = colors.getDefaultColor();
Sunny Goyaled7a6932018-04-13 11:41:50 -0700490 if (Float.compare(mTextAlpha, 1) == 0) {
491 super.setTextColor(colors);
492 } else {
493 super.setTextColor(getModifiedColor());
494 }
Adam Cohen477828c2013-09-20 12:05:49 -0700495 }
496
Tony7308cde2017-06-27 22:38:33 -0700497 public boolean shouldTextBeVisible() {
498 // Text should be visible everywhere but the hotseat.
499 Object tag = getParent() instanceof FolderIcon ? ((View) getParent()).getTag() : getTag();
500 ItemInfo info = tag instanceof ItemInfo ? (ItemInfo) tag : null;
Samuel Fufaefb665d2019-10-30 13:24:14 -0700501 return info == null || (info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT
502 && info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION);
Tony7308cde2017-06-27 22:38:33 -0700503 }
504
Winson Chung5f8afe62013-08-12 16:19:28 -0700505 public void setTextVisibility(boolean visible) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700506 setTextAlpha(visible ? 1 : 0);
507 }
508
509 private void setTextAlpha(float alpha) {
510 mTextAlpha = alpha;
511 super.setTextColor(getModifiedColor());
512 }
513
514 private int getModifiedColor() {
515 if (mTextAlpha == 0) {
516 // Special case to prevent text shadows in high contrast mode
517 return Color.TRANSPARENT;
Winson Chung5f8afe62013-08-12 16:19:28 -0700518 }
Sunny Goyal066ace12018-11-05 11:08:31 -0800519 return setColorAlphaBound(mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
Tony8f402802017-06-16 17:24:54 -0700520 }
521
522 /**
523 * Creates an animator to fade the text in or out.
524 * @param fadeIn Whether the text should fade in or fade out.
525 */
Sunny Goyal4e5a8782017-06-23 09:34:06 -0700526 public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700527 float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0;
Jon Miranda83cdca62019-04-15 13:01:05 -0700528 return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha);
Tony8f402802017-06-16 17:24:54 -0700529 }
530
Winson Chungaffd7b42010-08-20 15:11:56 -0700531 @Override
Winson Chung88f33452012-02-23 15:23:44 -0800532 public void cancelLongPress() {
533 super.cancelLongPress();
534
535 mLongPressHelper.cancelLongPress();
536 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500537
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800538 public void applyPromiseState(boolean promiseStateChanged) {
Sunny Goyal95899162019-03-27 16:03:06 -0700539 if (getTag() instanceof WorkspaceItemInfo) {
540 WorkspaceItemInfo info = (WorkspaceItemInfo) getTag();
Mario Bertschler8ff9e1d2017-08-08 16:26:18 -0700541 final boolean isPromise = info.hasPromiseIconUi();
Sunny Goyal34942622014-08-29 17:20:55 -0700542 final int progressLevel = isPromise ?
Sunny Goyal95899162019-03-27 16:03:06 -0700543 ((info.hasStatusFlag(WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE) ?
Sunny Goyal34942622014-08-29 17:20:55 -0700544 info.getInstallProgress() : 0)) : 100;
Sunny Goyale755d462014-07-22 13:48:29 -0700545
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700546 PreloadIconDrawable preloadDrawable = applyProgressLevel(progressLevel);
547 if (preloadDrawable != null && promiseStateChanged) {
548 preloadDrawable.maybePerformFinishedAnimation();
549 }
550 }
551 }
552
553 public PreloadIconDrawable applyProgressLevel(int progressLevel) {
554 if (getTag() instanceof ItemInfoWithIcon) {
555 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Mario Bertschler230612f2017-09-27 17:05:21 -0700556 if (progressLevel >= 100) {
557 setContentDescription(info.contentDescription != null
558 ? info.contentDescription : "");
559 } else if (progressLevel > 0) {
560 setContentDescription(getContext()
561 .getString(R.string.app_downloading_title, info.title,
562 NumberFormat.getPercentInstance().format(progressLevel * 0.01)));
563 } else {
564 setContentDescription(getContext()
565 .getString(R.string.app_waiting_download_title, info.title));
566 }
Winson Chungb745afb2015-03-02 11:51:23 -0800567 if (mIcon != null) {
Sunny Goyale755d462014-07-22 13:48:29 -0700568 final PreloadIconDrawable preloadDrawable;
Winson Chungb745afb2015-03-02 11:51:23 -0800569 if (mIcon instanceof PreloadIconDrawable) {
570 preloadDrawable = (PreloadIconDrawable) mIcon;
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700571 preloadDrawable.setLevel(progressLevel);
Sunny Goyale755d462014-07-22 13:48:29 -0700572 } else {
Sunny Goyal14168432019-10-24 15:59:49 -0700573 preloadDrawable = newPendingIcon(getContext(), info);
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700574 preloadDrawable.setLevel(progressLevel);
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700575 setIcon(preloadDrawable);
Sunny Goyale755d462014-07-22 13:48:29 -0700576 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700577 return preloadDrawable;
Sunny Goyale755d462014-07-22 13:48:29 -0700578 }
Chris Wren40c5ed32014-06-24 18:24:23 -0400579 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700580 return null;
Chris Wren40c5ed32014-06-24 18:24:23 -0400581 }
Sunny Goyal95abbb32014-08-04 10:53:22 -0700582
Tony Wickhamf34bee82018-12-03 18:11:39 -0800583 public void applyDotState(ItemInfo itemInfo, boolean animate) {
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800584 if (mIcon instanceof FastBitmapDrawable) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800585 boolean wasDotted = mDotInfo != null;
586 mDotInfo = mActivity.getDotInfoForItem(itemInfo);
587 boolean isDotted = mDotInfo != null;
588 float newDotScale = isDotted ? 1f : 0;
Samuel Fufac96fa242019-09-26 23:06:32 -0700589 if (mDisplay == DISPLAY_ALL_APPS) {
590 mDotRenderer = mActivity.getDeviceProfile().mDotRendererAllApps;
591 } else {
592 mDotRenderer = mActivity.getDeviceProfile().mDotRendererWorkSpace;
593 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800594 if (wasDotted || isDotted) {
595 // Animate when a dot is first added or when it is removed.
596 if (animate && (wasDotted ^ isDotted) && isShown()) {
597 animateDotScale(newDotScale);
Tony Wickham1237df02017-02-24 08:59:36 -0800598 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800599 cancelDotScaleAnim();
600 mDotParams.scale = newDotScale;
Tony Wickham1237df02017-02-24 08:59:36 -0800601 invalidate();
602 }
603 }
Tony Wickham305e9202018-01-23 17:46:47 -0800604 if (itemInfo.contentDescription != null) {
vadimtda6dad52019-05-21 13:24:23 -0700605 if (itemInfo.isDisabled()) {
606 setContentDescription(getContext().getString(R.string.disabled_app_label,
607 itemInfo.contentDescription));
608 } else if (hasDot()) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800609 int count = mDotInfo.getNotificationCount();
Tony Wickham305e9202018-01-23 17:46:47 -0800610 setContentDescription(getContext().getResources().getQuantityString(
Tony Wickhamf34bee82018-12-03 18:11:39 -0800611 R.plurals.dotted_app_label, count, itemInfo.contentDescription, count));
Tony Wickham305e9202018-01-23 17:46:47 -0800612 } else {
613 setContentDescription(itemInfo.contentDescription);
614 }
615 }
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800616 }
617 }
618
Winson Chungb745afb2015-03-02 11:51:23 -0800619 /**
620 * Sets the icon for this view based on the layout direction.
621 */
Tony Wickham377ed3f2016-07-20 15:21:04 -0700622 private void setIcon(Drawable icon) {
Tony17b7f9b2017-05-23 12:19:09 -0700623 if (mIsIconVisible) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700624 applyCompoundDrawables(icon);
Tony17b7f9b2017-05-23 12:19:09 -0700625 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700626 mIcon = icon;
Hyunyoung Songa2373852019-01-04 12:01:32 -0800627 if (mIcon != null) {
628 mIcon.setVisible(getWindowVisibility() == VISIBLE && isShown(), false);
629 }
Tony17b7f9b2017-05-23 12:19:09 -0700630 }
631
Jon Miranda9b78e192019-08-30 18:42:01 -0700632 @Override
Tony17b7f9b2017-05-23 12:19:09 -0700633 public void setIconVisible(boolean visible) {
634 mIsIconVisible = visible;
Sunny Goyal66dccad2018-03-19 12:00:51 -0700635 Drawable icon = visible ? mIcon : new ColorDrawable(Color.TRANSPARENT);
Tony17b7f9b2017-05-23 12:19:09 -0700636 applyCompoundDrawables(icon);
Tony Wickham377ed3f2016-07-20 15:21:04 -0700637 }
638
639 protected void applyCompoundDrawables(Drawable icon) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700640 // If we had already set an icon before, disable relayout as the icon size is the
641 // same as before.
642 mDisableRelayout = mIcon != null;
643
644 icon.setBounds(0, 0, mIconSize, mIconSize);
Winson Chungb745afb2015-03-02 11:51:23 -0800645 if (mLayoutHorizontal) {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800646 setCompoundDrawablesRelative(icon, null, null, null);
Winson Chungb745afb2015-03-02 11:51:23 -0800647 } else {
Tony Wickham377ed3f2016-07-20 15:21:04 -0700648 setCompoundDrawables(null, icon, null, null);
Winson Chungb745afb2015-03-02 11:51:23 -0800649 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700650 mDisableRelayout = false;
Winson Chungb745afb2015-03-02 11:51:23 -0800651 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700652
Sunny Goyal69b75642015-05-15 17:00:24 -0700653 @Override
654 public void requestLayout() {
655 if (!mDisableRelayout) {
656 super.requestLayout();
657 }
658 }
659
Sunny Goyal34b65272015-03-11 16:56:52 -0700660 /**
661 * Applies the item info if it is same as what the view is pointing to currently.
662 */
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800663 @Override
664 public void reapplyItemInfo(ItemInfoWithIcon info) {
Sunny Goyal34b65272015-03-11 16:56:52 -0700665 if (getTag() == info) {
666 mIconLoadRequest = null;
Sunny Goyal69b75642015-05-15 17:00:24 -0700667 mDisableRelayout = true;
Winsonc0880492015-08-21 11:16:27 -0700668
Jon Miranda7f522a22017-07-28 11:56:47 -0700669 // Optimization: Starting in N, pre-uploads the bitmap to RenderThread.
Sunny Goyal3808a692019-10-25 13:41:28 -0700670 info.bitmap.icon.prepareToDraw();
Jon Miranda7f522a22017-07-28 11:56:47 -0700671
Sunny Goyal34b65272015-03-11 16:56:52 -0700672 if (info instanceof AppInfo) {
673 applyFromApplicationInfo((AppInfo) info);
Sunny Goyal95899162019-03-27 16:03:06 -0700674 } else if (info instanceof WorkspaceItemInfo) {
675 applyFromWorkspaceItem((WorkspaceItemInfo) info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700676 mActivity.invalidateParent(info);
Sunny Goyal0e08f162015-05-12 11:32:39 -0700677 } else if (info instanceof PackageItemInfo) {
678 applyFromPackageItemInfo((PackageItemInfo) info);
Sunny Goyal34b65272015-03-11 16:56:52 -0700679 }
Winsonc0880492015-08-21 11:16:27 -0700680
Sunny Goyal69b75642015-05-15 17:00:24 -0700681 mDisableRelayout = false;
Sunny Goyal34b65272015-03-11 16:56:52 -0700682 }
683 }
684
685 /**
686 * Verifies that the current icon is high-res otherwise posts a request to load the icon.
687 */
688 public void verifyHighRes() {
689 if (mIconLoadRequest != null) {
690 mIconLoadRequest.cancel();
691 mIconLoadRequest = null;
692 }
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800693 if (getTag() instanceof ItemInfoWithIcon) {
694 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Sunny Goyal2b787e52018-08-20 15:01:03 -0700695 if (info.usingLowResIcon()) {
Sunny Goyal87f784c2017-01-11 10:48:34 -0800696 mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache()
Sunny Goyal0e08f162015-05-12 11:32:39 -0700697 .updateIconInBackground(BubbleTextView.this, info);
698 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700699 }
700 }
Sunny Goyal4b6eb262015-05-14 19:24:40 -0700701
Jon Miranda47170112017-03-03 14:57:14 -0800702 public int getIconSize() {
703 return mIconSize;
704 }
Adam Cohen65086992020-02-19 08:40:49 -0800705
706 @Override
707 public int getViewType() {
708 return DRAGGABLE_ICON;
709 }
710
711 @Override
712 public void getVisualDragBounds(Rect bounds) {
713 DeviceProfile grid = mActivity.getDeviceProfile();
714 BubbleTextView.getIconBounds(this, bounds, grid.iconSizePx);
715 }
716
717 @Override
718 public void prepareDrawDragView() {
719 if (getIcon() instanceof FastBitmapDrawable) {
720 FastBitmapDrawable icon = (FastBitmapDrawable) getIcon();
721 icon.setScale(1f);
722 }
723 setForceHideDot(true);
724 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725}