blob: 06bb263f2369778de04ffbe250170766823d41af [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;
Adam Cohend9162062020-03-24 16:35:35 -070032import android.graphics.PointF;
Tony Wickham1237df02017-02-24 08:59:36 -080033import android.graphics.Rect;
Tony17b7f9b2017-05-23 12:19:09 -070034import android.graphics.drawable.ColorDrawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.graphics.drawable.Drawable;
Sunny Goyal66dccad2018-03-19 12:00:51 -070036import android.text.TextUtils.TruncateAt;
Winson Chung656d11c2010-11-29 17:15:47 -080037import android.util.AttributeSet;
Tony Wickham1237df02017-02-24 08:59:36 -080038import android.util.Property;
Winson Chung5f8afe62013-08-12 16:19:28 -070039import android.util.TypedValue;
Sunny Goyal508da152014-08-14 10:53:27 -070040import android.view.KeyEvent;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080041import android.view.MotionEvent;
Sunny Goyal317698b2015-07-29 11:45:41 -070042import android.view.View;
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;
Sunny Goyale396abf2020-04-06 15:11:17 -070057import com.android.launcher3.model.data.AppInfo;
58import com.android.launcher3.model.data.ItemInfo;
59import com.android.launcher3.model.data.ItemInfoWithIcon;
60import com.android.launcher3.model.data.PackageItemInfo;
61import com.android.launcher3.model.data.PromiseAppInfo;
62import com.android.launcher3.model.data.WorkspaceItemInfo;
Samuel Fufa167210a2020-05-12 18:40:11 -070063import com.android.launcher3.util.SafeCloseable;
Sunny Goyalfe8e4a92018-11-13 19:43:57 -080064import com.android.launcher3.views.ActivityContext;
Jon Miranda9b78e192019-08-30 18:42:01 -070065import com.android.launcher3.views.IconLabelDotView;
Sunny Goyal34b65272015-03-11 16:56:52 -070066
Sunny Goyalc469aad2015-10-01 11:24:23 -070067import java.text.NumberFormat;
68
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069/**
70 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
71 * because we want to make the bubble taller than the text and TextView's clip is
72 * too aggressive.
73 */
Jon Miranda9b78e192019-08-30 18:42:01 -070074public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, OnResumeCallback,
Adam Cohend9162062020-03-24 16:35:35 -070075 IconLabelDotView, DraggableView, Reorderable {
Sunny Goyal95abbb32014-08-04 10:53:22 -070076
Sunny Goyaldfaccf62015-05-11 16:30:44 -070077 private static final int DISPLAY_WORKSPACE = 0;
78 private static final int DISPLAY_ALL_APPS = 1;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -070079 private static final int DISPLAY_FOLDER = 2;
Samuel Fufa4a53c702020-08-04 14:06:55 -070080 private static final int DISPLAY_HERO_APP = 5;
Sunny Goyaldfaccf62015-05-11 16:30:44 -070081
Samuel Fufad6bacdc2020-08-23 21:56:07 -070082 private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed};
Sunny Goyal2a76e3f2017-02-16 13:33:15 -080083
Adam Cohen1d13c0b2020-04-21 16:29:12 -070084 private final PointF mTranslationForReorderBounce = new PointF(0, 0);
85 private final PointF mTranslationForReorderPreview = new PointF(0, 0);
86
87 private float mScaleForReorderBounce = 1f;
Tony Wickham1237df02017-02-24 08:59:36 -080088
Tony Wickhamf34bee82018-12-03 18:11:39 -080089 private static final Property<BubbleTextView, Float> DOT_SCALE_PROPERTY
90 = new Property<BubbleTextView, Float>(Float.TYPE, "dotScale") {
Tony Wickham1237df02017-02-24 08:59:36 -080091 @Override
92 public Float get(BubbleTextView bubbleTextView) {
Tony Wickham8912b042018-11-29 15:28:53 -080093 return bubbleTextView.mDotParams.scale;
Tony Wickham1237df02017-02-24 08:59:36 -080094 }
95
96 @Override
97 public void set(BubbleTextView bubbleTextView, Float value) {
Tony Wickham8912b042018-11-29 15:28:53 -080098 bubbleTextView.mDotParams.scale = value;
Tony Wickham1237df02017-02-24 08:59:36 -080099 bubbleTextView.invalidate();
100 }
101 };
102
Sunny Goyaled7a6932018-04-13 11:41:50 -0700103 public static final Property<BubbleTextView, Float> TEXT_ALPHA_PROPERTY
104 = new Property<BubbleTextView, Float>(Float.class, "textAlpha") {
Tony8f402802017-06-16 17:24:54 -0700105 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700106 public Float get(BubbleTextView bubbleTextView) {
107 return bubbleTextView.mTextAlpha;
Tony8f402802017-06-16 17:24:54 -0700108 }
109
110 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700111 public void set(BubbleTextView bubbleTextView, Float alpha) {
Tony8f402802017-06-16 17:24:54 -0700112 bubbleTextView.setTextAlpha(alpha);
113 }
114 };
115
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800116 private final ActivityContext mActivity;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700117 private Drawable mIcon;
Adam Cohen65086992020-02-19 08:40:49 -0800118 private boolean mCenterVertically;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700119
Samuel Fufac96fa242019-09-26 23:06:32 -0700120 private final int mDisplay;
121
Sunny Goyaled7a6932018-04-13 11:41:50 -0700122 private final CheckLongPressHelper mLongPressHelper;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700123
124 private final boolean mLayoutHorizontal;
125 private final int mIconSize;
126
127 @ViewDebug.ExportedProperty(category = "launcher")
128 private boolean mIsIconVisible = true;
129 @ViewDebug.ExportedProperty(category = "launcher")
130 private int mTextColor;
131 @ViewDebug.ExportedProperty(category = "launcher")
132 private float mTextAlpha = 1;
133
Tony4043b052018-08-17 13:47:39 -0700134 @ViewDebug.ExportedProperty(category = "launcher")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800135 private DotInfo mDotInfo;
Tony Wickham8912b042018-11-29 15:28:53 -0800136 private DotRenderer mDotRenderer;
137 @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
138 private DotRenderer.DrawParams mDotParams;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800139 private Animator mDotScaleAnim;
140 private boolean mForceHideDot;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700141
Sunny Goyal4ffec482016-02-09 11:28:52 -0800142 @ViewDebug.ExportedProperty(category = "launcher")
Michael Jurkaddd62e92011-02-16 17:49:14 -0800143 private boolean mStayPressed;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800144 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal508da152014-08-14 10:53:27 -0700145 private boolean mIgnorePressedStateChange;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800146 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal69b75642015-05-15 17:00:24 -0700147 private boolean mDisableRelayout = false;
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500148
Sunny Goyal34b65272015-03-11 16:56:52 -0700149 private IconLoadRequest mIconLoadRequest;
150
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 public BubbleTextView(Context context) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700152 this(context, null, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 }
154
155 public BubbleTextView(Context context, AttributeSet attrs) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700156 this(context, attrs, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 }
158
159 public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
160 super(context, attrs, defStyle);
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800161 mActivity = ActivityContext.lookupContext(context);
Adam Cohen96bb7982014-07-07 11:58:56 -0700162
Adam Cohen96bb7982014-07-07 11:58:56 -0700163 TypedArray a = context.obtainStyledAttributes(attrs,
164 R.styleable.BubbleTextView, defStyle, 0);
Winson Chungb745afb2015-03-02 11:51:23 -0800165 mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
Sunny Goyalc4d32012020-04-03 17:10:11 -0700166 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700167
Samuel Fufac96fa242019-09-26 23:06:32 -0700168 mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700169 final int defaultIconSize;
Samuel Fufac96fa242019-09-26 23:06:32 -0700170 if (mDisplay == DISPLAY_WORKSPACE) {
Winson Chung44d0aac2015-05-11 18:02:55 -0700171 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
Jon Miranda09660722017-06-14 14:20:14 -0700172 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700173 defaultIconSize = grid.iconSizePx;
Samuel Fufac96fa242019-09-26 23:06:32 -0700174 } else if (mDisplay == DISPLAY_ALL_APPS) {
Winson1f064272016-07-18 17:18:02 -0700175 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
176 setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700177 defaultIconSize = grid.allAppsIconSizePx;
Samuel Fufac96fa242019-09-26 23:06:32 -0700178 } else if (mDisplay == DISPLAY_FOLDER) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700179 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700180 setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700181 defaultIconSize = grid.folderChildIconSizePx;
Samuel Fufa4a53c702020-08-04 14:06:55 -0700182 } else if (mDisplay == DISPLAY_HERO_APP) {
183 defaultIconSize = grid.allAppsIconSizePx;
Sunny Goyalae6e3182019-04-30 12:04:37 -0700184 } else {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700185 // widget_selection or shortcut_popup
Sunny Goyalc4d32012020-04-03 17:10:11 -0700186 defaultIconSize = grid.iconSizePx;
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700187 }
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700188
Winson1f064272016-07-18 17:18:02 -0700189 mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700190
191 mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
192 defaultIconSize);
Adam Cohen96bb7982014-07-07 11:58:56 -0700193 a.recycle();
194
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800195 mLongPressHelper = new CheckLongPressHelper(this);
196
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
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700283 /**
284 * Apply label and tag using a generic {@link ItemInfoWithIcon}
285 */
286 public void applyFromItemInfoWithIcon(ItemInfoWithIcon info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800287 applyIconAndLabel(info);
Sunny Goyal95899162019-03-27 16:03:06 -0700288 // We don't need to check the info since it's not a WorkspaceItemInfo
Sunny Goyal0e08f162015-05-12 11:32:39 -0700289 super.setTag(info);
290
291 // Verify high res immediately
292 verifyHighRes();
293 }
294
Sunny Goyal179249d2017-12-19 16:49:24 -0800295 private void applyIconAndLabel(ItemInfoWithIcon info) {
Sunny Goyal14168432019-10-24 15:59:49 -0700296 FastBitmapDrawable iconDrawable = newIcon(getContext(), info);
Sunny Goyal3808a692019-10-25 13:41:28 -0700297 mDotParams.color = IconPalette.getMutedColor(info.bitmap.color, 0.54f);
Sunny Goyal179249d2017-12-19 16:49:24 -0800298
Sunny Goyalf4204382016-07-13 10:46:07 -0700299 setIcon(iconDrawable);
300 setText(info.title);
301 if (info.contentDescription != null) {
302 setContentDescription(info.isDisabled()
303 ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
304 : info.contentDescription);
305 }
306 }
307
Winson Chung7501adf2015-06-02 11:24:28 -0700308 /**
309 * Overrides the default long press timeout.
310 */
Tony2ca999c2018-09-24 17:24:51 -0400311 public void setLongPressTimeoutFactor(float longPressTimeoutFactor) {
312 mLongPressHelper.setLongPressTimeoutFactor(longPressTimeoutFactor);
Winson Chung7501adf2015-06-02 11:24:28 -0700313 }
Sunny Goyal0e08f162015-05-12 11:32:39 -0700314
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800315 @Override
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800316 public void refreshDrawableState() {
Sunny Goyal508da152014-08-14 10:53:27 -0700317 if (!mIgnorePressedStateChange) {
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800318 super.refreshDrawableState();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800319 }
Sunny Goyal508da152014-08-14 10:53:27 -0700320 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800321
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800322 @Override
323 protected int[] onCreateDrawableState(int extraSpace) {
324 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
325 if (mStayPressed) {
326 mergeDrawableStates(drawableState, STATE_PRESSED);
327 }
328 return drawableState;
329 }
330
Winson Chungb745afb2015-03-02 11:51:23 -0800331 /** Returns the icon for this view. */
332 public Drawable getIcon() {
333 return mIcon;
334 }
335
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700336 @Override
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800337 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700338 // ignore events if they happen in padding area
Sunny Goyal17feee82020-03-24 13:55:15 -0700339 if (event.getAction() == MotionEvent.ACTION_DOWN
Sunny Goyal44a3b202020-07-09 08:27:06 -0700340 && shouldIgnoreTouchDown(event.getX(), event.getY())) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700341 return false;
342 }
Sunny Goyal17feee82020-03-24 13:55:15 -0700343 if (isLongClickable()) {
344 super.onTouchEvent(event);
345 mLongPressHelper.onTouchEvent(event);
346 // Keep receiving the rest of the events
347 return true;
348 } else {
349 return super.onTouchEvent(event);
Mady Melloref044dd2015-06-02 15:35:07 -0700350 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800351 }
352
Sunny Goyal44a3b202020-07-09 08:27:06 -0700353 /**
354 * Returns true if the touch down at the provided position be ignored
355 */
356 protected boolean shouldIgnoreTouchDown(float x, float y) {
357 return y < getPaddingTop()
358 || x < getPaddingLeft()
359 || y > getHeight() - getPaddingBottom()
360 || x > getWidth() - getPaddingRight();
361 }
362
Michael Jurkaddd62e92011-02-16 17:49:14 -0800363 void setStayPressed(boolean stayPressed) {
364 mStayPressed = stayPressed;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800365 refreshDrawableState();
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800366 }
367
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700368 @Override
Hyunyoung Songef468d82019-01-03 01:02:43 -0800369 public void onVisibilityAggregated(boolean isVisible) {
370 super.onVisibilityAggregated(isVisible);
371 if (mIcon != null) {
Hyunyoung Songa2373852019-01-04 12:01:32 -0800372 mIcon.setVisible(isVisible, false);
Hyunyoung Songef468d82019-01-03 01:02:43 -0800373 }
374 }
375
376 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700377 public void onLauncherResume() {
378 // Reset the pressed state of icon that was locked in the press state while activity
379 // was launching
380 setStayPressed(false);
381 }
382
Sunny Goyal508da152014-08-14 10:53:27 -0700383 void clearPressedBackground() {
384 setPressed(false);
385 setStayPressed(false);
386 }
387
388 @Override
Sunny Goyal508da152014-08-14 10:53:27 -0700389 public boolean onKeyUp(int keyCode, KeyEvent event) {
390 // Unlike touch events, keypress event propagate pressed state change immediately,
391 // without waiting for onClickHandler to execute. Disable pressed state changes here
392 // to avoid flickering.
393 mIgnorePressedStateChange = true;
394 boolean result = super.onKeyUp(keyCode, event);
Sunny Goyal508da152014-08-14 10:53:27 -0700395 mIgnorePressedStateChange = false;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800396 refreshDrawableState();
Sunny Goyal508da152014-08-14 10:53:27 -0700397 return result;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800398 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800399
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700400 @SuppressWarnings("wrongcall")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800401 protected void drawWithoutDot(Canvas canvas) {
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700402 super.onDraw(canvas);
403 }
404
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 @Override
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700406 public void onDraw(Canvas canvas) {
407 super.onDraw(canvas);
Tony Wickhamf34bee82018-12-03 18:11:39 -0800408 drawDotIfNecessary(canvas);
Tony Wickham1237df02017-02-24 08:59:36 -0800409 }
410
411 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800412 * Draws the notification dot in the top right corner of the icon bounds.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700413 *
Tony Wickham1237df02017-02-24 08:59:36 -0800414 * @param canvas The canvas to draw to.
415 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800416 protected void drawDotIfNecessary(Canvas canvas) {
417 if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800418 getIconBounds(mDotParams.iconBounds);
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700419 Utilities.scaleRectAboutCenter(mDotParams.iconBounds,
420 IconShape.getNormalizationScale());
Tony Wickham1237df02017-02-24 08:59:36 -0800421 final int scrollX = getScrollX();
422 final int scrollY = getScrollY();
423 canvas.translate(scrollX, scrollY);
Tony Wickham8912b042018-11-29 15:28:53 -0800424 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham1237df02017-02-24 08:59:36 -0800425 canvas.translate(-scrollX, -scrollY);
426 }
427 }
428
Jon Miranda9b78e192019-08-30 18:42:01 -0700429 @Override
430 public void setForceHideDot(boolean forceHideDot) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800431 if (mForceHideDot == forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800432 return;
433 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800434 mForceHideDot = forceHideDot;
Tony Wickham1237df02017-02-24 08:59:36 -0800435
Tony Wickhamf34bee82018-12-03 18:11:39 -0800436 if (forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800437 invalidate();
Tony Wickhamf34bee82018-12-03 18:11:39 -0800438 } else if (hasDot()) {
439 animateDotScale(0, 1);
Tony Wickham1237df02017-02-24 08:59:36 -0800440 }
441 }
442
Tony Wickhamf34bee82018-12-03 18:11:39 -0800443 private boolean hasDot() {
444 return mDotInfo != null;
Tony Wickham1237df02017-02-24 08:59:36 -0800445 }
446
447 public void getIconBounds(Rect outBounds) {
Tony05d98c22018-07-23 08:01:15 -0700448 getIconBounds(this, outBounds, mIconSize);
449 }
450
451 public static void getIconBounds(View iconView, Rect outBounds, int iconSize) {
452 int top = iconView.getPaddingTop();
453 int left = (iconView.getWidth() - iconSize) / 2;
454 int right = left + iconSize;
455 int bottom = top + iconSize;
Tony Wickham1237df02017-02-24 08:59:36 -0800456 outBounds.set(left, top, right, bottom);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400458
459 @Override
Winson1f064272016-07-18 17:18:02 -0700460 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
461 if (mCenterVertically) {
462 Paint.FontMetrics fm = getPaint().getFontMetrics();
463 int cellHeightPx = mIconSize + getCompoundDrawablePadding() +
464 (int) Math.ceil(fm.bottom - fm.top);
465 int height = MeasureSpec.getSize(heightMeasureSpec);
466 setPadding(getPaddingLeft(), (height - cellHeightPx) / 2, getPaddingRight(),
467 getPaddingBottom());
468 }
469 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
470 }
471
472 @Override
Adam Cohen477828c2013-09-20 12:05:49 -0700473 public void setTextColor(int color) {
474 mTextColor = color;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700475 super.setTextColor(getModifiedColor());
Adam Cohen477828c2013-09-20 12:05:49 -0700476 }
477
Adam Cohen96bb7982014-07-07 11:58:56 -0700478 @Override
479 public void setTextColor(ColorStateList colors) {
480 mTextColor = colors.getDefaultColor();
Sunny Goyaled7a6932018-04-13 11:41:50 -0700481 if (Float.compare(mTextAlpha, 1) == 0) {
482 super.setTextColor(colors);
483 } else {
484 super.setTextColor(getModifiedColor());
485 }
Adam Cohen477828c2013-09-20 12:05:49 -0700486 }
487
Tony7308cde2017-06-27 22:38:33 -0700488 public boolean shouldTextBeVisible() {
489 // Text should be visible everywhere but the hotseat.
490 Object tag = getParent() instanceof FolderIcon ? ((View) getParent()).getTag() : getTag();
491 ItemInfo info = tag instanceof ItemInfo ? (ItemInfo) tag : null;
Samuel Fufaefb665d2019-10-30 13:24:14 -0700492 return info == null || (info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT
493 && info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION);
Tony7308cde2017-06-27 22:38:33 -0700494 }
495
Winson Chung5f8afe62013-08-12 16:19:28 -0700496 public void setTextVisibility(boolean visible) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700497 setTextAlpha(visible ? 1 : 0);
498 }
499
500 private void setTextAlpha(float alpha) {
501 mTextAlpha = alpha;
502 super.setTextColor(getModifiedColor());
503 }
504
505 private int getModifiedColor() {
506 if (mTextAlpha == 0) {
507 // Special case to prevent text shadows in high contrast mode
508 return Color.TRANSPARENT;
Winson Chung5f8afe62013-08-12 16:19:28 -0700509 }
Sunny Goyal066ace12018-11-05 11:08:31 -0800510 return setColorAlphaBound(mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
Tony8f402802017-06-16 17:24:54 -0700511 }
512
513 /**
514 * Creates an animator to fade the text in or out.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700515 *
Tony8f402802017-06-16 17:24:54 -0700516 * @param fadeIn Whether the text should fade in or fade out.
517 */
Sunny Goyal4e5a8782017-06-23 09:34:06 -0700518 public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700519 float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0;
Jon Miranda83cdca62019-04-15 13:01:05 -0700520 return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha);
Tony8f402802017-06-16 17:24:54 -0700521 }
522
Winson Chungaffd7b42010-08-20 15:11:56 -0700523 @Override
Winson Chung88f33452012-02-23 15:23:44 -0800524 public void cancelLongPress() {
525 super.cancelLongPress();
Winson Chung88f33452012-02-23 15:23:44 -0800526 mLongPressHelper.cancelLongPress();
527 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500528
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800529 public void applyPromiseState(boolean promiseStateChanged) {
Sunny Goyal95899162019-03-27 16:03:06 -0700530 if (getTag() instanceof WorkspaceItemInfo) {
531 WorkspaceItemInfo info = (WorkspaceItemInfo) getTag();
Mario Bertschler8ff9e1d2017-08-08 16:26:18 -0700532 final boolean isPromise = info.hasPromiseIconUi();
Sunny Goyal34942622014-08-29 17:20:55 -0700533 final int progressLevel = isPromise ?
Sunny Goyal95899162019-03-27 16:03:06 -0700534 ((info.hasStatusFlag(WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE) ?
Sunny Goyal34942622014-08-29 17:20:55 -0700535 info.getInstallProgress() : 0)) : 100;
Sunny Goyale755d462014-07-22 13:48:29 -0700536
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700537 PreloadIconDrawable preloadDrawable = applyProgressLevel(progressLevel);
538 if (preloadDrawable != null && promiseStateChanged) {
539 preloadDrawable.maybePerformFinishedAnimation();
540 }
541 }
542 }
543
544 public PreloadIconDrawable applyProgressLevel(int progressLevel) {
545 if (getTag() instanceof ItemInfoWithIcon) {
546 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Mario Bertschler230612f2017-09-27 17:05:21 -0700547 if (progressLevel >= 100) {
548 setContentDescription(info.contentDescription != null
549 ? info.contentDescription : "");
550 } else if (progressLevel > 0) {
551 setContentDescription(getContext()
552 .getString(R.string.app_downloading_title, info.title,
553 NumberFormat.getPercentInstance().format(progressLevel * 0.01)));
554 } else {
555 setContentDescription(getContext()
556 .getString(R.string.app_waiting_download_title, info.title));
557 }
Winson Chungb745afb2015-03-02 11:51:23 -0800558 if (mIcon != null) {
Sunny Goyale755d462014-07-22 13:48:29 -0700559 final PreloadIconDrawable preloadDrawable;
Winson Chungb745afb2015-03-02 11:51:23 -0800560 if (mIcon instanceof PreloadIconDrawable) {
561 preloadDrawable = (PreloadIconDrawable) mIcon;
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700562 preloadDrawable.setLevel(progressLevel);
Sunny Goyale755d462014-07-22 13:48:29 -0700563 } else {
Sunny Goyal14168432019-10-24 15:59:49 -0700564 preloadDrawable = newPendingIcon(getContext(), info);
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700565 preloadDrawable.setLevel(progressLevel);
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700566 setIcon(preloadDrawable);
Sunny Goyale755d462014-07-22 13:48:29 -0700567 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700568 return preloadDrawable;
Sunny Goyale755d462014-07-22 13:48:29 -0700569 }
Chris Wren40c5ed32014-06-24 18:24:23 -0400570 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700571 return null;
Chris Wren40c5ed32014-06-24 18:24:23 -0400572 }
Sunny Goyal95abbb32014-08-04 10:53:22 -0700573
Tony Wickhamf34bee82018-12-03 18:11:39 -0800574 public void applyDotState(ItemInfo itemInfo, boolean animate) {
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800575 if (mIcon instanceof FastBitmapDrawable) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800576 boolean wasDotted = mDotInfo != null;
577 mDotInfo = mActivity.getDotInfoForItem(itemInfo);
578 boolean isDotted = mDotInfo != null;
579 float newDotScale = isDotted ? 1f : 0;
Samuel Fufac96fa242019-09-26 23:06:32 -0700580 if (mDisplay == DISPLAY_ALL_APPS) {
581 mDotRenderer = mActivity.getDeviceProfile().mDotRendererAllApps;
582 } else {
583 mDotRenderer = mActivity.getDeviceProfile().mDotRendererWorkSpace;
584 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800585 if (wasDotted || isDotted) {
586 // Animate when a dot is first added or when it is removed.
587 if (animate && (wasDotted ^ isDotted) && isShown()) {
588 animateDotScale(newDotScale);
Tony Wickham1237df02017-02-24 08:59:36 -0800589 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800590 cancelDotScaleAnim();
591 mDotParams.scale = newDotScale;
Tony Wickham1237df02017-02-24 08:59:36 -0800592 invalidate();
593 }
594 }
Tony Wickham305e9202018-01-23 17:46:47 -0800595 if (itemInfo.contentDescription != null) {
vadimtda6dad52019-05-21 13:24:23 -0700596 if (itemInfo.isDisabled()) {
597 setContentDescription(getContext().getString(R.string.disabled_app_label,
598 itemInfo.contentDescription));
599 } else if (hasDot()) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800600 int count = mDotInfo.getNotificationCount();
Tony Wickham305e9202018-01-23 17:46:47 -0800601 setContentDescription(getContext().getResources().getQuantityString(
Tony Wickhamf34bee82018-12-03 18:11:39 -0800602 R.plurals.dotted_app_label, count, itemInfo.contentDescription, count));
Tony Wickham305e9202018-01-23 17:46:47 -0800603 } else {
604 setContentDescription(itemInfo.contentDescription);
605 }
606 }
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800607 }
608 }
609
Winson Chungb745afb2015-03-02 11:51:23 -0800610 /**
611 * Sets the icon for this view based on the layout direction.
612 */
Tony Wickham377ed3f2016-07-20 15:21:04 -0700613 private void setIcon(Drawable icon) {
Tony17b7f9b2017-05-23 12:19:09 -0700614 if (mIsIconVisible) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700615 applyCompoundDrawables(icon);
Tony17b7f9b2017-05-23 12:19:09 -0700616 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700617 mIcon = icon;
Hyunyoung Songa2373852019-01-04 12:01:32 -0800618 if (mIcon != null) {
619 mIcon.setVisible(getWindowVisibility() == VISIBLE && isShown(), false);
620 }
Tony17b7f9b2017-05-23 12:19:09 -0700621 }
622
Jon Miranda9b78e192019-08-30 18:42:01 -0700623 @Override
Tony17b7f9b2017-05-23 12:19:09 -0700624 public void setIconVisible(boolean visible) {
625 mIsIconVisible = visible;
Sunny Goyal30ac97d2020-06-24 23:47:46 -0700626 if (!mIsIconVisible) {
627 resetIconScale();
628 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700629 Drawable icon = visible ? mIcon : new ColorDrawable(Color.TRANSPARENT);
Tony17b7f9b2017-05-23 12:19:09 -0700630 applyCompoundDrawables(icon);
Tony Wickham377ed3f2016-07-20 15:21:04 -0700631 }
632
633 protected void applyCompoundDrawables(Drawable icon) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700634 // If we had already set an icon before, disable relayout as the icon size is the
635 // same as before.
636 mDisableRelayout = mIcon != null;
637
638 icon.setBounds(0, 0, mIconSize, mIconSize);
Winson Chungb745afb2015-03-02 11:51:23 -0800639 if (mLayoutHorizontal) {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800640 setCompoundDrawablesRelative(icon, null, null, null);
Winson Chungb745afb2015-03-02 11:51:23 -0800641 } else {
Tony Wickham377ed3f2016-07-20 15:21:04 -0700642 setCompoundDrawables(null, icon, null, null);
Winson Chungb745afb2015-03-02 11:51:23 -0800643 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700644 mDisableRelayout = false;
Winson Chungb745afb2015-03-02 11:51:23 -0800645 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700646
Sunny Goyal69b75642015-05-15 17:00:24 -0700647 @Override
648 public void requestLayout() {
649 if (!mDisableRelayout) {
650 super.requestLayout();
651 }
652 }
653
Sunny Goyal34b65272015-03-11 16:56:52 -0700654 /**
655 * Applies the item info if it is same as what the view is pointing to currently.
656 */
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800657 @Override
658 public void reapplyItemInfo(ItemInfoWithIcon info) {
Sunny Goyal34b65272015-03-11 16:56:52 -0700659 if (getTag() == info) {
660 mIconLoadRequest = null;
Sunny Goyal69b75642015-05-15 17:00:24 -0700661 mDisableRelayout = true;
Winsonc0880492015-08-21 11:16:27 -0700662
Jon Miranda7f522a22017-07-28 11:56:47 -0700663 // Optimization: Starting in N, pre-uploads the bitmap to RenderThread.
Sunny Goyal3808a692019-10-25 13:41:28 -0700664 info.bitmap.icon.prepareToDraw();
Jon Miranda7f522a22017-07-28 11:56:47 -0700665
Sunny Goyal34b65272015-03-11 16:56:52 -0700666 if (info instanceof AppInfo) {
667 applyFromApplicationInfo((AppInfo) info);
Sunny Goyal95899162019-03-27 16:03:06 -0700668 } else if (info instanceof WorkspaceItemInfo) {
669 applyFromWorkspaceItem((WorkspaceItemInfo) info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700670 mActivity.invalidateParent(info);
Sunny Goyal0e08f162015-05-12 11:32:39 -0700671 } else if (info instanceof PackageItemInfo) {
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700672 applyFromItemInfoWithIcon((PackageItemInfo) info);
Sunny Goyal34b65272015-03-11 16:56:52 -0700673 }
Winsonc0880492015-08-21 11:16:27 -0700674
Sunny Goyal69b75642015-05-15 17:00:24 -0700675 mDisableRelayout = false;
Sunny Goyal34b65272015-03-11 16:56:52 -0700676 }
677 }
678
679 /**
680 * Verifies that the current icon is high-res otherwise posts a request to load the icon.
681 */
682 public void verifyHighRes() {
683 if (mIconLoadRequest != null) {
684 mIconLoadRequest.cancel();
685 mIconLoadRequest = null;
686 }
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800687 if (getTag() instanceof ItemInfoWithIcon) {
688 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Sunny Goyal2b787e52018-08-20 15:01:03 -0700689 if (info.usingLowResIcon()) {
Sunny Goyal87f784c2017-01-11 10:48:34 -0800690 mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache()
Sunny Goyal0e08f162015-05-12 11:32:39 -0700691 .updateIconInBackground(BubbleTextView.this, info);
692 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700693 }
694 }
Sunny Goyal4b6eb262015-05-14 19:24:40 -0700695
Jon Miranda47170112017-03-03 14:57:14 -0800696 public int getIconSize() {
697 return mIconSize;
698 }
Adam Cohen65086992020-02-19 08:40:49 -0800699
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700700 private void updateTranslation() {
701 super.setTranslationX(mTranslationForReorderBounce.x + mTranslationForReorderPreview.x);
702 super.setTranslationY(mTranslationForReorderBounce.y + mTranslationForReorderPreview.y);
Adam Cohend9162062020-03-24 16:35:35 -0700703 }
704
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700705 public void setReorderBounceOffset(float x, float y) {
706 mTranslationForReorderBounce.set(x, y);
707 updateTranslation();
Adam Cohend9162062020-03-24 16:35:35 -0700708 }
709
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700710 public void getReorderBounceOffset(PointF offset) {
711 offset.set(mTranslationForReorderBounce);
712 }
713
714 @Override
715 public void setReorderPreviewOffset(float x, float y) {
716 mTranslationForReorderPreview.set(x, y);
717 updateTranslation();
718 }
719
720 @Override
721 public void getReorderPreviewOffset(PointF offset) {
722 offset.set(mTranslationForReorderPreview);
723 }
724
725 public void setReorderBounceScale(float scale) {
726 mScaleForReorderBounce = scale;
Adam Cohend9162062020-03-24 16:35:35 -0700727 super.setScaleX(scale);
728 super.setScaleY(scale);
729 }
730
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700731 public float getReorderBounceScale() {
732 return mScaleForReorderBounce;
Adam Cohend9162062020-03-24 16:35:35 -0700733 }
734
735 public View getView() {
736 return this;
737 }
738
Adam Cohen65086992020-02-19 08:40:49 -0800739 @Override
740 public int getViewType() {
741 return DRAGGABLE_ICON;
742 }
743
744 @Override
Adam Cohenc77bc452020-05-07 11:55:19 -0700745 public void getWorkspaceVisualDragBounds(Rect bounds) {
Adam Cohen65086992020-02-19 08:40:49 -0800746 DeviceProfile grid = mActivity.getDeviceProfile();
747 BubbleTextView.getIconBounds(this, bounds, grid.iconSizePx);
748 }
749
Adam Cohenc77bc452020-05-07 11:55:19 -0700750 private int getIconSizeForDisplay(int display) {
751 DeviceProfile grid = mActivity.getDeviceProfile();
752 switch (display) {
753 case DISPLAY_ALL_APPS:
754 return grid.allAppsIconSizePx;
755 case DISPLAY_WORKSPACE:
756 case DISPLAY_FOLDER:
757 default:
758 return grid.iconSizePx;
759 }
760 }
761
762 public void getSourceVisualDragBounds(Rect bounds) {
763 BubbleTextView.getIconBounds(this, bounds, getIconSizeForDisplay(mDisplay));
764 }
765
Adam Cohen65086992020-02-19 08:40:49 -0800766 @Override
Samuel Fufa167210a2020-05-12 18:40:11 -0700767 public SafeCloseable prepareDrawDragView() {
Sunny Goyal30ac97d2020-06-24 23:47:46 -0700768 resetIconScale();
Adam Cohen65086992020-02-19 08:40:49 -0800769 setForceHideDot(true);
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700770 return () -> {
771 };
Adam Cohen65086992020-02-19 08:40:49 -0800772 }
Sunny Goyal30ac97d2020-06-24 23:47:46 -0700773
774 private void resetIconScale() {
775 if (mIcon instanceof FastBitmapDrawable) {
776 ((FastBitmapDrawable) mIcon).setScale(1f);
777 }
778 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800779}