blob: bd5c863283f2aca272a26326d57ce4b2ebc2b8ce [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) {
Sunny Goyal59f19152021-08-03 12:25:02 -0700379 boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER
380 || mDisplay == DISPLAY_TASKBAR;
Sunny Goyald872a972021-11-24 18:07:04 -0800381 int flags = useTheme ? FLAG_THEMED : 0;
382 if (mHideBadge) {
383 flags |= FLAG_NO_BADGE;
384 }
385 FastBitmapDrawable iconDrawable = info.newIcon(getContext(), flags);
James O'Leary1557ba32022-05-04 16:49:03 +0000386 mDotParams.appColor = iconDrawable.getIconColor();
387 mDotParams.dotColor = getContext().getResources()
James O'Learyede514f2022-06-06 16:01:45 -0400388 .getColor(android.R.color.system_accent3_200, getContext().getTheme());
Sunny Goyalf4204382016-07-13 10:46:07 -0700389 setIcon(iconDrawable);
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000390 applyLabel(info);
391 }
392
Hyunyoung Song5809a402021-02-02 01:19:18 -0800393 @UiThread
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000394 private void applyLabel(ItemInfoWithIcon info) {
Sunny Goyalf4204382016-07-13 10:46:07 -0700395 setText(info.title);
396 if (info.contentDescription != null) {
397 setContentDescription(info.isDisabled()
398 ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
399 : info.contentDescription);
400 }
401 }
402
Winson Chung7501adf2015-06-02 11:24:28 -0700403 /**
404 * Overrides the default long press timeout.
405 */
Tony2ca999c2018-09-24 17:24:51 -0400406 public void setLongPressTimeoutFactor(float longPressTimeoutFactor) {
407 mLongPressHelper.setLongPressTimeoutFactor(longPressTimeoutFactor);
Winson Chung7501adf2015-06-02 11:24:28 -0700408 }
Sunny Goyal0e08f162015-05-12 11:32:39 -0700409
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 @Override
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800411 public void refreshDrawableState() {
Sunny Goyal508da152014-08-14 10:53:27 -0700412 if (!mIgnorePressedStateChange) {
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800413 super.refreshDrawableState();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800414 }
Sunny Goyal508da152014-08-14 10:53:27 -0700415 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800416
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800417 @Override
418 protected int[] onCreateDrawableState(int extraSpace) {
419 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
420 if (mStayPressed) {
421 mergeDrawableStates(drawableState, STATE_PRESSED);
422 }
423 return drawableState;
424 }
425
Winson Chungb745afb2015-03-02 11:51:23 -0800426 /** Returns the icon for this view. */
Sunny Goyalc4c32692021-05-21 14:23:29 -0700427 public FastBitmapDrawable getIcon() {
Winson Chungb745afb2015-03-02 11:51:23 -0800428 return mIcon;
429 }
430
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700431 @Override
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800432 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700433 // ignore events if they happen in padding area
Sunny Goyal17feee82020-03-24 13:55:15 -0700434 if (event.getAction() == MotionEvent.ACTION_DOWN
Sunny Goyal44a3b202020-07-09 08:27:06 -0700435 && shouldIgnoreTouchDown(event.getX(), event.getY())) {
Samuel Fufa4a1d9b12019-09-19 17:28:00 -0700436 return false;
437 }
Sunny Goyal17feee82020-03-24 13:55:15 -0700438 if (isLongClickable()) {
439 super.onTouchEvent(event);
440 mLongPressHelper.onTouchEvent(event);
441 // Keep receiving the rest of the events
442 return true;
443 } else {
444 return super.onTouchEvent(event);
Mady Melloref044dd2015-06-02 15:35:07 -0700445 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800446 }
447
Sunny Goyal44a3b202020-07-09 08:27:06 -0700448 /**
449 * Returns true if the touch down at the provided position be ignored
450 */
451 protected boolean shouldIgnoreTouchDown(float x, float y) {
Tony Wickham42b03952021-08-31 10:41:36 -0700452 if (mDisplay == DISPLAY_TASKBAR) {
453 // Allow touching within padding on taskbar, given icon sizes are smaller.
454 return false;
455 }
Sunny Goyal44a3b202020-07-09 08:27:06 -0700456 return y < getPaddingTop()
457 || x < getPaddingLeft()
458 || y > getHeight() - getPaddingBottom()
459 || x > getWidth() - getPaddingRight();
460 }
461
Michael Jurkaddd62e92011-02-16 17:49:14 -0800462 void setStayPressed(boolean stayPressed) {
463 mStayPressed = stayPressed;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800464 refreshDrawableState();
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800465 }
466
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700467 @Override
Hyunyoung Songef468d82019-01-03 01:02:43 -0800468 public void onVisibilityAggregated(boolean isVisible) {
469 super.onVisibilityAggregated(isVisible);
470 if (mIcon != null) {
Hyunyoung Songa2373852019-01-04 12:01:32 -0800471 mIcon.setVisible(isVisible, false);
Hyunyoung Songef468d82019-01-03 01:02:43 -0800472 }
473 }
474
Tony Wickham8ac277e2021-05-24 15:47:38 -0700475 public void clearPressedBackground() {
Sunny Goyal508da152014-08-14 10:53:27 -0700476 setPressed(false);
477 setStayPressed(false);
478 }
479
480 @Override
Sunny Goyal508da152014-08-14 10:53:27 -0700481 public boolean onKeyUp(int keyCode, KeyEvent event) {
482 // Unlike touch events, keypress event propagate pressed state change immediately,
483 // without waiting for onClickHandler to execute. Disable pressed state changes here
484 // to avoid flickering.
485 mIgnorePressedStateChange = true;
486 boolean result = super.onKeyUp(keyCode, event);
Sunny Goyal508da152014-08-14 10:53:27 -0700487 mIgnorePressedStateChange = false;
Sunny Goyal2a76e3f2017-02-16 13:33:15 -0800488 refreshDrawableState();
Sunny Goyal508da152014-08-14 10:53:27 -0700489 return result;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800490 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800491
Sunny Goyal0d69cb62021-10-04 15:31:38 -0700492 @Override
493 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
494 super.onSizeChanged(w, h, oldw, oldh);
495 checkForEllipsis();
496 }
497
498 @Override
499 protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
500 super.onTextChanged(text, start, lengthBefore, lengthAfter);
501 checkForEllipsis();
502 }
503
504 private void checkForEllipsis() {
505 if (!ENABLE_ICON_LABEL_AUTO_SCALING.get()) {
506 return;
507 }
508 float width = getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight();
509 if (width <= 0) {
510 return;
511 }
512 setLetterSpacing(0);
513
514 String text = getText().toString();
515 TextPaint paint = getPaint();
516 if (paint.measureText(text) < width) {
517 return;
518 }
519
520 float spacing = findBestSpacingValue(paint, text, width, MIN_LETTER_SPACING);
521 // Reset the paint value so that the call to TextView does appropriate diff.
522 paint.setLetterSpacing(0);
523 setLetterSpacing(spacing);
524 }
525
526 /**
527 * Find the appropriate text spacing to display the provided text
528 * @param paint the paint used by the text view
529 * @param text the text to display
530 * @param allowedWidthPx available space to render the text
531 * @param minSpacingEm minimum spacing allowed between characters
532 * @return the final textSpacing value
533 *
534 * @see #setLetterSpacing(float)
535 */
536 private float findBestSpacingValue(TextPaint paint, String text, float allowedWidthPx,
537 float minSpacingEm) {
538 paint.setLetterSpacing(minSpacingEm);
539 if (paint.measureText(text) > allowedWidthPx) {
540 // If there is no result at high limit, we can do anything more
541 return minSpacingEm;
542 }
543
544 float lowLimit = 0;
545 float highLimit = minSpacingEm;
546
547 for (int i = 0; i < MAX_SEARCH_LOOP_COUNT; i++) {
548 float value = (lowLimit + highLimit) / 2;
549 paint.setLetterSpacing(value);
550 if (paint.measureText(text) < allowedWidthPx) {
551 highLimit = value;
552 } else {
553 lowLimit = value;
554 }
555 }
556
557 // At the end error on the higher side
558 return highLimit;
559 }
560
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700561 @SuppressWarnings("wrongcall")
Tony Wickhamf34bee82018-12-03 18:11:39 -0800562 protected void drawWithoutDot(Canvas canvas) {
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700563 super.onDraw(canvas);
564 }
565
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 @Override
Sunny Goyal9314b7c2017-06-23 10:36:27 -0700567 public void onDraw(Canvas canvas) {
568 super.onDraw(canvas);
Tony Wickham22a5a682020-11-02 17:04:58 -0800569 drawDotIfNecessary(canvas);
Samuel Fufa314761a2020-10-14 10:15:07 -0700570 }
571
Tony Wickham1237df02017-02-24 08:59:36 -0800572 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800573 * Draws the notification dot in the top right corner of the icon bounds.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700574 *
Tony Wickham1237df02017-02-24 08:59:36 -0800575 * @param canvas The canvas to draw to.
576 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800577 protected void drawDotIfNecessary(Canvas canvas) {
578 if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800579 getIconBounds(mDotParams.iconBounds);
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700580 Utilities.scaleRectAboutCenter(mDotParams.iconBounds,
581 IconShape.getNormalizationScale());
Tony Wickham1237df02017-02-24 08:59:36 -0800582 final int scrollX = getScrollX();
583 final int scrollY = getScrollY();
584 canvas.translate(scrollX, scrollY);
Tony Wickham8912b042018-11-29 15:28:53 -0800585 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham1237df02017-02-24 08:59:36 -0800586 canvas.translate(-scrollX, -scrollY);
587 }
588 }
589
Jon Miranda9b78e192019-08-30 18:42:01 -0700590 @Override
591 public void setForceHideDot(boolean forceHideDot) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800592 if (mForceHideDot == forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800593 return;
594 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800595 mForceHideDot = forceHideDot;
Tony Wickham1237df02017-02-24 08:59:36 -0800596
Tony Wickhamf34bee82018-12-03 18:11:39 -0800597 if (forceHideDot) {
Tony Wickham1237df02017-02-24 08:59:36 -0800598 invalidate();
Tony Wickhamf34bee82018-12-03 18:11:39 -0800599 } else if (hasDot()) {
600 animateDotScale(0, 1);
Tony Wickham1237df02017-02-24 08:59:36 -0800601 }
602 }
603
Tony Wickhamf34bee82018-12-03 18:11:39 -0800604 private boolean hasDot() {
605 return mDotInfo != null;
Tony Wickham1237df02017-02-24 08:59:36 -0800606 }
607
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700608 /**
609 * Get the icon bounds on the view depending on the layout type.
610 */
Tony Wickham1237df02017-02-24 08:59:36 -0800611 public void getIconBounds(Rect outBounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700612 getIconBounds(mIconSize, outBounds);
Tony05d98c22018-07-23 08:01:15 -0700613 }
614
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700615 /**
616 * Get the icon bounds on the view depending on the layout type.
617 */
618 public void getIconBounds(int iconSize, Rect outBounds) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700619 outBounds.set(0, 0, iconSize, iconSize);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700620 if (mLayoutHorizontal) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700621 int top = (getHeight() - iconSize) / 2;
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700622 if (mIsRtl) {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700623 outBounds.offsetTo(getWidth() - iconSize - getPaddingRight(), top);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700624 } else {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700625 outBounds.offsetTo(getPaddingLeft(), top);
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700626 }
627 } else {
Sunny Goyal47d4d812022-11-04 16:43:42 -0700628 outBounds.offset((getWidth() - iconSize) / 2, getPaddingTop());
Hyunyoung Songc2f024b2021-11-03 23:16:53 -0700629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400631
Jon Miranda228877d2021-02-09 11:05:00 -0500632 /**
633 * Sets whether to vertically center the content.
634 */
635 public void setCenterVertically(boolean centerVertically) {
636 mCenterVertically = centerVertically;
637 }
638
Joe Onorato9c1289c2009-08-17 11:03:03 -0400639 @Override
Winson1f064272016-07-18 17:18:02 -0700640 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
641 if (mCenterVertically) {
642 Paint.FontMetrics fm = getPaint().getFontMetrics();
643 int cellHeightPx = mIconSize + getCompoundDrawablePadding() +
644 (int) Math.ceil(fm.bottom - fm.top);
645 int height = MeasureSpec.getSize(heightMeasureSpec);
646 setPadding(getPaddingLeft(), (height - cellHeightPx) / 2, getPaddingRight(),
647 getPaddingBottom());
648 }
649 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
650 }
651
652 @Override
Adam Cohen477828c2013-09-20 12:05:49 -0700653 public void setTextColor(int color) {
654 mTextColor = color;
Jon Spivack68862142021-10-28 18:37:19 -0700655 mTextColorStateList = null;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700656 super.setTextColor(getModifiedColor());
Adam Cohen477828c2013-09-20 12:05:49 -0700657 }
658
Adam Cohen96bb7982014-07-07 11:58:56 -0700659 @Override
660 public void setTextColor(ColorStateList colors) {
661 mTextColor = colors.getDefaultColor();
Jon Spivack68862142021-10-28 18:37:19 -0700662 mTextColorStateList = colors;
Sunny Goyaled7a6932018-04-13 11:41:50 -0700663 if (Float.compare(mTextAlpha, 1) == 0) {
664 super.setTextColor(colors);
665 } else {
666 super.setTextColor(getModifiedColor());
667 }
Adam Cohen477828c2013-09-20 12:05:49 -0700668 }
669
Tony7308cde2017-06-27 22:38:33 -0700670 public boolean shouldTextBeVisible() {
671 // Text should be visible everywhere but the hotseat.
672 Object tag = getParent() instanceof FolderIcon ? ((View) getParent()).getTag() : getTag();
673 ItemInfo info = tag instanceof ItemInfo ? (ItemInfo) tag : null;
Samuel Fufaefb665d2019-10-30 13:24:14 -0700674 return info == null || (info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT
675 && info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION);
Tony7308cde2017-06-27 22:38:33 -0700676 }
677
Winson Chung5f8afe62013-08-12 16:19:28 -0700678 public void setTextVisibility(boolean visible) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700679 setTextAlpha(visible ? 1 : 0);
680 }
681
682 private void setTextAlpha(float alpha) {
683 mTextAlpha = alpha;
Jon Spivack68862142021-10-28 18:37:19 -0700684 if (mTextColorStateList != null) {
685 setTextColor(mTextColorStateList);
686 } else {
687 super.setTextColor(getModifiedColor());
688 }
Sunny Goyaled7a6932018-04-13 11:41:50 -0700689 }
690
691 private int getModifiedColor() {
692 if (mTextAlpha == 0) {
693 // Special case to prevent text shadows in high contrast mode
694 return Color.TRANSPARENT;
Winson Chung5f8afe62013-08-12 16:19:28 -0700695 }
Sunny Goyal066ace12018-11-05 11:08:31 -0800696 return setColorAlphaBound(mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
Tony8f402802017-06-16 17:24:54 -0700697 }
698
699 /**
700 * Creates an animator to fade the text in or out.
Samuel Fufad6bacdc2020-08-23 21:56:07 -0700701 *
Tony8f402802017-06-16 17:24:54 -0700702 * @param fadeIn Whether the text should fade in or fade out.
703 */
Sunny Goyal4e5a8782017-06-23 09:34:06 -0700704 public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) {
Sunny Goyaled7a6932018-04-13 11:41:50 -0700705 float toAlpha = shouldTextBeVisible() && fadeIn ? 1 : 0;
Jon Miranda83cdca62019-04-15 13:01:05 -0700706 return ObjectAnimator.ofFloat(this, TEXT_ALPHA_PROPERTY, toAlpha);
Tony8f402802017-06-16 17:24:54 -0700707 }
708
Winson Chungaffd7b42010-08-20 15:11:56 -0700709 @Override
Winson Chung88f33452012-02-23 15:23:44 -0800710 public void cancelLongPress() {
711 super.cancelLongPress();
Winson Chung88f33452012-02-23 15:23:44 -0800712 mLongPressHelper.cancelLongPress();
713 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500714
Samuel Fufac2820182021-01-22 11:47:25 -0600715 /**
716 * Applies the loading progress value to the progress bar.
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000717 *
718 * If this app is installing, the progress bar will be updated with the installation progress.
719 * If this app is installed and downloading incrementally, the progress bar will be updated
720 * with the total download progress.
721 */
Federico Baron4eb502a2022-12-14 00:04:53 -0800722 public void applyLoadingState(PreloadIconDrawable icon) {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800723 if (getTag() instanceof ItemInfoWithIcon) {
Sunny Goyal95899162019-03-27 16:03:06 -0700724 WorkspaceItemInfo info = (WorkspaceItemInfo) getTag();
Federico Baron4eb502a2022-12-14 00:04:53 -0800725 if ((info.runtimeStatusFlags & FLAG_INCREMENTAL_DOWNLOAD_ACTIVE) != 0
726 || info.hasPromiseIconUi()
727 || (info.runtimeStatusFlags & FLAG_INSTALL_SESSION_ACTIVE) != 0
728 || (ENABLE_DOWNLOAD_APP_UX_V2.get() && icon != null)) {
729 updateProgressBarUi(icon);
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700730 }
731 }
732 }
733
Federico Baron4eb502a2022-12-14 00:04:53 -0800734 private void updateProgressBarUi(PreloadIconDrawable oldIcon) {
735 FastBitmapDrawable originalIcon = mIcon;
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800736 PreloadIconDrawable preloadDrawable = applyProgressLevel();
Federico Baron4eb502a2022-12-14 00:04:53 -0800737 if (preloadDrawable != null && oldIcon != null) {
738 preloadDrawable.maybePerformFinishedAnimation(oldIcon, () -> setIcon(originalIcon));
Schneider Victor-tulias6a5f4312021-01-12 19:30:02 +0000739 }
740 }
741
742 /** Applies the given progress level to the this icon's progress bar. */
743 @Nullable
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800744 public PreloadIconDrawable applyProgressLevel() {
745 if (!(getTag() instanceof ItemInfoWithIcon)) {
746 return null;
747 }
748
749 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
750 int progressLevel = info.getProgressLevel();
751 if (progressLevel >= 100) {
752 setContentDescription(info.contentDescription != null
753 ? info.contentDescription : "");
754 } else if (progressLevel > 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800755 setDownloadStateContentDescription(info, progressLevel);
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800756 } else {
757 setContentDescription(getContext()
758 .getString(R.string.app_waiting_download_title, info.title));
759 }
760 if (mIcon != null) {
761 PreloadIconDrawable preloadIconDrawable;
762 if (mIcon instanceof PreloadIconDrawable) {
763 preloadIconDrawable = (PreloadIconDrawable) mIcon;
764 preloadIconDrawable.setLevel(progressLevel);
765 preloadIconDrawable.setIsDisabled(!info.isAppStartable());
Mario Bertschler230612f2017-09-27 17:05:21 -0700766 } else {
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800767 preloadIconDrawable = makePreloadIcon();
768 setIcon(preloadIconDrawable);
Mario Bertschler230612f2017-09-27 17:05:21 -0700769 }
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800770 return preloadIconDrawable;
Chris Wren40c5ed32014-06-24 18:24:23 -0400771 }
Mario Bertschler08ffaae2017-03-20 11:30:27 -0700772 return null;
Chris Wren40c5ed32014-06-24 18:24:23 -0400773 }
Sunny Goyal95abbb32014-08-04 10:53:22 -0700774
Schneider Victor-tuliasb40b98d2021-01-21 14:41:07 -0800775 /**
776 * Creates a PreloadIconDrawable with the appropriate progress level without mutating this
777 * object.
778 */
779 @Nullable
780 public PreloadIconDrawable makePreloadIcon() {
781 if (!(getTag() instanceof ItemInfoWithIcon)) {
782 return null;
783 }
784
785 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
786 int progressLevel = info.getProgressLevel();
787 final PreloadIconDrawable preloadDrawable = newPendingIcon(getContext(), info);
788
789 preloadDrawable.setLevel(progressLevel);
790 preloadDrawable.setIsDisabled(!info.isAppStartable());
791
792 return preloadDrawable;
793 }
794
Tony Wickhamf34bee82018-12-03 18:11:39 -0800795 public void applyDotState(ItemInfo itemInfo, boolean animate) {
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800796 if (mIcon instanceof FastBitmapDrawable) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800797 boolean wasDotted = mDotInfo != null;
798 mDotInfo = mActivity.getDotInfoForItem(itemInfo);
799 boolean isDotted = mDotInfo != null;
800 float newDotScale = isDotted ? 1f : 0;
Samuel Fufac96fa242019-09-26 23:06:32 -0700801 if (mDisplay == DISPLAY_ALL_APPS) {
802 mDotRenderer = mActivity.getDeviceProfile().mDotRendererAllApps;
803 } else {
804 mDotRenderer = mActivity.getDeviceProfile().mDotRendererWorkSpace;
805 }
Tony Wickhamf34bee82018-12-03 18:11:39 -0800806 if (wasDotted || isDotted) {
807 // Animate when a dot is first added or when it is removed.
808 if (animate && (wasDotted ^ isDotted) && isShown()) {
809 animateDotScale(newDotScale);
Tony Wickham1237df02017-02-24 08:59:36 -0800810 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800811 cancelDotScaleAnim();
812 mDotParams.scale = newDotScale;
Tony Wickham1237df02017-02-24 08:59:36 -0800813 invalidate();
814 }
815 }
Andy Wickham56be73b2022-01-18 09:13:43 -0800816 if (!TextUtils.isEmpty(itemInfo.contentDescription)) {
vadimtda6dad52019-05-21 13:24:23 -0700817 if (itemInfo.isDisabled()) {
818 setContentDescription(getContext().getString(R.string.disabled_app_label,
819 itemInfo.contentDescription));
820 } else if (hasDot()) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800821 int count = mDotInfo.getNotificationCount();
Steven Ng707b1182021-09-13 11:54:58 +0100822 setContentDescription(
823 getAppLabelPluralString(itemInfo.contentDescription.toString(), count));
Tony Wickham305e9202018-01-23 17:46:47 -0800824 } else {
825 setContentDescription(itemInfo.contentDescription);
826 }
827 }
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800828 }
829 }
830
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800831 private void setDownloadStateContentDescription(ItemInfoWithIcon info, int progressLevel) {
832 if ((info.runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK)
833 != 0) {
834 String percentageString = NumberFormat.getPercentInstance()
835 .format(progressLevel * 0.01);
Federico Baron4eb502a2022-12-14 00:04:53 -0800836 if ((info.runtimeStatusFlags & FLAG_INSTALL_SESSION_ACTIVE) != 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800837 setContentDescription(getContext()
838 .getString(
839 R.string.app_installing_title, info.title, percentageString));
840 } else if ((info.runtimeStatusFlags
Federico Baron4eb502a2022-12-14 00:04:53 -0800841 & FLAG_INCREMENTAL_DOWNLOAD_ACTIVE) != 0) {
Schneider Victor-tulias5f7f4cb2021-01-28 13:51:23 -0800842 setContentDescription(getContext()
843 .getString(
844 R.string.app_downloading_title, info.title, percentageString));
845 }
846 }
847 }
848
Winson Chungb745afb2015-03-02 11:51:23 -0800849 /**
850 * Sets the icon for this view based on the layout direction.
851 */
Sunny Goyalc4c32692021-05-21 14:23:29 -0700852 protected void setIcon(FastBitmapDrawable icon) {
Tony17b7f9b2017-05-23 12:19:09 -0700853 if (mIsIconVisible) {
Sunny Goyal66dccad2018-03-19 12:00:51 -0700854 applyCompoundDrawables(icon);
Tony17b7f9b2017-05-23 12:19:09 -0700855 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700856 mIcon = icon;
Hyunyoung Songa2373852019-01-04 12:01:32 -0800857 if (mIcon != null) {
858 mIcon.setVisible(getWindowVisibility() == VISIBLE && isShown(), false);
859 }
Tony17b7f9b2017-05-23 12:19:09 -0700860 }
861
Jon Miranda9b78e192019-08-30 18:42:01 -0700862 @Override
Tony17b7f9b2017-05-23 12:19:09 -0700863 public void setIconVisible(boolean visible) {
864 mIsIconVisible = visible;
Sunny Goyal30ac97d2020-06-24 23:47:46 -0700865 if (!mIsIconVisible) {
866 resetIconScale();
867 }
Sunny Goyal66dccad2018-03-19 12:00:51 -0700868 Drawable icon = visible ? mIcon : new ColorDrawable(Color.TRANSPARENT);
Tony17b7f9b2017-05-23 12:19:09 -0700869 applyCompoundDrawables(icon);
Tony Wickham377ed3f2016-07-20 15:21:04 -0700870 }
871
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400872 protected boolean iconUpdateAnimationEnabled() {
873 return mEnableIconUpdateAnimation;
874 }
875
Tony Wickham377ed3f2016-07-20 15:21:04 -0700876 protected void applyCompoundDrawables(Drawable icon) {
Jon Mirandafe749972022-03-15 10:02:39 -0700877 if (icon == null) {
878 // Icon can be null when we use the BubbleTextView for text only.
879 return;
880 }
881
Sunny Goyal66dccad2018-03-19 12:00:51 -0700882 // If we had already set an icon before, disable relayout as the icon size is the
883 // same as before.
884 mDisableRelayout = mIcon != null;
885
886 icon.setBounds(0, 0, mIconSize, mIconSize);
Schneider Victor-tulias350b4622020-09-18 11:16:30 -0700887
888 updateIcon(icon);
889
890 // If the current icon is a placeholder color, animate its update.
Schneider Victor-tulias3ee70182020-10-21 14:01:53 -0400891 if (mIcon != null
892 && mIcon instanceof PlaceHolderIconDrawable
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400893 && iconUpdateAnimationEnabled()) {
Steven Nge92bc552021-02-10 17:10:15 +0000894 ((PlaceHolderIconDrawable) mIcon).animateIconUpdate(icon);
Winson Chungb745afb2015-03-02 11:51:23 -0800895 }
Schneider Victor-tulias350b4622020-09-18 11:16:30 -0700896
Sunny Goyal66dccad2018-03-19 12:00:51 -0700897 mDisableRelayout = false;
Winson Chungb745afb2015-03-02 11:51:23 -0800898 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700899
Sunny Goyal69b75642015-05-15 17:00:24 -0700900 @Override
901 public void requestLayout() {
902 if (!mDisableRelayout) {
903 super.requestLayout();
904 }
905 }
906
Sunny Goyal34b65272015-03-11 16:56:52 -0700907 /**
908 * Applies the item info if it is same as what the view is pointing to currently.
909 */
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800910 @Override
911 public void reapplyItemInfo(ItemInfoWithIcon info) {
Sunny Goyal34b65272015-03-11 16:56:52 -0700912 if (getTag() == info) {
913 mIconLoadRequest = null;
Sunny Goyal69b75642015-05-15 17:00:24 -0700914 mDisableRelayout = true;
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400915 mEnableIconUpdateAnimation = true;
Winsonc0880492015-08-21 11:16:27 -0700916
Jon Miranda7f522a22017-07-28 11:56:47 -0700917 // Optimization: Starting in N, pre-uploads the bitmap to RenderThread.
Sunny Goyal3808a692019-10-25 13:41:28 -0700918 info.bitmap.icon.prepareToDraw();
Jon Miranda7f522a22017-07-28 11:56:47 -0700919
Sunny Goyal34b65272015-03-11 16:56:52 -0700920 if (info instanceof AppInfo) {
921 applyFromApplicationInfo((AppInfo) info);
Sunny Goyal95899162019-03-27 16:03:06 -0700922 } else if (info instanceof WorkspaceItemInfo) {
923 applyFromWorkspaceItem((WorkspaceItemInfo) info);
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700924 mActivity.invalidateParent(info);
Sunny Goyalf0ff70a2022-05-11 07:23:10 -0700925 } else if (info != null) {
926 applyFromItemInfoWithIcon(info);
Sunny Goyal34b65272015-03-11 16:56:52 -0700927 }
Winsonc0880492015-08-21 11:16:27 -0700928
Sunny Goyal69b75642015-05-15 17:00:24 -0700929 mDisableRelayout = false;
Schneider Victor-tulias7bbec502020-10-29 11:39:24 -0400930 mEnableIconUpdateAnimation = false;
Sunny Goyal34b65272015-03-11 16:56:52 -0700931 }
932 }
933
934 /**
935 * Verifies that the current icon is high-res otherwise posts a request to load the icon.
936 */
937 public void verifyHighRes() {
938 if (mIconLoadRequest != null) {
939 mIconLoadRequest.cancel();
940 mIconLoadRequest = null;
941 }
Sunny Goyal2d7cca12017-01-03 16:52:43 -0800942 if (getTag() instanceof ItemInfoWithIcon) {
943 ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
Sunny Goyal2b787e52018-08-20 15:01:03 -0700944 if (info.usingLowResIcon()) {
Sunny Goyal87f784c2017-01-11 10:48:34 -0800945 mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache()
Sunny Goyal0e08f162015-05-12 11:32:39 -0700946 .updateIconInBackground(BubbleTextView.this, info);
947 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700948 }
949 }
Sunny Goyal4b6eb262015-05-14 19:24:40 -0700950
Jon Miranda47170112017-03-03 14:57:14 -0800951 public int getIconSize() {
952 return mIconSize;
953 }
Adam Cohen65086992020-02-19 08:40:49 -0800954
Brandon Dayauond3755f42022-08-29 11:48:27 -0700955 public boolean isDisplaySearchResult() {
956 return mDisplay == DISPLAY_SEARCH_RESULT ||
957 mDisplay == DISPLAY_SEARCH_RESULT_SMALL;
958 }
959
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700960 private void updateTranslation() {
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800961 super.setTranslationX(mTranslationForReorderBounce.x
962 + mTranslationForReorderPreview.x
Jagrut Desai560b0ea2023-02-16 15:40:44 -0800963 + mTranslationXForTaskbarAllAppsIcon
Nick Chameyev4dd41592021-08-27 14:11:53 +0100964 + mTranslationForMoveFromCenterAnimation.x
Jon Miranda13e9b9f2023-02-14 21:02:25 -0800965 + mTranslationXForTaskbarAlignmentAnimation
966 + mTranslationXForTaskbarRevealAnimation
967 );
968 super.setTranslationY(mTranslationForReorderBounce.y
969 + mTranslationForReorderPreview.y
970 + mTranslationForMoveFromCenterAnimation.y
971 + mTranslationYForTaskbarAlignmentAnimation
972 + mTranslationYForTaskbarRevealAnimation);
Adam Cohend9162062020-03-24 16:35:35 -0700973 }
974
Jagrut Desai560b0ea2023-02-16 15:40:44 -0800975 /**
976 * Sets translationX for taskbar all apps icon
977 */
978 public void setTranslationXForTaskbarAllAppsIcon(float translationX) {
979 mTranslationXForTaskbarAllAppsIcon = translationX;
980 updateTranslation();
981 }
982
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700983 public void setReorderBounceOffset(float x, float y) {
984 mTranslationForReorderBounce.set(x, y);
985 updateTranslation();
Adam Cohend9162062020-03-24 16:35:35 -0700986 }
987
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700988 public void getReorderBounceOffset(PointF offset) {
989 offset.set(mTranslationForReorderBounce);
990 }
991
992 @Override
993 public void setReorderPreviewOffset(float x, float y) {
994 mTranslationForReorderPreview.set(x, y);
995 updateTranslation();
996 }
997
998 @Override
999 public void getReorderPreviewOffset(PointF offset) {
1000 offset.set(mTranslationForReorderPreview);
1001 }
1002
1003 public void setReorderBounceScale(float scale) {
1004 mScaleForReorderBounce = scale;
Adam Cohend9162062020-03-24 16:35:35 -07001005 super.setScaleX(scale);
1006 super.setScaleY(scale);
1007 }
1008
Adam Cohen1d13c0b2020-04-21 16:29:12 -07001009 public float getReorderBounceScale() {
1010 return mScaleForReorderBounce;
Adam Cohend9162062020-03-24 16:35:35 -07001011 }
1012
Nick Chameyev4dd41592021-08-27 14:11:53 +01001013 /**
1014 * Sets translation values for move from center animation
1015 */
Nick Chameyev5e8dbe72021-07-26 14:56:50 +01001016 public void setTranslationForMoveFromCenterAnimation(float x, float y) {
1017 mTranslationForMoveFromCenterAnimation.set(x, y);
1018 updateTranslation();
1019 }
1020
Nick Chameyev4dd41592021-08-27 14:11:53 +01001021 /**
1022 * Sets translationX for taskbar to launcher alignment animation
1023 */
1024 public void setTranslationXForTaskbarAlignmentAnimation(float translationX) {
1025 mTranslationXForTaskbarAlignmentAnimation = translationX;
1026 updateTranslation();
1027 }
1028
1029 /**
1030 * Returns translationX value for taskbar to launcher alignment animation
1031 */
1032 public float getTranslationXForTaskbarAlignmentAnimation() {
1033 return mTranslationXForTaskbarAlignmentAnimation;
1034 }
1035
Jon Miranda13e9b9f2023-02-14 21:02:25 -08001036 /**
1037 * Sets translationX for taskbar to launcher alignment animation
1038 */
1039 public void setTranslationYForTaskbarAlignmentAnimation(float translationY) {
1040 mTranslationYForTaskbarAlignmentAnimation = translationY;
1041 updateTranslation();
1042 }
1043
1044 /**
1045 * Returns translationY value for taskbar to launcher alignment animation
1046 */
1047 public float getTranslationYForTaskbarAlignmentAnimation() {
1048 return mTranslationYForTaskbarAlignmentAnimation;
1049 }
1050
1051 /**
1052 * Sets translationX value for taskbar reveal animation
1053 */
1054 public void setTranslationXForTaskbarRevealAnimation(float translationX) {
1055 mTranslationXForTaskbarRevealAnimation = translationX;
1056 updateTranslation();
1057 }
1058
1059 /**
1060 * Returns translation values for taskbar reveal animation
1061 */
1062 public float getTranslationXForTaskbarRevealAnimation() {
1063 return mTranslationXForTaskbarRevealAnimation;
1064 }
1065
1066 /**
1067 * Sets translationY value for taskbar reveal animation
1068 */
1069 public void setTranslationYForTaskbarRevealAnimation(float translationY) {
1070 mTranslationYForTaskbarRevealAnimation = translationY;
1071 updateTranslation();
1072 }
1073
1074 /**
1075 * Returns translationY values for taskbar reveal animation
1076 */
1077 public float getTranslationYForTaskbarRevealAnimation() {
1078 return mTranslationYForTaskbarRevealAnimation;
1079 }
1080
Adam Cohend9162062020-03-24 16:35:35 -07001081 public View getView() {
1082 return this;
1083 }
1084
Adam Cohen65086992020-02-19 08:40:49 -08001085 @Override
1086 public int getViewType() {
1087 return DRAGGABLE_ICON;
1088 }
1089
1090 @Override
Adam Cohenc77bc452020-05-07 11:55:19 -07001091 public void getWorkspaceVisualDragBounds(Rect bounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -07001092 getIconBounds(mIconSize, bounds);
Adam Cohen65086992020-02-19 08:40:49 -08001093 }
1094
Adam Cohenc77bc452020-05-07 11:55:19 -07001095 public void getSourceVisualDragBounds(Rect bounds) {
Hyunyoung Songc2f024b2021-11-03 23:16:53 -07001096 getIconBounds(mIconSize, bounds);
Adam Cohenc77bc452020-05-07 11:55:19 -07001097 }
1098
Adam Cohen65086992020-02-19 08:40:49 -08001099 @Override
Samuel Fufa167210a2020-05-12 18:40:11 -07001100 public SafeCloseable prepareDrawDragView() {
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001101 resetIconScale();
Adam Cohen65086992020-02-19 08:40:49 -08001102 setForceHideDot(true);
Sunny Goyal8b9919d2021-04-07 14:45:17 -07001103 return () -> { };
Adam Cohen65086992020-02-19 08:40:49 -08001104 }
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001105
1106 private void resetIconScale() {
Sunny Goyal52f4c162022-04-23 16:02:03 +00001107 if (mIcon != null) {
1108 mIcon.resetScale();
Sunny Goyal30ac97d2020-06-24 23:47:46 -07001109 }
1110 }
Schneider Victor-tulias350b4622020-09-18 11:16:30 -07001111
1112 private void updateIcon(Drawable newIcon) {
1113 if (mLayoutHorizontal) {
1114 setCompoundDrawablesRelative(newIcon, null, null, null);
1115 } else {
1116 setCompoundDrawables(null, newIcon, null, null);
1117 }
1118 }
Steven Ng707b1182021-09-13 11:54:58 +01001119
1120 private String getAppLabelPluralString(String appName, int notificationCount) {
1121 MessageFormat icuCountFormat = new MessageFormat(
1122 getResources().getString(R.string.dotted_app_label),
1123 Locale.getDefault());
1124 HashMap<String, Object> args = new HashMap();
1125 args.put("app_name", appName);
1126 args.put("count", notificationCount);
1127 return icuCountFormat.format(args);
1128 }
Sunny Goyalf0ff70a2022-05-11 07:23:10 -07001129
1130 /**
1131 * Starts a long press action and returns the corresponding pre-drag condition
1132 */
1133 public PreDragCondition startLongPressAction() {
1134 PopupContainerWithArrow popup = PopupContainerWithArrow.showForIcon(this);
1135 return popup != null ? popup.createPreDragCondition(true) : null;
1136 }
1137
1138 /**
1139 * Returns true if the view can show long-press popup
1140 */
1141 public boolean canShowLongPressPopup() {
1142 return getTag() instanceof ItemInfo && ShortcutUtil.supportsShortcuts((ItemInfo) getTag());
1143 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001144}