blob: df38c26a1bb8532e606e7783965a03df982ff673 [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
Jagrut Desai560b0ea2023-02-16 15:40:44 -0800116 private float mTranslationXForTaskbarAllAppsIcon = 0f;
117
Tony Wickhamf34bee82018-12-03 18:11:39 -0800118 private static final Property<BubbleTextView, Float> DOT_SCALE_PROPERTY
119 = new Property<BubbleTextView, Float>(Float.TYPE, "dotScale") {
Tony Wickham1237df02017-02-24 08:59:36 -0800120 @Override
121 public Float get(BubbleTextView bubbleTextView) {
Tony Wickham8912b042018-11-29 15:28:53 -0800122 return bubbleTextView.mDotParams.scale;
Tony Wickham1237df02017-02-24 08:59:36 -0800123 }
124
125 @Override
126 public void set(BubbleTextView bubbleTextView, Float value) {
Tony Wickham8912b042018-11-29 15:28:53 -0800127 bubbleTextView.mDotParams.scale = value;
Tony Wickham1237df02017-02-24 08:59:36 -0800128 bubbleTextView.invalidate();
129 }
130 };
131
Sunny Goyaled7a6932018-04-13 11:41:50 -0700132 public static final Property<BubbleTextView, Float> TEXT_ALPHA_PROPERTY
133 = new Property<BubbleTextView, Float>(Float.class, "textAlpha") {
Tony8f402802017-06-16 17:24:54 -0700134 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700135 public Float get(BubbleTextView bubbleTextView) {
136 return bubbleTextView.mTextAlpha;
Tony8f402802017-06-16 17:24:54 -0700137 }
138
139 @Override
Sunny Goyaled7a6932018-04-13 11:41:50 -0700140 public void set(BubbleTextView bubbleTextView, Float alpha) {
Tony8f402802017-06-16 17:24:54 -0700141 bubbleTextView.setTextAlpha(alpha);
142 }
143 };
144
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800145 private final ActivityContext mActivity;
Sunny Goyalc4c32692021-05-21 14:23:29 -0700146 private FastBitmapDrawable mIcon;
Adam Cohen65086992020-02-19 08:40:49 -0800147 private boolean mCenterVertically;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700148
Tony Wickham794fe4f2021-01-11 14:54:23 -0600149 protected final int mDisplay;
Samuel Fufac96fa242019-09-26 23:06:32 -0700150
Sunny Goyaled7a6932018-04-13 11:41:50 -0700151 private final CheckLongPressHelper mLongPressHelper;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700152
153 private final boolean mLayoutHorizontal;
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700154 private final boolean mIsRtl;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700155 private final int mIconSize;
156
157 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyald872a972021-11-24 18:07:04 -0800158 private boolean mHideBadge = false;
159 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyaled7a6932018-04-13 11:41:50 -0700160 private boolean mIsIconVisible = true;
161 @ViewDebug.ExportedProperty(category = "launcher")
162 private int mTextColor;
163 @ViewDebug.ExportedProperty(category = "launcher")
Jon Spivack68862142021-10-28 18:37:19 -0700164 private ColorStateList mTextColorStateList;
165 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyaled7a6932018-04-13 11:41:50 -0700166 private float mTextAlpha = 1;
167
Tony4043b052018-08-17 13:47:39 -0700168 @ViewDebug.ExportedProperty(category = "launcher")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800169 private DotInfo mDotInfo;
Tony Wickham8912b042018-11-29 15:28:53 -0800170 private DotRenderer mDotRenderer;
171 @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
Sunny Goyal67555872021-05-21 12:56:55 -0700172 protected DotRenderer.DrawParams mDotParams;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800173 private Animator mDotScaleAnim;
174 private boolean mForceHideDot;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700175
Sunny Goyal4ffec482016-02-09 11:28:52 -0800176 @ViewDebug.ExportedProperty(category = "launcher")
Michael Jurkaddd62e92011-02-16 17:49:14 -0800177 private boolean mStayPressed;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800178 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal508da152014-08-14 10:53:27 -0700179 private boolean mIgnorePressedStateChange;
Sunny Goyal4ffec482016-02-09 11:28:52 -0800180 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal69b75642015-05-15 17:00:24 -0700181 private boolean mDisableRelayout = false;
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500182
Sunny Goyal79e52fc2021-02-03 10:22:28 -0800183 private HandlerRunnable mIconLoadRequest;
Sunny Goyal34b65272015-03-11 16:56:52 -0700184
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400185 private boolean mEnableIconUpdateAnimation = false;
186
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 public BubbleTextView(Context context) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700188 this(context, null, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189 }
190
191 public BubbleTextView(Context context, AttributeSet attrs) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700192 this(context, attrs, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 }
194
195 public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
196 super(context, attrs, defStyle);
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800197 mActivity = ActivityContext.lookupContext(context);
Adam Cohen96bb7982014-07-07 11:58:56 -0700198
Adam Cohen96bb7982014-07-07 11:58:56 -0700199 TypedArray a = context.obtainStyledAttributes(attrs,
200 R.styleable.BubbleTextView, defStyle, 0);
Winson Chungb745afb2015-03-02 11:51:23 -0800201 mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700202 mIsRtl = (getResources().getConfiguration().getLayoutDirection()
203 == View.LAYOUT_DIRECTION_RTL);
Sunny Goyalc4d32012020-04-03 17:10:11 -0700204 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700205
Samuel Fufac96fa242019-09-26 23:06:32 -0700206 mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700207 final int defaultIconSize;
Samuel Fufac96fa242019-09-26 23:06:32 -0700208 if (mDisplay == DISPLAY_WORKSPACE) {
Winson Chung44d0aac2015-05-11 18:02:55 -0700209 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
Jon Miranda09660722017-06-14 14:20:14 -0700210 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
Sunny Goyalae6e3182019-04-30 12:04:37 -0700211 defaultIconSize = grid.iconSizePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500212 setCenterVertically(grid.isScalableGrid);
Samuel Fufac96fa242019-09-26 23:06:32 -0700213 } else if (mDisplay == DISPLAY_ALL_APPS) {
Winson1f064272016-07-18 17:18:02 -0700214 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
215 setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700216 defaultIconSize = grid.allAppsIconSizePx;
Samuel Fufac96fa242019-09-26 23:06:32 -0700217 } else if (mDisplay == DISPLAY_FOLDER) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700218 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700219 setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700220 defaultIconSize = grid.folderChildIconSizePx;
Hyunyoung Songe3d32b52021-06-03 21:20:18 -0700221 } else if (mDisplay == DISPLAY_SEARCH_RESULT) {
222 defaultIconSize = getResources().getDimensionPixelSize(R.dimen.search_row_icon_size);
223 } else if (mDisplay == DISPLAY_SEARCH_RESULT_SMALL) {
224 defaultIconSize = getResources().getDimensionPixelSize(
225 R.dimen.search_row_small_icon_size);
Tony Wickham794fe4f2021-01-11 14:54:23 -0600226 } else if (mDisplay == DISPLAY_TASKBAR) {
227 defaultIconSize = grid.iconSizePx;
Sunny Goyalae6e3182019-04-30 12:04:37 -0700228 } else {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700229 // widget_selection or shortcut_popup
Sunny Goyalc4d32012020-04-03 17:10:11 -0700230 defaultIconSize = grid.iconSizePx;
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700231 }
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700232
Winson1f064272016-07-18 17:18:02 -0700233 mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700234
235 mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
236 defaultIconSize);
Adam Cohen96bb7982014-07-07 11:58:56 -0700237 a.recycle();
238
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800239 mLongPressHelper = new CheckLongPressHelper(this);
240
Tony Wickham8912b042018-11-29 15:28:53 -0800241 mDotParams = new DotRenderer.DrawParams();
242
Sunny Goyal66dccad2018-03-19 12:00:51 -0700243 setEllipsize(TruncateAt.END);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700244 setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
Sunny Goyaled7a6932018-04-13 11:41:50 -0700245 setTextAlpha(1f);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 }
247
Sunny Goyal66dccad2018-03-19 12:00:51 -0700248 @Override
249 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
250 // Disable marques when not focused to that, so that updating text does not cause relayout.
251 setEllipsize(focused ? TruncateAt.MARQUEE : TruncateAt.END);
252 super.onFocusChanged(focused, direction, previouslyFocusedRect);
253 }
254
Sunny Goyald872a972021-11-24 18:07:04 -0800255 public void setHideBadge(boolean hideBadge) {
256 mHideBadge = hideBadge;
257 }
258
Jon Miranda52549442017-10-26 11:28:06 -0700259 /**
260 * Resets the view so it can be recycled.
261 */
262 public void reset() {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800263 mDotInfo = null;
James O'Leary1557ba32022-05-04 16:49:03 +0000264 mDotParams.dotColor = Color.TRANSPARENT;
265 mDotParams.appColor = Color.TRANSPARENT;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800266 cancelDotScaleAnim();
Tony Wickham8912b042018-11-29 15:28:53 -0800267 mDotParams.scale = 0f;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800268 mForceHideDot = false;
Samuel Fufaba6b47f2019-11-07 10:27:41 -0800269 setBackground(null);
Sunny Goyal52f4c162022-04-23 16:02:03 +0000270
271 setTag(null);
272 if (mIconLoadRequest != null) {
273 mIconLoadRequest.cancel();
274 mIconLoadRequest = null;
275 }
Jon Miranda52549442017-10-26 11:28:06 -0700276 }
277
Tony Wickhamf34bee82018-12-03 18:11:39 -0800278 private void cancelDotScaleAnim() {
279 if (mDotScaleAnim != null) {
280 mDotScaleAnim.cancel();
Tony4043b052018-08-17 13:47:39 -0700281 }
282 }
283
Tony Wickhamf34bee82018-12-03 18:11:39 -0800284 private void animateDotScale(float... dotScales) {
285 cancelDotScaleAnim();
286 mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales);
287 mDotScaleAnim.addListener(new AnimatorListenerAdapter() {
Tony4043b052018-08-17 13:47:39 -0700288 @Override
289 public void onAnimationEnd(Animator animation) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800290 mDotScaleAnim = null;
Tony4043b052018-08-17 13:47:39 -0700291 }
292 });
Tony Wickhamf34bee82018-12-03 18:11:39 -0800293 mDotScaleAnim.start();
Tony4043b052018-08-17 13:47:39 -0700294 }
295
Hyunyoung Song5809a402021-02-02 01:19:18 -0800296 @UiThread
Sunny Goyal95899162019-03-27 16:03:06 -0700297 public void applyFromWorkspaceItem(WorkspaceItemInfo info) {
Tony Wickham175d1522021-08-25 09:18:41 -0700298 applyFromWorkspaceItem(info, /* animate = */ false, /* staggerIndex = */ 0);
299 }
300
301 @UiThread
302 public void applyFromWorkspaceItem(WorkspaceItemInfo info, boolean animate, int staggerIndex) {
Federico Baron4eb502a2022-12-14 00:04:53 -0800303 applyFromWorkspaceItem(info, null);
Winson Chung5f8afe62013-08-12 16:19:28 -0700304 }
305
Tony Wickham175d1522021-08-25 09:18:41 -0700306 /**
307 * Returns whether the newInfo differs from the current getTag().
308 */
309 public boolean shouldAnimateIconChange(WorkspaceItemInfo newInfo) {
310 WorkspaceItemInfo oldInfo = getTag() instanceof WorkspaceItemInfo
311 ? (WorkspaceItemInfo) getTag()
312 : null;
313 boolean changedIcons = oldInfo != null && oldInfo.getTargetComponent() != null
314 && newInfo.getTargetComponent() != null
315 && !oldInfo.getTargetComponent().equals(newInfo.getTargetComponent());
316 return changedIcons && isShown();
317 }
318
Adam Cohen29794c52019-06-21 12:50:30 -0700319 @Override
320 public void setAccessibilityDelegate(AccessibilityDelegate delegate) {
Schneider Victor-tuliasbdb0dd82021-11-03 16:26:41 -0700321 if (delegate instanceof BaseAccessibilityDelegate) {
Adam Cohen29794c52019-06-21 12:50:30 -0700322 super.setAccessibilityDelegate(delegate);
323 } else {
324 // NO-OP
325 // Workaround for b/129745295 where RecyclerView is setting our Accessibility
326 // delegate incorrectly. There are no cases when we shouldn't be using the
327 // LauncherAccessibilityDelegate for BubbleTextView.
328 }
329 }
330
Hyunyoung Song5809a402021-02-02 01:19:18 -0800331 @UiThread
Federico Baron4eb502a2022-12-14 00:04:53 -0800332 public void applyFromWorkspaceItem(WorkspaceItemInfo info, PreloadIconDrawable icon) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800333 applyIconAndLabel(info);
sfufa@google.comca76de02021-09-24 08:55:48 -0700334 setItemInfo(info);
Federico Baron4eb502a2022-12-14 00:04:53 -0800335 applyLoadingState(icon);
Tony Wickhamf34bee82018-12-03 18:11:39 -0800336 applyDotState(info, false /* animate */);
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800337 setDownloadStateContentDescription(info, info.getProgressLevel());
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800338 }
339
Hyunyoung Song5809a402021-02-02 01:19:18 -0800340 @UiThread
Sunny Goyal508da152014-08-14 10:53:27 -0700341 public void applyFromApplicationInfo(AppInfo info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800342 applyIconAndLabel(info);
Sunny Goyalf4204382016-07-13 10:46:07 -0700343
Sunny Goyal95899162019-03-27 16:03:06 -0700344 // We don't need to check the info since it's not a WorkspaceItemInfo
sfufa@google.comca76de02021-09-24 08:55:48 -0700345 setItemInfo(info);
346
Sunny Goyal34b65272015-03-11 16:56:52 -0700347
348 // Verify high res immediately
349 verifyHighRes();
Tony Wickham010d2552017-01-20 08:15:28 -0800350
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000351 if ((info.runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800352 applyProgressLevel();
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700353 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800354 applyDotState(info, false /* animate */);
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800355 setDownloadStateContentDescription(info, info.getProgressLevel());
Sunny Goyal508da152014-08-14 10:53:27 -0700356 }
357
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700358 /**
359 * Apply label and tag using a generic {@link ItemInfoWithIcon}
360 */
Hyunyoung Song5809a402021-02-02 01:19:18 -0800361 @UiThread
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700362 public void applyFromItemInfoWithIcon(ItemInfoWithIcon info) {
Sunny Goyal179249d2017-12-19 16:49:24 -0800363 applyIconAndLabel(info);
Sunny Goyal95899162019-03-27 16:03:06 -0700364 // We don't need to check the info since it's not a WorkspaceItemInfo
sfufa@google.comca76de02021-09-24 08:55:48 -0700365 setItemInfo(info);
Sunny Goyal0e08f162015-05-12 11:32:39 -0700366
367 // Verify high res immediately
368 verifyHighRes();
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800369
370 setDownloadStateContentDescription(info, info.getProgressLevel());
Sunny Goyal0e08f162015-05-12 11:32:39 -0700371 }
372
Sunny Goyalf0ff70a2022-05-11 07:23:10 -0700373 protected void setItemInfo(ItemInfoWithIcon itemInfo) {
sfufa@google.comca76de02021-09-24 08:55:48 -0700374 setTag(itemInfo);
sfufa@google.com0fe464d2021-10-14 14:34:50 -0700375 }
376
Hyunyoung Song5809a402021-02-02 01:19:18 -0800377 @UiThread
Samuel Fufac2820182021-01-22 11:47:25 -0600378 protected void applyIconAndLabel(ItemInfoWithIcon info) {
Brandon Dayauone640a9e2023-02-03 14:12:25 -0800379 int flags = shouldUseTheme() ? FLAG_THEMED : 0;
Sunny Goyald872a972021-11-24 18:07:04 -0800380 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
Brandon Dayauone640a9e2023-02-03 14:12:25 -0800391 protected boolean shouldUseTheme() {
392 return mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER
393 || mDisplay == DISPLAY_TASKBAR;
394 }
395
Hyunyoung Song5809a402021-02-02 01:19:18 -0800396 @UiThread
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000397 private void applyLabel(ItemInfoWithIcon info) {
Sunny Goyalf4204382016-07-13 10:46:07 -0700398 setText(info.title);
399 if (info.contentDescription != null) {
400 setContentDescription(info.isDisabled()
401 ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
402 : info.contentDescription);
403 }
404 }
405
Winson Chung7501adf2015-06-02 11:24:28 -0700406 /**
407 * Overrides the default long press timeout.
408 */
Tony2ca999c2018-09-24 17:24:51 -0400409 public void setLongPressTimeoutFactor(float longPressTimeoutFactor) {
410 mLongPressHelper.setLongPressTimeoutFactor(longPressTimeoutFactor);
Winson Chung7501adf2015-06-02 11:24:28 -0700411 }
Sunny Goyal0e08f162015-05-12 11:32:39 -0700412
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 @Override
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800414 public void refreshDrawableState() {
Sunny Goyal508da152014-08-14 10:53:27 -0700415 if (!mIgnorePressedStateChange) {
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800416 super.refreshDrawableState();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800417 }
Sunny Goyal508da152014-08-14 10:53:27 -0700418 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800419
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800420 @Override
421 protected int[] onCreateDrawableState(int extraSpace) {
422 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
423 if (mStayPressed) {
424 mergeDrawableStates(drawableState, STATE_PRESSED);
425 }
426 return drawableState;
427 }
428
Winson Chungb745afb2015-03-02 11:51:23 -0800429 /** Returns the icon for this view. */
Sunny Goyalc4c32692021-05-21 14:23:29 -0700430 public FastBitmapDrawable getIcon() {
Winson Chungb745afb2015-03-02 11:51:23 -0800431 return mIcon;
432 }
433
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700434 @Override
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800435 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700436 // ignore events if they happen in padding area
Sunny Goyal17feee82020-03-24 13:55:15 -0700437 if (event.getAction() == MotionEvent.ACTION_DOWN
Sunny Goyal44a3b202020-07-09 08:27:06 -0700438 && shouldIgnoreTouchDown(event.getX(), event.getY())) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700439 return false;
440 }
Sunny Goyal17feee82020-03-24 13:55:15 -0700441 if (isLongClickable()) {
442 super.onTouchEvent(event);
443 mLongPressHelper.onTouchEvent(event);
444 // Keep receiving the rest of the events
445 return true;
446 } else {
447 return super.onTouchEvent(event);
Mady Melloref044dd2015-06-02 15:35:07 -0700448 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800449 }
450
Sunny Goyal44a3b202020-07-09 08:27:06 -0700451 /**
452 * Returns true if the touch down at the provided position be ignored
453 */
454 protected boolean shouldIgnoreTouchDown(float x, float y) {
Tony Wickham42b03952021-08-31 10:41:36 -0700455 if (mDisplay == DISPLAY_TASKBAR) {
456 // Allow touching within padding on taskbar, given icon sizes are smaller.
457 return false;
458 }
Sunny Goyal44a3b202020-07-09 08:27:06 -0700459 return y < getPaddingTop()
460 || x < getPaddingLeft()
461 || y > getHeight() - getPaddingBottom()
462 || x > getWidth() - getPaddingRight();
463 }
464
Michael Jurkaddd62e92011-02-16 17:49:14 -0800465 void setStayPressed(boolean stayPressed) {
466 mStayPressed = stayPressed;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800467 refreshDrawableState();
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800468 }
469
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700470 @Override
Hyunyoung Songef468d82019-01-03 01:02:43 -0800471 public void onVisibilityAggregated(boolean isVisible) {
472 super.onVisibilityAggregated(isVisible);
473 if (mIcon != null) {
Hyunyoung Songa2373852019-01-04 12:01:32 -0800474 mIcon.setVisible(isVisible, false);
Hyunyoung Songef468d82019-01-03 01:02:43 -0800475 }
476 }
477
Tony Wickham8ac277e2021-05-24 15:47:38 -0700478 public void clearPressedBackground() {
Sunny Goyal508da152014-08-14 10:53:27 -0700479 setPressed(false);
480 setStayPressed(false);
481 }
482
483 @Override
Sunny Goyal508da152014-08-14 10:53:27 -0700484 public boolean onKeyUp(int keyCode, KeyEvent event) {
485 // Unlike touch events, keypress event propagate pressed state change immediately,
486 // without waiting for onClickHandler to execute. Disable pressed state changes here
487 // to avoid flickering.
488 mIgnorePressedStateChange = true;
489 boolean result = super.onKeyUp(keyCode, event);
Sunny Goyal508da152014-08-14 10:53:27 -0700490 mIgnorePressedStateChange = false;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800491 refreshDrawableState();
Sunny Goyal508da152014-08-14 10:53:27 -0700492 return result;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800493 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800494
Sunny Goyal0d69cb62021-10-04 15:31:38 -0700495 @Override
496 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
497 super.onSizeChanged(w, h, oldw, oldh);
498 checkForEllipsis();
499 }
500
501 @Override
502 protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
503 super.onTextChanged(text, start, lengthBefore, lengthAfter);
504 checkForEllipsis();
505 }
506
507 private void checkForEllipsis() {
508 if (!ENABLE_ICON_LABEL_AUTO_SCALING.get()) {
509 return;
510 }
511 float width = getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight();
512 if (width <= 0) {
513 return;
514 }
515 setLetterSpacing(0);
516
517 String text = getText().toString();
518 TextPaint paint = getPaint();
519 if (paint.measureText(text) < width) {
520 return;
521 }
522
523 float spacing = findBestSpacingValue(paint, text, width, MIN_LETTER_SPACING);
524 // Reset the paint value so that the call to TextView does appropriate diff.
525 paint.setLetterSpacing(0);
526 setLetterSpacing(spacing);
527 }
528
529 /**
530 * Find the appropriate text spacing to display the provided text
531 * @param paint the paint used by the text view
532 * @param text the text to display
533 * @param allowedWidthPx available space to render the text
534 * @param minSpacingEm minimum spacing allowed between characters
535 * @return the final textSpacing value
536 *
537 * @see #setLetterSpacing(float)
538 */
539 private float findBestSpacingValue(TextPaint paint, String text, float allowedWidthPx,
540 float minSpacingEm) {
541 paint.setLetterSpacing(minSpacingEm);
542 if (paint.measureText(text) > allowedWidthPx) {
543 // If there is no result at high limit, we can do anything more
544 return minSpacingEm;
545 }
546
547 float lowLimit = 0;
548 float highLimit = minSpacingEm;
549
550 for (int i = 0; i < MAX_SEARCH_LOOP_COUNT; i++) {
551 float value = (lowLimit + highLimit) / 2;
552 paint.setLetterSpacing(value);
553 if (paint.measureText(text) < allowedWidthPx) {
554 highLimit = value;
555 } else {
556 lowLimit = value;
557 }
558 }
559
560 // At the end error on the higher side
561 return highLimit;
562 }
563
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700564 @SuppressWarnings("wrongcall")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800565 protected void drawWithoutDot(Canvas canvas) {
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700566 super.onDraw(canvas);
567 }
568
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 @Override
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700570 public void onDraw(Canvas canvas) {
571 super.onDraw(canvas);
Tony Wickham22a5a682020-11-02 17:04:58 -0800572 drawDotIfNecessary(canvas);
Samuel Fufa314761a2020-10-14 10:15:07 -0700573 }
574
Tony Wickham1237df02017-02-24 08:59:36 -0800575 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800576 * Draws the notification dot in the top right corner of the icon bounds.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700577 *
Tony Wickham1237df02017-02-24 08:59:36 -0800578 * @param canvas The canvas to draw to.
579 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800580 protected void drawDotIfNecessary(Canvas canvas) {
581 if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800582 getIconBounds(mDotParams.iconBounds);
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700583 Utilities.scaleRectAboutCenter(mDotParams.iconBounds,
584 IconShape.getNormalizationScale());
Tony Wickham1237df02017-02-24 08:59:36 -0800585 final int scrollX = getScrollX();
586 final int scrollY = getScrollY();
587 canvas.translate(scrollX, scrollY);
Tony Wickham8912b042018-11-29 15:28:53 -0800588 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham1237df02017-02-24 08:59:36 -0800589 canvas.translate(-scrollX, -scrollY);
590 }
591 }
592
Jon Miranda9b78e192019-08-30 18:42:01 -0700593 @Override
594 public void setForceHideDot(boolean forceHideDot) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800595 if (mForceHideDot == forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800596 return;
597 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800598 mForceHideDot = forceHideDot;
Tony Wickham1237df02017-02-24 08:59:36 -0800599
Tony Wickhamf34bee82018-12-03 18:11:39 -0800600 if (forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800601 invalidate();
Tony Wickhamf34bee82018-12-03 18:11:39 -0800602 } else if (hasDot()) {
603 animateDotScale(0, 1);
Tony Wickham1237df02017-02-24 08:59:36 -0800604 }
605 }
606
Tony Wickhamf34bee82018-12-03 18:11:39 -0800607 private boolean hasDot() {
608 return mDotInfo != null;
Tony Wickham1237df02017-02-24 08:59:36 -0800609 }
610
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700611 /**
612 * Get the icon bounds on the view depending on the layout type.
613 */
Tony Wickham1237df02017-02-24 08:59:36 -0800614 public void getIconBounds(Rect outBounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700615 getIconBounds(mIconSize, outBounds);
Tony05d98c22018-07-23 08:01:15 -0700616 }
617
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700618 /**
619 * Get the icon bounds on the view depending on the layout type.
620 */
621 public void getIconBounds(int iconSize, Rect outBounds) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700622 outBounds.set(0, 0, iconSize, iconSize);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700623 if (mLayoutHorizontal) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700624 int top = (getHeight() - iconSize) / 2;
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700625 if (mIsRtl) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700626 outBounds.offsetTo(getWidth() - iconSize - getPaddingRight(), top);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700627 } else {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700628 outBounds.offsetTo(getPaddingLeft(), top);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700629 }
630 } else {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700631 outBounds.offset((getWidth() - iconSize) / 2, getPaddingTop());
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700632 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400634
Jon Miranda228877d2021-02-09 11:05:00 -0500635 /**
636 * Sets whether to vertically center the content.
637 */
638 public void setCenterVertically(boolean centerVertically) {
639 mCenterVertically = centerVertically;
640 }
641
Joe Onorato9c1289c2009-08-17 11:03:03 -0400642 @Override
Winson1f064272016-07-18 17:18:02 -0700643 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
644 if (mCenterVertically) {
645 Paint.FontMetrics fm = getPaint().getFontMetrics();
646 int cellHeightPx = mIconSize + getCompoundDrawablePadding() +
647 (int) Math.ceil(fm.bottom - fm.top);
648 int height = MeasureSpec.getSize(heightMeasureSpec);
649 setPadding(getPaddingLeft(), (height - cellHeightPx) / 2, getPaddingRight(),
650 getPaddingBottom());
651 }
652 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
653 }
654
655 @Override
Adam Cohen477828c2013-09-20 12:05:49 -0700656 public void setTextColor(int color) {
657 mTextColor = color;
Jon Spivack68862142021-10-28 18:37:19 -0700658 mTextColorStateList = null;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700659 super.setTextColor(getModifiedColor());
Adam Cohen477828c2013-09-20 12:05:49 -0700660 }
661
Adam Cohen96bb7982014-07-07 11:58:56 -0700662 @Override
663 public void setTextColor(ColorStateList colors) {
664 mTextColor = colors.getDefaultColor();
Jon Spivack68862142021-10-28 18:37:19 -0700665 mTextColorStateList = colors;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700666 if (Float.compare(mTextAlpha, 1) == 0) {
667 super.setTextColor(colors);
668 } else {
669 super.setTextColor(getModifiedColor());
670 }
Adam Cohen477828c2013-09-20 12:05:49 -0700671 }
672
Tony7308cde2017-06-27 22:38:33 -0700673 public boolean shouldTextBeVisible() {
674 // Text should be visible everywhere but the hotseat.
675 Object tag = getParent() instanceof FolderIcon ? ((View) getParent()).getTag() : getTag();
676 ItemInfo info = tag instanceof ItemInfo ? (ItemInfo) tag : null;
Samuel Fufaefb665d2019-10-30 13:24:14 -0700677 return info == null || (info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT
678 && info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION);
Tony7308cde2017-06-27 22:38:33 -0700679 }
680
Winson Chung5f8afe62013-08-12 16:19:28 -0700681 public void setTextVisibility(boolean visible) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700682 setTextAlpha(visible ? 1 : 0);
683 }
684
685 private void setTextAlpha(float alpha) {
686 mTextAlpha = alpha;
Jon Spivack68862142021-10-28 18:37:19 -0700687 if (mTextColorStateList != null) {
688 setTextColor(mTextColorStateList);
689 } else {
690 super.setTextColor(getModifiedColor());
691 }
Sunny Goyaled7a6932018-04-13 11:41:50 -0700692 }
693
694 private int getModifiedColor() {
695 if (mTextAlpha == 0) {
696 // Special case to prevent text shadows in high contrast mode
697 return Color.TRANSPARENT;
Winson Chung5f8afe62013-08-12 16:19:28 -0700698 }
Sunny Goyal066ace12018-11-05 11:08:31 -0800699 return setColorAlphaBound(mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
Tony8f402802017-06-16 17:24:54 -0700700 }
701
702 /**
703 * Creates an animator to fade the text in or out.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700704 *
Tony8f402802017-06-16 17:24:54 -0700705 * @param fadeIn Whether the text should fade in or fade out.
706 */
Sunny Goyal4e5a8782017-06-23 09:34:06 -0700707 public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700708 float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0;
Jon Miranda83cdca62019-04-15 13:01:05 -0700709 return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha);
Tony8f402802017-06-16 17:24:54 -0700710 }
711
Winson Chungaffd7b42010-08-20 15:11:56 -0700712 @Override
Winson Chung88f33452012-02-23 15:23:44 -0800713 public void cancelLongPress() {
714 super.cancelLongPress();
Winson Chung88f33452012-02-23 15:23:44 -0800715 mLongPressHelper.cancelLongPress();
716 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500717
Samuel Fufac2820182021-01-22 11:47:25 -0600718 /**
719 * Applies the loading progress value to the progress bar.
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000720 *
721 * If this app is installing, the progress bar will be updated with the installation progress.
722 * If this app is installed and downloading incrementally, the progress bar will be updated
723 * with the total download progress.
724 */
Federico Baron4eb502a2022-12-14 00:04:53 -0800725 public void applyLoadingState(PreloadIconDrawable icon) {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800726 if (getTag() instanceof ItemInfoWithIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -0700727 WorkspaceItemInfo info = (WorkspaceItemInfo) getTag();
Federico Baron4eb502a2022-12-14 00:04:53 -0800728 if ((info.runtimeStatusFlags & FLAG_INCREMENTAL_DOWNLOAD_ACTIVE) != 0
729 || info.hasPromiseIconUi()
730 || (info.runtimeStatusFlags & FLAG_INSTALL_SESSION_ACTIVE) != 0
731 || (ENABLE_DOWNLOAD_APP_UX_V2.get() && icon != null)) {
732 updateProgressBarUi(icon);
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700733 }
734 }
735 }
736
Federico Baron4eb502a2022-12-14 00:04:53 -0800737 private void updateProgressBarUi(PreloadIconDrawable oldIcon) {
738 FastBitmapDrawable originalIcon = mIcon;
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800739 PreloadIconDrawable preloadDrawable = applyProgressLevel();
Federico Baron4eb502a2022-12-14 00:04:53 -0800740 if (preloadDrawable != null && oldIcon != null) {
741 preloadDrawable.maybePerformFinishedAnimation(oldIcon, () -> setIcon(originalIcon));
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000742 }
743 }
744
745 /** Applies the given progress level to the this icon's progress bar. */
746 @Nullable
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800747 public PreloadIconDrawable applyProgressLevel() {
748 if (!(getTag() instanceof ItemInfoWithIcon)) {
749 return null;
750 }
751
752 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
753 int progressLevel = info.getProgressLevel();
754 if (progressLevel >= 100) {
755 setContentDescription(info.contentDescription != null
756 ? info.contentDescription : "");
757 } else if (progressLevel > 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800758 setDownloadStateContentDescription(info, progressLevel);
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800759 } else {
760 setContentDescription(getContext()
761 .getString(R.string.app_waiting_download_title, info.title));
762 }
763 if (mIcon != null) {
764 PreloadIconDrawable preloadIconDrawable;
765 if (mIcon instanceof PreloadIconDrawable) {
766 preloadIconDrawable = (PreloadIconDrawable) mIcon;
767 preloadIconDrawable.setLevel(progressLevel);
768 preloadIconDrawable.setIsDisabled(!info.isAppStartable());
Mario Bertschler230612f2017-09-27 17:05:21 -0700769 } else {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800770 preloadIconDrawable = makePreloadIcon();
771 setIcon(preloadIconDrawable);
Mario Bertschler230612f2017-09-27 17:05:21 -0700772 }
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800773 return preloadIconDrawable;
Chris Wren40c5ed32014-06-24 18:24:23 -0400774 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700775 return null;
Chris Wren40c5ed32014-06-24 18:24:23 -0400776 }
Sunny Goyal95abbb32014-08-04 10:53:22 -0700777
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800778 /**
779 * Creates a PreloadIconDrawable with the appropriate progress level without mutating this
780 * object.
781 */
782 @Nullable
783 public PreloadIconDrawable makePreloadIcon() {
784 if (!(getTag() instanceof ItemInfoWithIcon)) {
785 return null;
786 }
787
788 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
789 int progressLevel = info.getProgressLevel();
790 final PreloadIconDrawable preloadDrawable = newPendingIcon(getContext(), info);
791
792 preloadDrawable.setLevel(progressLevel);
793 preloadDrawable.setIsDisabled(!info.isAppStartable());
794
795 return preloadDrawable;
796 }
797
Tony Wickhamf34bee82018-12-03 18:11:39 -0800798 public void applyDotState(ItemInfo itemInfo, boolean animate) {
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800799 if (mIcon instanceof FastBitmapDrawable) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800800 boolean wasDotted = mDotInfo != null;
801 mDotInfo = mActivity.getDotInfoForItem(itemInfo);
802 boolean isDotted = mDotInfo != null;
803 float newDotScale = isDotted ? 1f : 0;
Samuel Fufac96fa242019-09-26 23:06:32 -0700804 if (mDisplay == DISPLAY_ALL_APPS) {
805 mDotRenderer = mActivity.getDeviceProfile().mDotRendererAllApps;
806 } else {
807 mDotRenderer = mActivity.getDeviceProfile().mDotRendererWorkSpace;
808 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800809 if (wasDotted || isDotted) {
810 // Animate when a dot is first added or when it is removed.
811 if (animate && (wasDotted ^ isDotted) && isShown()) {
812 animateDotScale(newDotScale);
Tony Wickham1237df02017-02-24 08:59:36 -0800813 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800814 cancelDotScaleAnim();
815 mDotParams.scale = newDotScale;
Tony Wickham1237df02017-02-24 08:59:36 -0800816 invalidate();
817 }
818 }
Andy Wickham56be73b2022-01-18 09:13:43 -0800819 if (!TextUtils.isEmpty(itemInfo.contentDescription)) {
vadimtda6dad52019-05-21 13:24:23 -0700820 if (itemInfo.isDisabled()) {
821 setContentDescription(getContext().getString(R.string.disabled_app_label,
822 itemInfo.contentDescription));
823 } else if (hasDot()) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800824 int count = mDotInfo.getNotificationCount();
Steven Ng707b1182021-09-13 11:54:58 +0100825 setContentDescription(
826 getAppLabelPluralString(itemInfo.contentDescription.toString(), count));
Tony Wickham305e9202018-01-23 17:46:47 -0800827 } else {
828 setContentDescription(itemInfo.contentDescription);
829 }
830 }
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800831 }
832 }
833
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800834 private void setDownloadStateContentDescription(ItemInfoWithIcon info, int progressLevel) {
835 if ((info.runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK)
836 != 0) {
837 String percentageString = NumberFormat.getPercentInstance()
838 .format(progressLevel * 0.01);
Federico Baron4eb502a2022-12-14 00:04:53 -0800839 if ((info.runtimeStatusFlags & FLAG_INSTALL_SESSION_ACTIVE) != 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800840 setContentDescription(getContext()
841 .getString(
842 R.string.app_installing_title, info.title, percentageString));
843 } else if ((info.runtimeStatusFlags
Federico Baron4eb502a2022-12-14 00:04:53 -0800844 & FLAG_INCREMENTAL_DOWNLOAD_ACTIVE) != 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800845 setContentDescription(getContext()
846 .getString(
847 R.string.app_downloading_title, info.title, percentageString));
848 }
849 }
850 }
851
Winson Chungb745afb2015-03-02 11:51:23 -0800852 /**
853 * Sets the icon for this view based on the layout direction.
854 */
Sunny Goyalc4c32692021-05-21 14:23:29 -0700855 protected void setIcon(FastBitmapDrawable icon) {
Tony17b7f9b2017-05-23 12:19:09 -0700856 if (mIsIconVisible) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700857 applyCompoundDrawables(icon);
Tony17b7f9b2017-05-23 12:19:09 -0700858 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700859 mIcon = icon;
Hyunyoung Songa2373852019-01-04 12:01:32 -0800860 if (mIcon != null) {
861 mIcon.setVisible(getWindowVisibility() == VISIBLE && isShown(), false);
862 }
Tony17b7f9b2017-05-23 12:19:09 -0700863 }
864
Jon Miranda9b78e192019-08-30 18:42:01 -0700865 @Override
Tony17b7f9b2017-05-23 12:19:09 -0700866 public void setIconVisible(boolean visible) {
867 mIsIconVisible = visible;
Sunny Goyal30ac97d2020-06-24 23:47:46 -0700868 if (!mIsIconVisible) {
869 resetIconScale();
870 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700871 Drawable icon = visible ? mIcon : new ColorDrawable(Color.TRANSPARENT);
Tony17b7f9b2017-05-23 12:19:09 -0700872 applyCompoundDrawables(icon);
Tony Wickham377ed3f2016-07-20 15:21:04 -0700873 }
874
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400875 protected boolean iconUpdateAnimationEnabled() {
876 return mEnableIconUpdateAnimation;
877 }
878
Tony Wickham377ed3f2016-07-20 15:21:04 -0700879 protected void applyCompoundDrawables(Drawable icon) {
Jon Mirandafe749972022-03-15 10:02:39 -0700880 if (icon == null) {
881 // Icon can be null when we use the BubbleTextView for text only.
882 return;
883 }
884
Sunny Goyal66dccad2018-03-19 12:00:51 -0700885 // If we had already set an icon before, disable relayout as the icon size is the
886 // same as before.
887 mDisableRelayout = mIcon != null;
888
889 icon.setBounds(0, 0, mIconSize, mIconSize);
Schneider Victor-tulias350b4622020-09-18 11:16:30 -0700890
891 updateIcon(icon);
892
893 // If the current icon is a placeholder color, animate its update.
Schneider Victor-tulias3ee70182020-10-21 14:01:53 -0400894 if (mIcon != null
895 && mIcon instanceof PlaceHolderIconDrawable
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400896 && iconUpdateAnimationEnabled()) {
Steven Nge92bc552021-02-10 17:10:15 +0000897 ((PlaceHolderIconDrawable) mIcon).animateIconUpdate(icon);
Winson Chungb745afb2015-03-02 11:51:23 -0800898 }
Schneider Victor-tulias350b4622020-09-18 11:16:30 -0700899
Sunny Goyal66dccad2018-03-19 12:00:51 -0700900 mDisableRelayout = false;
Winson Chungb745afb2015-03-02 11:51:23 -0800901 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700902
Sunny Goyal69b75642015-05-15 17:00:24 -0700903 @Override
904 public void requestLayout() {
905 if (!mDisableRelayout) {
906 super.requestLayout();
907 }
908 }
909
Sunny Goyal34b65272015-03-11 16:56:52 -0700910 /**
911 * Applies the item info if it is same as what the view is pointing to currently.
912 */
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800913 @Override
914 public void reapplyItemInfo(ItemInfoWithIcon info) {
Sunny Goyal34b65272015-03-11 16:56:52 -0700915 if (getTag() == info) {
916 mIconLoadRequest = null;
Sunny Goyal69b75642015-05-15 17:00:24 -0700917 mDisableRelayout = true;
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400918 mEnableIconUpdateAnimation = true;
Winsonc0880492015-08-21 11:16:27 -0700919
Jon Miranda7f522a22017-07-28 11:56:47 -0700920 // Optimization: Starting in N, pre-uploads the bitmap to RenderThread.
Sunny Goyal3808a692019-10-25 13:41:28 -0700921 info.bitmap.icon.prepareToDraw();
Jon Miranda7f522a22017-07-28 11:56:47 -0700922
Sunny Goyal34b65272015-03-11 16:56:52 -0700923 if (info instanceof AppInfo) {
924 applyFromApplicationInfo((AppInfo) info);
Sunny Goyal95899162019-03-27 16:03:06 -0700925 } else if (info instanceof WorkspaceItemInfo) {
926 applyFromWorkspaceItem((WorkspaceItemInfo) info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700927 mActivity.invalidateParent(info);
Sunny Goyalf0ff70a2022-05-11 07:23:10 -0700928 } else if (info != null) {
929 applyFromItemInfoWithIcon(info);
Sunny Goyal34b65272015-03-11 16:56:52 -0700930 }
Winsonc0880492015-08-21 11:16:27 -0700931
Sunny Goyal69b75642015-05-15 17:00:24 -0700932 mDisableRelayout = false;
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400933 mEnableIconUpdateAnimation = false;
Sunny Goyal34b65272015-03-11 16:56:52 -0700934 }
935 }
936
937 /**
938 * Verifies that the current icon is high-res otherwise posts a request to load the icon.
939 */
940 public void verifyHighRes() {
941 if (mIconLoadRequest != null) {
942 mIconLoadRequest.cancel();
943 mIconLoadRequest = null;
944 }
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800945 if (getTag() instanceof ItemInfoWithIcon) {
946 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Sunny Goyal2b787e52018-08-20 15:01:03 -0700947 if (info.usingLowResIcon()) {
Sunny Goyal87f784c2017-01-11 10:48:34 -0800948 mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache()
Sunny Goyal0e08f162015-05-12 11:32:39 -0700949 .updateIconInBackground(BubbleTextView.this, info);
950 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700951 }
952 }
Sunny Goyal4b6eb262015-05-14 19:24:40 -0700953
Jon Miranda47170112017-03-03 14:57:14 -0800954 public int getIconSize() {
955 return mIconSize;
956 }
Adam Cohen65086992020-02-19 08:40:49 -0800957
Brandon Dayauond3755f42022-08-29 11:48:27 -0700958 public boolean isDisplaySearchResult() {
959 return mDisplay == DISPLAY_SEARCH_RESULT ||
960 mDisplay == DISPLAY_SEARCH_RESULT_SMALL;
961 }
962
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700963 private void updateTranslation() {
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800964 super.setTranslationX(mTranslationForReorderBounce.x
965 + mTranslationForReorderPreview.x
Jagrut Desai560b0ea2023-02-16 15:40:44 -0800966 + mTranslationXForTaskbarAllAppsIcon
Nick Chameyev4dd41592021-08-27 14:11:53 +0100967 + mTranslationForMoveFromCenterAnimation.x
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800968 + mTranslationXForTaskbarAlignmentAnimation
969 + mTranslationXForTaskbarRevealAnimation
970 );
971 super.setTranslationY(mTranslationForReorderBounce.y
972 + mTranslationForReorderPreview.y
973 + mTranslationForMoveFromCenterAnimation.y
974 + mTranslationYForTaskbarAlignmentAnimation
975 + mTranslationYForTaskbarRevealAnimation);
Adam Cohend9162062020-03-24 16:35:35 -0700976 }
977
Jagrut Desai560b0ea2023-02-16 15:40:44 -0800978 /**
979 * Sets translationX for taskbar all apps icon
980 */
981 public void setTranslationXForTaskbarAllAppsIcon(float translationX) {
982 mTranslationXForTaskbarAllAppsIcon = translationX;
983 updateTranslation();
984 }
985
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700986 public void setReorderBounceOffset(float x, float y) {
987 mTranslationForReorderBounce.set(x, y);
988 updateTranslation();
Adam Cohend9162062020-03-24 16:35:35 -0700989 }
990
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700991 public void getReorderBounceOffset(PointF offset) {
992 offset.set(mTranslationForReorderBounce);
993 }
994
995 @Override
996 public void setReorderPreviewOffset(float x, float y) {
997 mTranslationForReorderPreview.set(x, y);
998 updateTranslation();
999 }
1000
1001 @Override
1002 public void getReorderPreviewOffset(PointF offset) {
1003 offset.set(mTranslationForReorderPreview);
1004 }
1005
1006 public void setReorderBounceScale(float scale) {
1007 mScaleForReorderBounce = scale;
Adam Cohend9162062020-03-24 16:35:35 -07001008 super.setScaleX(scale);
1009 super.setScaleY(scale);
1010 }
1011
Adam Cohen1d13c0b2020-04-21 16:29:12 -07001012 public float getReorderBounceScale() {
1013 return mScaleForReorderBounce;
Adam Cohend9162062020-03-24 16:35:35 -07001014 }
1015
Nick Chameyev4dd41592021-08-27 14:11:53 +01001016 /**
1017 * Sets translation values for move from center animation
1018 */
Nick Chameyev5e8dbe72021-07-26 14:56:50 +01001019 public void setTranslationForMoveFromCenterAnimation(float x, float y) {
1020 mTranslationForMoveFromCenterAnimation.set(x, y);
1021 updateTranslation();
1022 }
1023
Nick Chameyev4dd41592021-08-27 14:11:53 +01001024 /**
1025 * Sets translationX for taskbar to launcher alignment animation
1026 */
1027 public void setTranslationXForTaskbarAlignmentAnimation(float translationX) {
1028 mTranslationXForTaskbarAlignmentAnimation = translationX;
1029 updateTranslation();
1030 }
1031
1032 /**
1033 * Returns translationX value for taskbar to launcher alignment animation
1034 */
1035 public float getTranslationXForTaskbarAlignmentAnimation() {
1036 return mTranslationXForTaskbarAlignmentAnimation;
1037 }
1038
Jon Miranda13e9b9f2023-02-14 21:02:25 -08001039 /**
1040 * Sets translationX for taskbar to launcher alignment animation
1041 */
1042 public void setTranslationYForTaskbarAlignmentAnimation(float translationY) {
1043 mTranslationYForTaskbarAlignmentAnimation = translationY;
1044 updateTranslation();
1045 }
1046
1047 /**
1048 * Returns translationY value for taskbar to launcher alignment animation
1049 */
1050 public float getTranslationYForTaskbarAlignmentAnimation() {
1051 return mTranslationYForTaskbarAlignmentAnimation;
1052 }
1053
1054 /**
1055 * Sets translationX value for taskbar reveal animation
1056 */
1057 public void setTranslationXForTaskbarRevealAnimation(float translationX) {
1058 mTranslationXForTaskbarRevealAnimation = translationX;
1059 updateTranslation();
1060 }
1061
1062 /**
1063 * Returns translation values for taskbar reveal animation
1064 */
1065 public float getTranslationXForTaskbarRevealAnimation() {
1066 return mTranslationXForTaskbarRevealAnimation;
1067 }
1068
1069 /**
1070 * Sets translationY value for taskbar reveal animation
1071 */
1072 public void setTranslationYForTaskbarRevealAnimation(float translationY) {
1073 mTranslationYForTaskbarRevealAnimation = translationY;
1074 updateTranslation();
1075 }
1076
1077 /**
1078 * Returns translationY values for taskbar reveal animation
1079 */
1080 public float getTranslationYForTaskbarRevealAnimation() {
1081 return mTranslationYForTaskbarRevealAnimation;
1082 }
1083
Adam Cohend9162062020-03-24 16:35:35 -07001084 public View getView() {
1085 return this;
1086 }
1087
Adam Cohen65086992020-02-19 08:40:49 -08001088 @Override
1089 public int getViewType() {
1090 return DRAGGABLE_ICON;
1091 }
1092
1093 @Override
Adam Cohenc77bc452020-05-07 11:55:19 -07001094 public void getWorkspaceVisualDragBounds(Rect bounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -07001095 getIconBounds(mIconSize, bounds);
Adam Cohen65086992020-02-19 08:40:49 -08001096 }
1097
Adam Cohenc77bc452020-05-07 11:55:19 -07001098 public void getSourceVisualDragBounds(Rect bounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -07001099 getIconBounds(mIconSize, bounds);
Adam Cohenc77bc452020-05-07 11:55:19 -07001100 }
1101
Adam Cohen65086992020-02-19 08:40:49 -08001102 @Override
Samuel Fufa167210a2020-05-12 18:40:11 -07001103 public SafeCloseable prepareDrawDragView() {
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001104 resetIconScale();
Adam Cohen65086992020-02-19 08:40:49 -08001105 setForceHideDot(true);
Sunny Goyal8b9919d2021-04-07 14:45:17 -07001106 return () -> { };
Adam Cohen65086992020-02-19 08:40:49 -08001107 }
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001108
1109 private void resetIconScale() {
Sunny Goyal52f4c162022-04-23 16:02:03 +00001110 if (mIcon != null) {
1111 mIcon.resetScale();
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001112 }
1113 }
Schneider Victor-tulias350b4622020-09-18 11:16:30 -07001114
1115 private void updateIcon(Drawable newIcon) {
1116 if (mLayoutHorizontal) {
1117 setCompoundDrawablesRelative(newIcon, null, null, null);
1118 } else {
1119 setCompoundDrawables(null, newIcon, null, null);
1120 }
1121 }
Steven Ng707b1182021-09-13 11:54:58 +01001122
1123 private String getAppLabelPluralString(String appName, int notificationCount) {
1124 MessageFormat icuCountFormat = new MessageFormat(
1125 getResources().getString(R.string.dotted_app_label),
1126 Locale.getDefault());
1127 HashMap<String, Object> args = new HashMap();
1128 args.put("app_name", appName);
1129 args.put("count", notificationCount);
1130 return icuCountFormat.format(args);
1131 }
Sunny Goyalf0ff70a2022-05-11 07:23:10 -07001132
1133 /**
1134 * Starts a long press action and returns the corresponding pre-drag condition
1135 */
1136 public PreDragCondition startLongPressAction() {
1137 PopupContainerWithArrow popup = PopupContainerWithArrow.showForIcon(this);
1138 return popup != null ? popup.createPreDragCondition(true) : null;
1139 }
1140
1141 /**
1142 * Returns true if the view can show long-press popup
1143 */
1144 public boolean canShowLongPressPopup() {
1145 return getTag() instanceof ItemInfo && ShortcutUtil.supportsShortcuts((ItemInfo) getTag());
1146 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147}