blob: b109e8ab1c77c55eec0690dd3e6335605b0263de [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
Federico Baron4eb502a2022-12-14 00:04:53 -080019import static com.android.launcher3.config.FeatureFlags.ENABLE_DOWNLOAD_APP_UX_V2;
Sunny Goyal0d69cb62021-10-04 15:31:38 -070020import static com.android.launcher3.config.FeatureFlags.ENABLE_ICON_LABEL_AUTO_SCALING;
Sunny Goyal14168432019-10-24 15:59:49 -070021import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
Sunny Goyald872a972021-11-24 18:07:04 -080022import static com.android.launcher3.icons.BitmapInfo.FLAG_NO_BADGE;
23import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED;
Sunny Goyal066ace12018-11-05 11:08:31 -080024import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;
Federico Baron4eb502a2022-12-14 00:04:53 -080025import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_INCREMENTAL_DOWNLOAD_ACTIVE;
26import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE;
Sunny Goyal066ace12018-11-05 11:08:31 -080027
Tony4043b052018-08-17 13:47:39 -070028import android.animation.Animator;
29import android.animation.AnimatorListenerAdapter;
Tony Wickham1237df02017-02-24 08:59:36 -080030import android.animation.ObjectAnimator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.content.Context;
Adam Cohen96bb7982014-07-07 11:58:56 -070032import android.content.res.ColorStateList;
Adam Cohen96bb7982014-07-07 11:58:56 -070033import android.content.res.TypedArray;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.graphics.Canvas;
Tony17b7f9b2017-05-23 12:19:09 -070035import android.graphics.Color;
Winson1f064272016-07-18 17:18:02 -070036import android.graphics.Paint;
Adam Cohend9162062020-03-24 16:35:35 -070037import android.graphics.PointF;
Tony Wickham1237df02017-02-24 08:59:36 -080038import android.graphics.Rect;
Tony17b7f9b2017-05-23 12:19:09 -070039import android.graphics.drawable.ColorDrawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.graphics.drawable.Drawable;
Steven Ng707b1182021-09-13 11:54:58 +010041import android.icu.text.MessageFormat;
Sunny Goyal0d69cb62021-10-04 15:31:38 -070042import android.text.TextPaint;
Andy Wickham56be73b2022-01-18 09:13:43 -080043import android.text.TextUtils;
Sunny Goyal66dccad2018-03-19 12:00:51 -070044import android.text.TextUtils.TruncateAt;
Winson Chung656d11c2010-11-29 17:15:47 -080045import android.util.AttributeSet;
Tony Wickham1237df02017-02-24 08:59:36 -080046import android.util.Property;
Winson Chung5f8afe62013-08-12 16:19:28 -070047import android.util.TypedValue;
Sunny Goyal508da152014-08-14 10:53:27 -070048import android.view.KeyEvent;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080049import android.view.MotionEvent;
Sunny Goyal317698b2015-07-29 11:45:41 -070050import android.view.View;
Sunny Goyal4ffec482016-02-09 11:28:52 -080051import android.view.ViewDebug;
Michael Jurkabdb5c532011-02-01 15:05:06 -080052import android.widget.TextView;
Sunny Goyal317698b2015-07-29 11:45:41 -070053
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +000054import androidx.annotation.Nullable;
Hyunyoung Song5809a402021-02-02 01:19:18 -080055import androidx.annotation.UiThread;
Schneider Victor-tulias350b4622020-09-18 11:16:30 -070056
Schneider Victor-tuliasbdb0dd82021-11-03 16:26:41 -070057import com.android.launcher3.accessibility.BaseAccessibilityDelegate;
Tony Wickhamf34bee82018-12-03 18:11:39 -080058import com.android.launcher3.dot.DotInfo;
Sunny Goyalf0ff70a2022-05-11 07:23:10 -070059import com.android.launcher3.dragndrop.DragOptions.PreDragCondition;
Adam Cohen65086992020-02-19 08:40:49 -080060import com.android.launcher3.dragndrop.DraggableView;
Tony7308cde2017-06-27 22:38:33 -070061import com.android.launcher3.folder.FolderIcon;
Tony Wickhame1cb93f2019-05-03 11:27:32 -070062import com.android.launcher3.graphics.IconShape;
Sunny Goyal96ac68a2017-02-02 16:37:21 -080063import com.android.launcher3.graphics.PreloadIconDrawable;
Tony Wickham8912b042018-11-29 15:28:53 -080064import com.android.launcher3.icons.DotRenderer;
Sunny Goyal572aca42021-03-24 15:21:39 -070065import com.android.launcher3.icons.FastBitmapDrawable;
Sunny Goyalfe8e4a92018-11-13 19:43:57 -080066import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
Sunny Goyal572aca42021-03-24 15:21:39 -070067import com.android.launcher3.icons.PlaceHolderIconDrawable;
Sunny Goyal79e52fc2021-02-03 10:22:28 -080068import com.android.launcher3.icons.cache.HandlerRunnable;
Sunny Goyale396abf2020-04-06 15:11:17 -070069import com.android.launcher3.model.data.AppInfo;
70import com.android.launcher3.model.data.ItemInfo;
71import com.android.launcher3.model.data.ItemInfoWithIcon;
Sunny Goyale396abf2020-04-06 15:11:17 -070072import com.android.launcher3.model.data.WorkspaceItemInfo;
Sunny Goyalf0ff70a2022-05-11 07:23:10 -070073import com.android.launcher3.popup.PopupContainerWithArrow;
Samuel Fufa167210a2020-05-12 18:40:11 -070074import com.android.launcher3.util.SafeCloseable;
Sunny Goyalf0ff70a2022-05-11 07:23:10 -070075import com.android.launcher3.util.ShortcutUtil;
Sunny Goyalfe8e4a92018-11-13 19:43:57 -080076import com.android.launcher3.views.ActivityContext;
Jon Miranda9b78e192019-08-30 18:42:01 -070077import com.android.launcher3.views.IconLabelDotView;
Sunny Goyal34b65272015-03-11 16:56:52 -070078
Sunny Goyalc469aad2015-10-01 11:24:23 -070079import java.text.NumberFormat;
Steven Ng707b1182021-09-13 11:54:58 +010080import java.util.HashMap;
81import java.util.Locale;
Sunny Goyalc469aad2015-10-01 11:24:23 -070082
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083/**
84 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
85 * because we want to make the bubble taller than the text and TextView's clip is
86 * too aggressive.
87 */
Sunny Goyalb65d7662021-03-07 15:09:11 -080088public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
Hyunyoung Songdb9a53d2021-02-17 00:35:10 -080089 IconLabelDotView, DraggableView, Reorderable {
Sunny Goyal95abbb32014-08-04 10:53:22 -070090
Sunny Goyaldfaccf62015-05-11 16:30:44 -070091 private static final int DISPLAY_WORKSPACE = 0;
92 private static final int DISPLAY_ALL_APPS = 1;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -070093 private static final int DISPLAY_FOLDER = 2;
Hyunyoung Songe3d32b52021-06-03 21:20:18 -070094 protected static final int DISPLAY_TASKBAR = 5;
95 private static final int DISPLAY_SEARCH_RESULT = 6;
96 private static final int DISPLAY_SEARCH_RESULT_SMALL = 7;
Sunny Goyaldfaccf62015-05-11 16:30:44 -070097
Sunny Goyal486adb02021-10-21 11:29:52 -070098 private static final float MIN_LETTER_SPACING = -0.05f;
Sunny Goyal0d69cb62021-10-04 15:31:38 -070099 private static final int MAX_SEARCH_LOOP_COUNT = 20;
100
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700101 private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed};
Samuel Fufa314761a2020-10-14 10:15:07 -0700102
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700103 private final PointF mTranslationForReorderBounce = new PointF(0, 0);
104 private final PointF mTranslationForReorderPreview = new PointF(0, 0);
105
Nick Chameyev4dd41592021-08-27 14:11:53 +0100106 private float mTranslationXForTaskbarAlignmentAnimation = 0f;
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800107 private float mTranslationYForTaskbarAlignmentAnimation = 0f;
108
109 private float mTranslationXForTaskbarRevealAnimation = 0f;
110 private float mTranslationYForTaskbarRevealAnimation = 0f;
Nick Chameyev4dd41592021-08-27 14:11:53 +0100111
Nick Chameyev5e8dbe72021-07-26 14:56:50 +0100112 private final PointF mTranslationForMoveFromCenterAnimation = new PointF(0, 0);
113
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700114 private float mScaleForReorderBounce = 1f;
Tony Wickham1237df02017-02-24 08:59:36 -0800115
Tony Wickhamf34bee82018-12-03 18:11:39 -0800116 private static final Property<BubbleTextView, Float> DOT_SCALE_PROPERTY
117 = new Property<BubbleTextView, Float>(Float.TYPE, "dotScale") {
Tony Wickham1237df02017-02-24 08:59:36 -0800118 @Override
119 public Float get(BubbleTextView bubbleTextView) {
Tony Wickham8912b042018-11-29 15:28:53 -0800120 return bubbleTextView.mDotParams.scale;
Tony Wickham1237df02017-02-24 08:59:36 -0800121 }
122
123 @Override
124 public void set(BubbleTextView bubbleTextView, Float value) {
Tony Wickham8912b042018-11-29 15:28:53 -0800125 bubbleTextView.mDotParams.scale = value;
Tony Wickham1237df02017-02-24 08:59:36 -0800126 bubbleTextView.invalidate();
127 }
128 };
129
Sunny Goyaled7a6932018-04-13 11:41:50 -0700130 public static final Property<BubbleTextView, Float> TEXT_ALPHA_PROPERTY
131 = new Property<BubbleTextView, Float>(Float.class, "textAlpha") {
Tony8f402802017-06-16 17:24:54 -0700132 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700133 public Float get(BubbleTextView bubbleTextView) {
134 return bubbleTextView.mTextAlpha;
Tony8f402802017-06-16 17:24:54 -0700135 }
136
137 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700138 public void set(BubbleTextView bubbleTextView, Float alpha) {
Tony8f402802017-06-16 17:24:54 -0700139 bubbleTextView.setTextAlpha(alpha);
140 }
141 };
142
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800143 private final ActivityContext mActivity;
Sunny Goyalc4c32692021-05-21 14:23:29 -0700144 private FastBitmapDrawable mIcon;
Adam Cohen65086992020-02-19 08:40:49 -0800145 private boolean mCenterVertically;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700146
Tony Wickham794fe4f2021-01-11 14:54:23 -0600147 protected final int mDisplay;
Samuel Fufac96fa242019-09-26 23:06:32 -0700148
Sunny Goyaled7a6932018-04-13 11:41:50 -0700149 private final CheckLongPressHelper mLongPressHelper;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700150
151 private final boolean mLayoutHorizontal;
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700152 private final boolean mIsRtl;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700153 private final int mIconSize;
154
155 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyald872a972021-11-24 18:07:04 -0800156 private boolean mHideBadge = false;
157 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyaled7a6932018-04-13 11:41:50 -0700158 private boolean mIsIconVisible = true;
159 @ViewDebug.ExportedProperty(category = "launcher")
160 private int mTextColor;
161 @ViewDebug.ExportedProperty(category = "launcher")
Jon Spivack68862142021-10-28 18:37:19 -0700162 private ColorStateList mTextColorStateList;
163 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyaled7a6932018-04-13 11:41:50 -0700164 private float mTextAlpha = 1;
165
Tony4043b052018-08-17 13:47:39 -0700166 @ViewDebug.ExportedProperty(category = "launcher")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800167 private DotInfo mDotInfo;
Tony Wickham8912b042018-11-29 15:28:53 -0800168 private DotRenderer mDotRenderer;
169 @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
Sunny Goyal67555872021-05-21 12:56:55 -0700170 protected DotRenderer.DrawParams mDotParams;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800171 private Animator mDotScaleAnim;
172 private boolean mForceHideDot;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700173
Sunny Goyal4ffec482016-02-09 11:28:52 -0800174 @ViewDebug.ExportedProperty(category = "launcher")
Michael Jurkaddd62e92011-02-16 17:49:14 -0800175 private boolean mStayPressed;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800176 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal508da152014-08-14 10:53:27 -0700177 private boolean mIgnorePressedStateChange;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800178 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal69b75642015-05-15 17:00:24 -0700179 private boolean mDisableRelayout = false;
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500180
Sunny Goyal79e52fc2021-02-03 10:22:28 -0800181 private HandlerRunnable mIconLoadRequest;
Sunny Goyal34b65272015-03-11 16:56:52 -0700182
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400183 private boolean mEnableIconUpdateAnimation = false;
184
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 public BubbleTextView(Context context) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700186 this(context, null, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 }
188
189 public BubbleTextView(Context context, AttributeSet attrs) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700190 this(context, attrs, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 }
192
193 public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
194 super(context, attrs, defStyle);
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800195 mActivity = ActivityContext.lookupContext(context);
Adam Cohen96bb7982014-07-07 11:58:56 -0700196
Adam Cohen96bb7982014-07-07 11:58:56 -0700197 TypedArray a = context.obtainStyledAttributes(attrs,
198 R.styleable.BubbleTextView, defStyle, 0);
Winson Chungb745afb2015-03-02 11:51:23 -0800199 mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700200 mIsRtl = (getResources().getConfiguration().getLayoutDirection()
201 == View.LAYOUT_DIRECTION_RTL);
Sunny Goyalc4d32012020-04-03 17:10:11 -0700202 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700203
Samuel Fufac96fa242019-09-26 23:06:32 -0700204 mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700205 final int defaultIconSize;
Samuel Fufac96fa242019-09-26 23:06:32 -0700206 if (mDisplay == DISPLAY_WORKSPACE) {
Winson Chung44d0aac2015-05-11 18:02:55 -0700207 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
Jon Miranda09660722017-06-14 14:20:14 -0700208 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700209 defaultIconSize = grid.iconSizePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500210 setCenterVertically(grid.isScalableGrid);
Samuel Fufac96fa242019-09-26 23:06:32 -0700211 } else if (mDisplay == DISPLAY_ALL_APPS) {
Winson1f064272016-07-18 17:18:02 -0700212 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
213 setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700214 defaultIconSize = grid.allAppsIconSizePx;
Samuel Fufac96fa242019-09-26 23:06:32 -0700215 } else if (mDisplay == DISPLAY_FOLDER) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700216 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700217 setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700218 defaultIconSize = grid.folderChildIconSizePx;
Hyunyoung Songe3d32b52021-06-03 21:20:18 -0700219 } else if (mDisplay == DISPLAY_SEARCH_RESULT) {
220 defaultIconSize = getResources().getDimensionPixelSize(R.dimen.search_row_icon_size);
221 } else if (mDisplay == DISPLAY_SEARCH_RESULT_SMALL) {
222 defaultIconSize = getResources().getDimensionPixelSize(
223 R.dimen.search_row_small_icon_size);
Tony Wickham794fe4f2021-01-11 14:54:23 -0600224 } else if (mDisplay == DISPLAY_TASKBAR) {
225 defaultIconSize = grid.iconSizePx;
Sunny Goyalae6e3182019-04-30 12:04:37 -0700226 } else {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700227 // widget_selection or shortcut_popup
Sunny Goyalc4d32012020-04-03 17:10:11 -0700228 defaultIconSize = grid.iconSizePx;
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700229 }
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700230
Winson1f064272016-07-18 17:18:02 -0700231 mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700232
233 mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
234 defaultIconSize);
Adam Cohen96bb7982014-07-07 11:58:56 -0700235 a.recycle();
236
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800237 mLongPressHelper = new CheckLongPressHelper(this);
238
Tony Wickham8912b042018-11-29 15:28:53 -0800239 mDotParams = new DotRenderer.DrawParams();
240
Sunny Goyal66dccad2018-03-19 12:00:51 -0700241 setEllipsize(TruncateAt.END);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700242 setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
Sunny Goyaled7a6932018-04-13 11:41:50 -0700243 setTextAlpha(1f);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 }
245
Sunny Goyal66dccad2018-03-19 12:00:51 -0700246 @Override
247 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
248 // Disable marques when not focused to that, so that updating text does not cause relayout.
249 setEllipsize(focused ? TruncateAt.MARQUEE : TruncateAt.END);
250 super.onFocusChanged(focused, direction, previouslyFocusedRect);
251 }
252
Sunny Goyald872a972021-11-24 18:07:04 -0800253 public void setHideBadge(boolean hideBadge) {
254 mHideBadge = hideBadge;
255 }
256
Jon Miranda52549442017-10-26 11:28:06 -0700257 /**
258 * Resets the view so it can be recycled.
259 */
260 public void reset() {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800261 mDotInfo = null;
James O'Leary1557ba32022-05-04 16:49:03 +0000262 mDotParams.dotColor = Color.TRANSPARENT;
263 mDotParams.appColor = Color.TRANSPARENT;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800264 cancelDotScaleAnim();
Tony Wickham8912b042018-11-29 15:28:53 -0800265 mDotParams.scale = 0f;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800266 mForceHideDot = false;
Samuel Fufaba6b47f2019-11-07 10:27:41 -0800267 setBackground(null);
Sunny Goyal52f4c162022-04-23 16:02:03 +0000268
269 setTag(null);
270 if (mIconLoadRequest != null) {
271 mIconLoadRequest.cancel();
272 mIconLoadRequest = null;
273 }
Jon Miranda52549442017-10-26 11:28:06 -0700274 }
275
Tony Wickhamf34bee82018-12-03 18:11:39 -0800276 private void cancelDotScaleAnim() {
277 if (mDotScaleAnim != null) {
278 mDotScaleAnim.cancel();
Tony4043b052018-08-17 13:47:39 -0700279 }
280 }
281
Tony Wickhamf34bee82018-12-03 18:11:39 -0800282 private void animateDotScale(float... dotScales) {
283 cancelDotScaleAnim();
284 mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales);
285 mDotScaleAnim.addListener(new AnimatorListenerAdapter() {
Tony4043b052018-08-17 13:47:39 -0700286 @Override
287 public void onAnimationEnd(Animator animation) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800288 mDotScaleAnim = null;
Tony4043b052018-08-17 13:47:39 -0700289 }
290 });
Tony Wickhamf34bee82018-12-03 18:11:39 -0800291 mDotScaleAnim.start();
Tony4043b052018-08-17 13:47:39 -0700292 }
293
Hyunyoung Song5809a402021-02-02 01:19:18 -0800294 @UiThread
Sunny Goyal95899162019-03-27 16:03:06 -0700295 public void applyFromWorkspaceItem(WorkspaceItemInfo info) {
Tony Wickham175d1522021-08-25 09:18:41 -0700296 applyFromWorkspaceItem(info, /* animate = */ false, /* staggerIndex = */ 0);
297 }
298
299 @UiThread
300 public void applyFromWorkspaceItem(WorkspaceItemInfo info, boolean animate, int staggerIndex) {
Federico Baron4eb502a2022-12-14 00:04:53 -0800301 applyFromWorkspaceItem(info, null);
Winson Chung5f8afe62013-08-12 16:19:28 -0700302 }
303
Tony Wickham175d1522021-08-25 09:18:41 -0700304 /**
305 * Returns whether the newInfo differs from the current getTag().
306 */
307 public boolean shouldAnimateIconChange(WorkspaceItemInfo newInfo) {
308 WorkspaceItemInfo oldInfo = getTag() instanceof WorkspaceItemInfo
309 ? (WorkspaceItemInfo) getTag()
310 : null;
311 boolean changedIcons = oldInfo != null && oldInfo.getTargetComponent() != null
312 && newInfo.getTargetComponent() != null
313 && !oldInfo.getTargetComponent().equals(newInfo.getTargetComponent());
314 return changedIcons && isShown();
315 }
316
Adam Cohen29794c52019-06-21 12:50:30 -0700317 @Override
318 public void setAccessibilityDelegate(AccessibilityDelegate delegate) {
Schneider Victor-tuliasbdb0dd82021-11-03 16:26:41 -0700319 if (delegate instanceof BaseAccessibilityDelegate) {
Adam Cohen29794c52019-06-21 12:50:30 -0700320 super.setAccessibilityDelegate(delegate);
321 } else {
322 // NO-OP
323 // Workaround for b/129745295 where RecyclerView is setting our Accessibility
324 // delegate incorrectly. There are no cases when we shouldn't be using the
325 // LauncherAccessibilityDelegate for BubbleTextView.
326 }
327 }
328
Hyunyoung Song5809a402021-02-02 01:19:18 -0800329 @UiThread
Federico Baron4eb502a2022-12-14 00:04:53 -0800330 public void applyFromWorkspaceItem(WorkspaceItemInfo info, PreloadIconDrawable icon) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800331 applyIconAndLabel(info);
sfufa@google.comca76de02021-09-24 08:55:48 -0700332 setItemInfo(info);
Federico Baron4eb502a2022-12-14 00:04:53 -0800333 applyLoadingState(icon);
Tony Wickhamf34bee82018-12-03 18:11:39 -0800334 applyDotState(info, false /* animate */);
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800335 setDownloadStateContentDescription(info, info.getProgressLevel());
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800336 }
337
Hyunyoung Song5809a402021-02-02 01:19:18 -0800338 @UiThread
Sunny Goyal508da152014-08-14 10:53:27 -0700339 public void applyFromApplicationInfo(AppInfo info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800340 applyIconAndLabel(info);
Sunny Goyalf4204382016-07-13 10:46:07 -0700341
Sunny Goyal95899162019-03-27 16:03:06 -0700342 // We don't need to check the info since it's not a WorkspaceItemInfo
sfufa@google.comca76de02021-09-24 08:55:48 -0700343 setItemInfo(info);
344
Sunny Goyal34b65272015-03-11 16:56:52 -0700345
346 // Verify high res immediately
347 verifyHighRes();
Tony Wickham010d2552017-01-20 08:15:28 -0800348
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000349 if ((info.runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800350 applyProgressLevel();
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700351 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800352 applyDotState(info, false /* animate */);
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800353 setDownloadStateContentDescription(info, info.getProgressLevel());
Sunny Goyal508da152014-08-14 10:53:27 -0700354 }
355
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700356 /**
357 * Apply label and tag using a generic {@link ItemInfoWithIcon}
358 */
Hyunyoung Song5809a402021-02-02 01:19:18 -0800359 @UiThread
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700360 public void applyFromItemInfoWithIcon(ItemInfoWithIcon info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800361 applyIconAndLabel(info);
Sunny Goyal95899162019-03-27 16:03:06 -0700362 // We don't need to check the info since it's not a WorkspaceItemInfo
sfufa@google.comca76de02021-09-24 08:55:48 -0700363 setItemInfo(info);
Sunny Goyal0e08f162015-05-12 11:32:39 -0700364
365 // Verify high res immediately
366 verifyHighRes();
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800367
368 setDownloadStateContentDescription(info, info.getProgressLevel());
Sunny Goyal0e08f162015-05-12 11:32:39 -0700369 }
370
Sunny Goyalf0ff70a2022-05-11 07:23:10 -0700371 protected void setItemInfo(ItemInfoWithIcon itemInfo) {
sfufa@google.comca76de02021-09-24 08:55:48 -0700372 setTag(itemInfo);
sfufa@google.com0fe464d2021-10-14 14:34:50 -0700373 }
374
Hyunyoung Song5809a402021-02-02 01:19:18 -0800375 @UiThread
Samuel Fufac2820182021-01-22 11:47:25 -0600376 protected void applyIconAndLabel(ItemInfoWithIcon info) {
Sunny Goyal59f19152021-08-03 12:25:02 -0700377 boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER
378 || mDisplay == DISPLAY_TASKBAR;
Sunny Goyald872a972021-11-24 18:07:04 -0800379 int flags = useTheme ? FLAG_THEMED : 0;
380 if (mHideBadge) {
381 flags |= FLAG_NO_BADGE;
382 }
383 FastBitmapDrawable iconDrawable = info.newIcon(getContext(), flags);
James O'Leary1557ba32022-05-04 16:49:03 +0000384 mDotParams.appColor = iconDrawable.getIconColor();
385 mDotParams.dotColor = getContext().getResources()
James O'Learyede514f2022-06-06 16:01:45 -0400386 .getColor(android.R.color.system_accent3_200, getContext().getTheme());
Sunny Goyalf4204382016-07-13 10:46:07 -0700387 setIcon(iconDrawable);
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000388 applyLabel(info);
389 }
390
Hyunyoung Song5809a402021-02-02 01:19:18 -0800391 @UiThread
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000392 private void applyLabel(ItemInfoWithIcon info) {
Sunny Goyalf4204382016-07-13 10:46:07 -0700393 setText(info.title);
394 if (info.contentDescription != null) {
395 setContentDescription(info.isDisabled()
396 ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
397 : info.contentDescription);
398 }
399 }
400
Winson Chung7501adf2015-06-02 11:24:28 -0700401 /**
402 * Overrides the default long press timeout.
403 */
Tony2ca999c2018-09-24 17:24:51 -0400404 public void setLongPressTimeoutFactor(float longPressTimeoutFactor) {
405 mLongPressHelper.setLongPressTimeoutFactor(longPressTimeoutFactor);
Winson Chung7501adf2015-06-02 11:24:28 -0700406 }
Sunny Goyal0e08f162015-05-12 11:32:39 -0700407
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 @Override
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800409 public void refreshDrawableState() {
Sunny Goyal508da152014-08-14 10:53:27 -0700410 if (!mIgnorePressedStateChange) {
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800411 super.refreshDrawableState();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800412 }
Sunny Goyal508da152014-08-14 10:53:27 -0700413 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800414
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800415 @Override
416 protected int[] onCreateDrawableState(int extraSpace) {
417 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
418 if (mStayPressed) {
419 mergeDrawableStates(drawableState, STATE_PRESSED);
420 }
421 return drawableState;
422 }
423
Winson Chungb745afb2015-03-02 11:51:23 -0800424 /** Returns the icon for this view. */
Sunny Goyalc4c32692021-05-21 14:23:29 -0700425 public FastBitmapDrawable getIcon() {
Winson Chungb745afb2015-03-02 11:51:23 -0800426 return mIcon;
427 }
428
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700429 @Override
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800430 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700431 // ignore events if they happen in padding area
Sunny Goyal17feee82020-03-24 13:55:15 -0700432 if (event.getAction() == MotionEvent.ACTION_DOWN
Sunny Goyal44a3b202020-07-09 08:27:06 -0700433 && shouldIgnoreTouchDown(event.getX(), event.getY())) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700434 return false;
435 }
Sunny Goyal17feee82020-03-24 13:55:15 -0700436 if (isLongClickable()) {
437 super.onTouchEvent(event);
438 mLongPressHelper.onTouchEvent(event);
439 // Keep receiving the rest of the events
440 return true;
441 } else {
442 return super.onTouchEvent(event);
Mady Melloref044dd2015-06-02 15:35:07 -0700443 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800444 }
445
Sunny Goyal44a3b202020-07-09 08:27:06 -0700446 /**
447 * Returns true if the touch down at the provided position be ignored
448 */
449 protected boolean shouldIgnoreTouchDown(float x, float y) {
Tony Wickham42b03952021-08-31 10:41:36 -0700450 if (mDisplay == DISPLAY_TASKBAR) {
451 // Allow touching within padding on taskbar, given icon sizes are smaller.
452 return false;
453 }
Sunny Goyal44a3b202020-07-09 08:27:06 -0700454 return y < getPaddingTop()
455 || x < getPaddingLeft()
456 || y > getHeight() - getPaddingBottom()
457 || x > getWidth() - getPaddingRight();
458 }
459
Michael Jurkaddd62e92011-02-16 17:49:14 -0800460 void setStayPressed(boolean stayPressed) {
461 mStayPressed = stayPressed;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800462 refreshDrawableState();
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800463 }
464
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700465 @Override
Hyunyoung Songef468d82019-01-03 01:02:43 -0800466 public void onVisibilityAggregated(boolean isVisible) {
467 super.onVisibilityAggregated(isVisible);
468 if (mIcon != null) {
Hyunyoung Songa2373852019-01-04 12:01:32 -0800469 mIcon.setVisible(isVisible, false);
Hyunyoung Songef468d82019-01-03 01:02:43 -0800470 }
471 }
472
Tony Wickham8ac277e2021-05-24 15:47:38 -0700473 public void clearPressedBackground() {
Sunny Goyal508da152014-08-14 10:53:27 -0700474 setPressed(false);
475 setStayPressed(false);
476 }
477
478 @Override
Sunny Goyal508da152014-08-14 10:53:27 -0700479 public boolean onKeyUp(int keyCode, KeyEvent event) {
480 // Unlike touch events, keypress event propagate pressed state change immediately,
481 // without waiting for onClickHandler to execute. Disable pressed state changes here
482 // to avoid flickering.
483 mIgnorePressedStateChange = true;
484 boolean result = super.onKeyUp(keyCode, event);
Sunny Goyal508da152014-08-14 10:53:27 -0700485 mIgnorePressedStateChange = false;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800486 refreshDrawableState();
Sunny Goyal508da152014-08-14 10:53:27 -0700487 return result;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800488 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800489
Sunny Goyal0d69cb62021-10-04 15:31:38 -0700490 @Override
491 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
492 super.onSizeChanged(w, h, oldw, oldh);
493 checkForEllipsis();
494 }
495
496 @Override
497 protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
498 super.onTextChanged(text, start, lengthBefore, lengthAfter);
499 checkForEllipsis();
500 }
501
502 private void checkForEllipsis() {
503 if (!ENABLE_ICON_LABEL_AUTO_SCALING.get()) {
504 return;
505 }
506 float width = getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight();
507 if (width <= 0) {
508 return;
509 }
510 setLetterSpacing(0);
511
512 String text = getText().toString();
513 TextPaint paint = getPaint();
514 if (paint.measureText(text) < width) {
515 return;
516 }
517
518 float spacing = findBestSpacingValue(paint, text, width, MIN_LETTER_SPACING);
519 // Reset the paint value so that the call to TextView does appropriate diff.
520 paint.setLetterSpacing(0);
521 setLetterSpacing(spacing);
522 }
523
524 /**
525 * Find the appropriate text spacing to display the provided text
526 * @param paint the paint used by the text view
527 * @param text the text to display
528 * @param allowedWidthPx available space to render the text
529 * @param minSpacingEm minimum spacing allowed between characters
530 * @return the final textSpacing value
531 *
532 * @see #setLetterSpacing(float)
533 */
534 private float findBestSpacingValue(TextPaint paint, String text, float allowedWidthPx,
535 float minSpacingEm) {
536 paint.setLetterSpacing(minSpacingEm);
537 if (paint.measureText(text) > allowedWidthPx) {
538 // If there is no result at high limit, we can do anything more
539 return minSpacingEm;
540 }
541
542 float lowLimit = 0;
543 float highLimit = minSpacingEm;
544
545 for (int i = 0; i < MAX_SEARCH_LOOP_COUNT; i++) {
546 float value = (lowLimit + highLimit) / 2;
547 paint.setLetterSpacing(value);
548 if (paint.measureText(text) < allowedWidthPx) {
549 highLimit = value;
550 } else {
551 lowLimit = value;
552 }
553 }
554
555 // At the end error on the higher side
556 return highLimit;
557 }
558
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700559 @SuppressWarnings("wrongcall")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800560 protected void drawWithoutDot(Canvas canvas) {
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700561 super.onDraw(canvas);
562 }
563
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 @Override
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700565 public void onDraw(Canvas canvas) {
566 super.onDraw(canvas);
Tony Wickham22a5a682020-11-02 17:04:58 -0800567 drawDotIfNecessary(canvas);
Samuel Fufa314761a2020-10-14 10:15:07 -0700568 }
569
Tony Wickham1237df02017-02-24 08:59:36 -0800570 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800571 * Draws the notification dot in the top right corner of the icon bounds.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700572 *
Tony Wickham1237df02017-02-24 08:59:36 -0800573 * @param canvas The canvas to draw to.
574 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800575 protected void drawDotIfNecessary(Canvas canvas) {
576 if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800577 getIconBounds(mDotParams.iconBounds);
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700578 Utilities.scaleRectAboutCenter(mDotParams.iconBounds,
579 IconShape.getNormalizationScale());
Tony Wickham1237df02017-02-24 08:59:36 -0800580 final int scrollX = getScrollX();
581 final int scrollY = getScrollY();
582 canvas.translate(scrollX, scrollY);
Tony Wickham8912b042018-11-29 15:28:53 -0800583 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham1237df02017-02-24 08:59:36 -0800584 canvas.translate(-scrollX, -scrollY);
585 }
586 }
587
Jon Miranda9b78e192019-08-30 18:42:01 -0700588 @Override
589 public void setForceHideDot(boolean forceHideDot) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800590 if (mForceHideDot == forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800591 return;
592 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800593 mForceHideDot = forceHideDot;
Tony Wickham1237df02017-02-24 08:59:36 -0800594
Tony Wickhamf34bee82018-12-03 18:11:39 -0800595 if (forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800596 invalidate();
Tony Wickhamf34bee82018-12-03 18:11:39 -0800597 } else if (hasDot()) {
598 animateDotScale(0, 1);
Tony Wickham1237df02017-02-24 08:59:36 -0800599 }
600 }
601
Tony Wickhamf34bee82018-12-03 18:11:39 -0800602 private boolean hasDot() {
603 return mDotInfo != null;
Tony Wickham1237df02017-02-24 08:59:36 -0800604 }
605
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700606 /**
607 * Get the icon bounds on the view depending on the layout type.
608 */
Tony Wickham1237df02017-02-24 08:59:36 -0800609 public void getIconBounds(Rect outBounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700610 getIconBounds(mIconSize, outBounds);
Tony05d98c22018-07-23 08:01:15 -0700611 }
612
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700613 /**
614 * Get the icon bounds on the view depending on the layout type.
615 */
616 public void getIconBounds(int iconSize, Rect outBounds) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700617 outBounds.set(0, 0, iconSize, iconSize);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700618 if (mLayoutHorizontal) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700619 int top = (getHeight() - iconSize) / 2;
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700620 if (mIsRtl) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700621 outBounds.offsetTo(getWidth() - iconSize - getPaddingRight(), top);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700622 } else {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700623 outBounds.offsetTo(getPaddingLeft(), top);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700624 }
625 } else {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700626 outBounds.offset((getWidth() - iconSize) / 2, getPaddingTop());
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700627 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800628 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400629
Jon Miranda228877d2021-02-09 11:05:00 -0500630 /**
631 * Sets whether to vertically center the content.
632 */
633 public void setCenterVertically(boolean centerVertically) {
634 mCenterVertically = centerVertically;
635 }
636
Joe Onorato9c1289c2009-08-17 11:03:03 -0400637 @Override
Winson1f064272016-07-18 17:18:02 -0700638 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
639 if (mCenterVertically) {
640 Paint.FontMetrics fm = getPaint().getFontMetrics();
641 int cellHeightPx = mIconSize + getCompoundDrawablePadding() +
642 (int) Math.ceil(fm.bottom - fm.top);
643 int height = MeasureSpec.getSize(heightMeasureSpec);
644 setPadding(getPaddingLeft(), (height - cellHeightPx) / 2, getPaddingRight(),
645 getPaddingBottom());
646 }
647 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
648 }
649
650 @Override
Adam Cohen477828c2013-09-20 12:05:49 -0700651 public void setTextColor(int color) {
652 mTextColor = color;
Jon Spivack68862142021-10-28 18:37:19 -0700653 mTextColorStateList = null;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700654 super.setTextColor(getModifiedColor());
Adam Cohen477828c2013-09-20 12:05:49 -0700655 }
656
Adam Cohen96bb7982014-07-07 11:58:56 -0700657 @Override
658 public void setTextColor(ColorStateList colors) {
659 mTextColor = colors.getDefaultColor();
Jon Spivack68862142021-10-28 18:37:19 -0700660 mTextColorStateList = colors;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700661 if (Float.compare(mTextAlpha, 1) == 0) {
662 super.setTextColor(colors);
663 } else {
664 super.setTextColor(getModifiedColor());
665 }
Adam Cohen477828c2013-09-20 12:05:49 -0700666 }
667
Tony7308cde2017-06-27 22:38:33 -0700668 public boolean shouldTextBeVisible() {
669 // Text should be visible everywhere but the hotseat.
670 Object tag = getParent() instanceof FolderIcon ? ((View) getParent()).getTag() : getTag();
671 ItemInfo info = tag instanceof ItemInfo ? (ItemInfo) tag : null;
Samuel Fufaefb665d2019-10-30 13:24:14 -0700672 return info == null || (info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT
673 && info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION);
Tony7308cde2017-06-27 22:38:33 -0700674 }
675
Winson Chung5f8afe62013-08-12 16:19:28 -0700676 public void setTextVisibility(boolean visible) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700677 setTextAlpha(visible ? 1 : 0);
678 }
679
680 private void setTextAlpha(float alpha) {
681 mTextAlpha = alpha;
Jon Spivack68862142021-10-28 18:37:19 -0700682 if (mTextColorStateList != null) {
683 setTextColor(mTextColorStateList);
684 } else {
685 super.setTextColor(getModifiedColor());
686 }
Sunny Goyaled7a6932018-04-13 11:41:50 -0700687 }
688
689 private int getModifiedColor() {
690 if (mTextAlpha == 0) {
691 // Special case to prevent text shadows in high contrast mode
692 return Color.TRANSPARENT;
Winson Chung5f8afe62013-08-12 16:19:28 -0700693 }
Sunny Goyal066ace12018-11-05 11:08:31 -0800694 return setColorAlphaBound(mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
Tony8f402802017-06-16 17:24:54 -0700695 }
696
697 /**
698 * Creates an animator to fade the text in or out.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700699 *
Tony8f402802017-06-16 17:24:54 -0700700 * @param fadeIn Whether the text should fade in or fade out.
701 */
Sunny Goyal4e5a8782017-06-23 09:34:06 -0700702 public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700703 float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0;
Jon Miranda83cdca62019-04-15 13:01:05 -0700704 return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha);
Tony8f402802017-06-16 17:24:54 -0700705 }
706
Winson Chungaffd7b42010-08-20 15:11:56 -0700707 @Override
Winson Chung88f33452012-02-23 15:23:44 -0800708 public void cancelLongPress() {
709 super.cancelLongPress();
Winson Chung88f33452012-02-23 15:23:44 -0800710 mLongPressHelper.cancelLongPress();
711 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500712
Samuel Fufac2820182021-01-22 11:47:25 -0600713 /**
714 * Applies the loading progress value to the progress bar.
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000715 *
716 * If this app is installing, the progress bar will be updated with the installation progress.
717 * If this app is installed and downloading incrementally, the progress bar will be updated
718 * with the total download progress.
719 */
Federico Baron4eb502a2022-12-14 00:04:53 -0800720 public void applyLoadingState(PreloadIconDrawable icon) {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800721 if (getTag() instanceof ItemInfoWithIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -0700722 WorkspaceItemInfo info = (WorkspaceItemInfo) getTag();
Federico Baron4eb502a2022-12-14 00:04:53 -0800723 if ((info.runtimeStatusFlags & FLAG_INCREMENTAL_DOWNLOAD_ACTIVE) != 0
724 || info.hasPromiseIconUi()
725 || (info.runtimeStatusFlags & FLAG_INSTALL_SESSION_ACTIVE) != 0
726 || (ENABLE_DOWNLOAD_APP_UX_V2.get() && icon != null)) {
727 updateProgressBarUi(icon);
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700728 }
729 }
730 }
731
Federico Baron4eb502a2022-12-14 00:04:53 -0800732 private void updateProgressBarUi(PreloadIconDrawable oldIcon) {
733 FastBitmapDrawable originalIcon = mIcon;
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800734 PreloadIconDrawable preloadDrawable = applyProgressLevel();
Federico Baron4eb502a2022-12-14 00:04:53 -0800735 if (preloadDrawable != null && oldIcon != null) {
736 preloadDrawable.maybePerformFinishedAnimation(oldIcon, () -> setIcon(originalIcon));
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000737 }
738 }
739
740 /** Applies the given progress level to the this icon's progress bar. */
741 @Nullable
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800742 public PreloadIconDrawable applyProgressLevel() {
743 if (!(getTag() instanceof ItemInfoWithIcon)) {
744 return null;
745 }
746
747 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
748 int progressLevel = info.getProgressLevel();
749 if (progressLevel >= 100) {
750 setContentDescription(info.contentDescription != null
751 ? info.contentDescription : "");
752 } else if (progressLevel > 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800753 setDownloadStateContentDescription(info, progressLevel);
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800754 } else {
755 setContentDescription(getContext()
756 .getString(R.string.app_waiting_download_title, info.title));
757 }
758 if (mIcon != null) {
759 PreloadIconDrawable preloadIconDrawable;
760 if (mIcon instanceof PreloadIconDrawable) {
761 preloadIconDrawable = (PreloadIconDrawable) mIcon;
762 preloadIconDrawable.setLevel(progressLevel);
763 preloadIconDrawable.setIsDisabled(!info.isAppStartable());
Mario Bertschler230612f2017-09-27 17:05:21 -0700764 } else {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800765 preloadIconDrawable = makePreloadIcon();
766 setIcon(preloadIconDrawable);
Mario Bertschler230612f2017-09-27 17:05:21 -0700767 }
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800768 return preloadIconDrawable;
Chris Wren40c5ed32014-06-24 18:24:23 -0400769 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700770 return null;
Chris Wren40c5ed32014-06-24 18:24:23 -0400771 }
Sunny Goyal95abbb32014-08-04 10:53:22 -0700772
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800773 /**
774 * Creates a PreloadIconDrawable with the appropriate progress level without mutating this
775 * object.
776 */
777 @Nullable
778 public PreloadIconDrawable makePreloadIcon() {
779 if (!(getTag() instanceof ItemInfoWithIcon)) {
780 return null;
781 }
782
783 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
784 int progressLevel = info.getProgressLevel();
785 final PreloadIconDrawable preloadDrawable = newPendingIcon(getContext(), info);
786
787 preloadDrawable.setLevel(progressLevel);
788 preloadDrawable.setIsDisabled(!info.isAppStartable());
789
790 return preloadDrawable;
791 }
792
Tony Wickhamf34bee82018-12-03 18:11:39 -0800793 public void applyDotState(ItemInfo itemInfo, boolean animate) {
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800794 if (mIcon instanceof FastBitmapDrawable) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800795 boolean wasDotted = mDotInfo != null;
796 mDotInfo = mActivity.getDotInfoForItem(itemInfo);
797 boolean isDotted = mDotInfo != null;
798 float newDotScale = isDotted ? 1f : 0;
Samuel Fufac96fa242019-09-26 23:06:32 -0700799 if (mDisplay == DISPLAY_ALL_APPS) {
800 mDotRenderer = mActivity.getDeviceProfile().mDotRendererAllApps;
801 } else {
802 mDotRenderer = mActivity.getDeviceProfile().mDotRendererWorkSpace;
803 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800804 if (wasDotted || isDotted) {
805 // Animate when a dot is first added or when it is removed.
806 if (animate && (wasDotted ^ isDotted) && isShown()) {
807 animateDotScale(newDotScale);
Tony Wickham1237df02017-02-24 08:59:36 -0800808 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800809 cancelDotScaleAnim();
810 mDotParams.scale = newDotScale;
Tony Wickham1237df02017-02-24 08:59:36 -0800811 invalidate();
812 }
813 }
Andy Wickham56be73b2022-01-18 09:13:43 -0800814 if (!TextUtils.isEmpty(itemInfo.contentDescription)) {
vadimtda6dad52019-05-21 13:24:23 -0700815 if (itemInfo.isDisabled()) {
816 setContentDescription(getContext().getString(R.string.disabled_app_label,
817 itemInfo.contentDescription));
818 } else if (hasDot()) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800819 int count = mDotInfo.getNotificationCount();
Steven Ng707b1182021-09-13 11:54:58 +0100820 setContentDescription(
821 getAppLabelPluralString(itemInfo.contentDescription.toString(), count));
Tony Wickham305e9202018-01-23 17:46:47 -0800822 } else {
823 setContentDescription(itemInfo.contentDescription);
824 }
825 }
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800826 }
827 }
828
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800829 private void setDownloadStateContentDescription(ItemInfoWithIcon info, int progressLevel) {
830 if ((info.runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK)
831 != 0) {
832 String percentageString = NumberFormat.getPercentInstance()
833 .format(progressLevel * 0.01);
Federico Baron4eb502a2022-12-14 00:04:53 -0800834 if ((info.runtimeStatusFlags & FLAG_INSTALL_SESSION_ACTIVE) != 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800835 setContentDescription(getContext()
836 .getString(
837 R.string.app_installing_title, info.title, percentageString));
838 } else if ((info.runtimeStatusFlags
Federico Baron4eb502a2022-12-14 00:04:53 -0800839 & FLAG_INCREMENTAL_DOWNLOAD_ACTIVE) != 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800840 setContentDescription(getContext()
841 .getString(
842 R.string.app_downloading_title, info.title, percentageString));
843 }
844 }
845 }
846
Winson Chungb745afb2015-03-02 11:51:23 -0800847 /**
848 * Sets the icon for this view based on the layout direction.
849 */
Sunny Goyalc4c32692021-05-21 14:23:29 -0700850 protected void setIcon(FastBitmapDrawable icon) {
Tony17b7f9b2017-05-23 12:19:09 -0700851 if (mIsIconVisible) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700852 applyCompoundDrawables(icon);
Tony17b7f9b2017-05-23 12:19:09 -0700853 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700854 mIcon = icon;
Hyunyoung Songa2373852019-01-04 12:01:32 -0800855 if (mIcon != null) {
856 mIcon.setVisible(getWindowVisibility() == VISIBLE && isShown(), false);
857 }
Tony17b7f9b2017-05-23 12:19:09 -0700858 }
859
Jon Miranda9b78e192019-08-30 18:42:01 -0700860 @Override
Tony17b7f9b2017-05-23 12:19:09 -0700861 public void setIconVisible(boolean visible) {
862 mIsIconVisible = visible;
Sunny Goyal30ac97d2020-06-24 23:47:46 -0700863 if (!mIsIconVisible) {
864 resetIconScale();
865 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700866 Drawable icon = visible ? mIcon : new ColorDrawable(Color.TRANSPARENT);
Tony17b7f9b2017-05-23 12:19:09 -0700867 applyCompoundDrawables(icon);
Tony Wickham377ed3f2016-07-20 15:21:04 -0700868 }
869
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400870 protected boolean iconUpdateAnimationEnabled() {
871 return mEnableIconUpdateAnimation;
872 }
873
Tony Wickham377ed3f2016-07-20 15:21:04 -0700874 protected void applyCompoundDrawables(Drawable icon) {
Jon Mirandafe749972022-03-15 10:02:39 -0700875 if (icon == null) {
876 // Icon can be null when we use the BubbleTextView for text only.
877 return;
878 }
879
Sunny Goyal66dccad2018-03-19 12:00:51 -0700880 // If we had already set an icon before, disable relayout as the icon size is the
881 // same as before.
882 mDisableRelayout = mIcon != null;
883
884 icon.setBounds(0, 0, mIconSize, mIconSize);
Schneider Victor-tulias350b4622020-09-18 11:16:30 -0700885
886 updateIcon(icon);
887
888 // If the current icon is a placeholder color, animate its update.
Schneider Victor-tulias3ee70182020-10-21 14:01:53 -0400889 if (mIcon != null
890 && mIcon instanceof PlaceHolderIconDrawable
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400891 && iconUpdateAnimationEnabled()) {
Steven Nge92bc552021-02-10 17:10:15 +0000892 ((PlaceHolderIconDrawable) mIcon).animateIconUpdate(icon);
Winson Chungb745afb2015-03-02 11:51:23 -0800893 }
Schneider Victor-tulias350b4622020-09-18 11:16:30 -0700894
Sunny Goyal66dccad2018-03-19 12:00:51 -0700895 mDisableRelayout = false;
Winson Chungb745afb2015-03-02 11:51:23 -0800896 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700897
Sunny Goyal69b75642015-05-15 17:00:24 -0700898 @Override
899 public void requestLayout() {
900 if (!mDisableRelayout) {
901 super.requestLayout();
902 }
903 }
904
Sunny Goyal34b65272015-03-11 16:56:52 -0700905 /**
906 * Applies the item info if it is same as what the view is pointing to currently.
907 */
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800908 @Override
909 public void reapplyItemInfo(ItemInfoWithIcon info) {
Sunny Goyal34b65272015-03-11 16:56:52 -0700910 if (getTag() == info) {
911 mIconLoadRequest = null;
Sunny Goyal69b75642015-05-15 17:00:24 -0700912 mDisableRelayout = true;
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400913 mEnableIconUpdateAnimation = true;
Winsonc0880492015-08-21 11:16:27 -0700914
Jon Miranda7f522a22017-07-28 11:56:47 -0700915 // Optimization: Starting in N, pre-uploads the bitmap to RenderThread.
Sunny Goyal3808a692019-10-25 13:41:28 -0700916 info.bitmap.icon.prepareToDraw();
Jon Miranda7f522a22017-07-28 11:56:47 -0700917
Sunny Goyal34b65272015-03-11 16:56:52 -0700918 if (info instanceof AppInfo) {
919 applyFromApplicationInfo((AppInfo) info);
Sunny Goyal95899162019-03-27 16:03:06 -0700920 } else if (info instanceof WorkspaceItemInfo) {
921 applyFromWorkspaceItem((WorkspaceItemInfo) info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700922 mActivity.invalidateParent(info);
Sunny Goyalf0ff70a2022-05-11 07:23:10 -0700923 } else if (info != null) {
924 applyFromItemInfoWithIcon(info);
Sunny Goyal34b65272015-03-11 16:56:52 -0700925 }
Winsonc0880492015-08-21 11:16:27 -0700926
Sunny Goyal69b75642015-05-15 17:00:24 -0700927 mDisableRelayout = false;
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400928 mEnableIconUpdateAnimation = false;
Sunny Goyal34b65272015-03-11 16:56:52 -0700929 }
930 }
931
932 /**
933 * Verifies that the current icon is high-res otherwise posts a request to load the icon.
934 */
935 public void verifyHighRes() {
936 if (mIconLoadRequest != null) {
937 mIconLoadRequest.cancel();
938 mIconLoadRequest = null;
939 }
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800940 if (getTag() instanceof ItemInfoWithIcon) {
941 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Sunny Goyal2b787e52018-08-20 15:01:03 -0700942 if (info.usingLowResIcon()) {
Sunny Goyal87f784c2017-01-11 10:48:34 -0800943 mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache()
Sunny Goyal0e08f162015-05-12 11:32:39 -0700944 .updateIconInBackground(BubbleTextView.this, info);
945 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700946 }
947 }
Sunny Goyal4b6eb262015-05-14 19:24:40 -0700948
Jon Miranda47170112017-03-03 14:57:14 -0800949 public int getIconSize() {
950 return mIconSize;
951 }
Adam Cohen65086992020-02-19 08:40:49 -0800952
Brandon Dayauond3755f42022-08-29 11:48:27 -0700953 public boolean isDisplaySearchResult() {
954 return mDisplay == DISPLAY_SEARCH_RESULT ||
955 mDisplay == DISPLAY_SEARCH_RESULT_SMALL;
956 }
957
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700958 private void updateTranslation() {
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800959 super.setTranslationX(mTranslationForReorderBounce.x
960 + mTranslationForReorderPreview.x
Nick Chameyev4dd41592021-08-27 14:11:53 +0100961 + mTranslationForMoveFromCenterAnimation.x
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800962 + mTranslationXForTaskbarAlignmentAnimation
963 + mTranslationXForTaskbarRevealAnimation
964 );
965 super.setTranslationY(mTranslationForReorderBounce.y
966 + mTranslationForReorderPreview.y
967 + mTranslationForMoveFromCenterAnimation.y
968 + mTranslationYForTaskbarAlignmentAnimation
969 + mTranslationYForTaskbarRevealAnimation);
Adam Cohend9162062020-03-24 16:35:35 -0700970 }
971
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700972 public void setReorderBounceOffset(float x, float y) {
973 mTranslationForReorderBounce.set(x, y);
974 updateTranslation();
Adam Cohend9162062020-03-24 16:35:35 -0700975 }
976
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700977 public void getReorderBounceOffset(PointF offset) {
978 offset.set(mTranslationForReorderBounce);
979 }
980
981 @Override
982 public void setReorderPreviewOffset(float x, float y) {
983 mTranslationForReorderPreview.set(x, y);
984 updateTranslation();
985 }
986
987 @Override
988 public void getReorderPreviewOffset(PointF offset) {
989 offset.set(mTranslationForReorderPreview);
990 }
991
992 public void setReorderBounceScale(float scale) {
993 mScaleForReorderBounce = scale;
Adam Cohend9162062020-03-24 16:35:35 -0700994 super.setScaleX(scale);
995 super.setScaleY(scale);
996 }
997
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700998 public float getReorderBounceScale() {
999 return mScaleForReorderBounce;
Adam Cohend9162062020-03-24 16:35:35 -07001000 }
1001
Nick Chameyev4dd41592021-08-27 14:11:53 +01001002 /**
1003 * Sets translation values for move from center animation
1004 */
Nick Chameyev5e8dbe72021-07-26 14:56:50 +01001005 public void setTranslationForMoveFromCenterAnimation(float x, float y) {
1006 mTranslationForMoveFromCenterAnimation.set(x, y);
1007 updateTranslation();
1008 }
1009
Nick Chameyev4dd41592021-08-27 14:11:53 +01001010 /**
1011 * Sets translationX for taskbar to launcher alignment animation
1012 */
1013 public void setTranslationXForTaskbarAlignmentAnimation(float translationX) {
1014 mTranslationXForTaskbarAlignmentAnimation = translationX;
1015 updateTranslation();
1016 }
1017
1018 /**
1019 * Returns translationX value for taskbar to launcher alignment animation
1020 */
1021 public float getTranslationXForTaskbarAlignmentAnimation() {
1022 return mTranslationXForTaskbarAlignmentAnimation;
1023 }
1024
Jon Miranda13e9b9f2023-02-14 21:02:25 -08001025 /**
1026 * Sets translationX for taskbar to launcher alignment animation
1027 */
1028 public void setTranslationYForTaskbarAlignmentAnimation(float translationY) {
1029 mTranslationYForTaskbarAlignmentAnimation = translationY;
1030 updateTranslation();
1031 }
1032
1033 /**
1034 * Returns translationY value for taskbar to launcher alignment animation
1035 */
1036 public float getTranslationYForTaskbarAlignmentAnimation() {
1037 return mTranslationYForTaskbarAlignmentAnimation;
1038 }
1039
1040 /**
1041 * Sets translationX value for taskbar reveal animation
1042 */
1043 public void setTranslationXForTaskbarRevealAnimation(float translationX) {
1044 mTranslationXForTaskbarRevealAnimation = translationX;
1045 updateTranslation();
1046 }
1047
1048 /**
1049 * Returns translation values for taskbar reveal animation
1050 */
1051 public float getTranslationXForTaskbarRevealAnimation() {
1052 return mTranslationXForTaskbarRevealAnimation;
1053 }
1054
1055 /**
1056 * Sets translationY value for taskbar reveal animation
1057 */
1058 public void setTranslationYForTaskbarRevealAnimation(float translationY) {
1059 mTranslationYForTaskbarRevealAnimation = translationY;
1060 updateTranslation();
1061 }
1062
1063 /**
1064 * Returns translationY values for taskbar reveal animation
1065 */
1066 public float getTranslationYForTaskbarRevealAnimation() {
1067 return mTranslationYForTaskbarRevealAnimation;
1068 }
1069
Adam Cohend9162062020-03-24 16:35:35 -07001070 public View getView() {
1071 return this;
1072 }
1073
Adam Cohen65086992020-02-19 08:40:49 -08001074 @Override
1075 public int getViewType() {
1076 return DRAGGABLE_ICON;
1077 }
1078
1079 @Override
Adam Cohenc77bc452020-05-07 11:55:19 -07001080 public void getWorkspaceVisualDragBounds(Rect bounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -07001081 getIconBounds(mIconSize, bounds);
Adam Cohen65086992020-02-19 08:40:49 -08001082 }
1083
Adam Cohenc77bc452020-05-07 11:55:19 -07001084 public void getSourceVisualDragBounds(Rect bounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -07001085 getIconBounds(mIconSize, bounds);
Adam Cohenc77bc452020-05-07 11:55:19 -07001086 }
1087
Adam Cohen65086992020-02-19 08:40:49 -08001088 @Override
Samuel Fufa167210a2020-05-12 18:40:11 -07001089 public SafeCloseable prepareDrawDragView() {
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001090 resetIconScale();
Adam Cohen65086992020-02-19 08:40:49 -08001091 setForceHideDot(true);
Sunny Goyal8b9919d2021-04-07 14:45:17 -07001092 return () -> { };
Adam Cohen65086992020-02-19 08:40:49 -08001093 }
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001094
1095 private void resetIconScale() {
Sunny Goyal52f4c162022-04-23 16:02:03 +00001096 if (mIcon != null) {
1097 mIcon.resetScale();
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001098 }
1099 }
Schneider Victor-tulias350b4622020-09-18 11:16:30 -07001100
1101 private void updateIcon(Drawable newIcon) {
1102 if (mLayoutHorizontal) {
1103 setCompoundDrawablesRelative(newIcon, null, null, null);
1104 } else {
1105 setCompoundDrawables(null, newIcon, null, null);
1106 }
1107 }
Steven Ng707b1182021-09-13 11:54:58 +01001108
1109 private String getAppLabelPluralString(String appName, int notificationCount) {
1110 MessageFormat icuCountFormat = new MessageFormat(
1111 getResources().getString(R.string.dotted_app_label),
1112 Locale.getDefault());
1113 HashMap<String, Object> args = new HashMap();
1114 args.put("app_name", appName);
1115 args.put("count", notificationCount);
1116 return icuCountFormat.format(args);
1117 }
Sunny Goyalf0ff70a2022-05-11 07:23:10 -07001118
1119 /**
1120 * Starts a long press action and returns the corresponding pre-drag condition
1121 */
1122 public PreDragCondition startLongPressAction() {
1123 PopupContainerWithArrow popup = PopupContainerWithArrow.showForIcon(this);
1124 return popup != null ? popup.createPreDragCondition(true) : null;
1125 }
1126
1127 /**
1128 * Returns true if the view can show long-press popup
1129 */
1130 public boolean canShowLongPressPopup() {
1131 return getTag() instanceof ItemInfo && ShortcutUtil.supportsShortcuts((ItemInfo) getTag());
1132 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133}