blob: 2b0da434a9c9454a28f6fce834e54cce1b332126 [file] [log] [blame]
Winson Chung61fa4192011-06-12 15:15:29 -07001/*
2 * Copyright (C) 2010 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;
Winson Chung61fa4192011-06-12 15:15:29 -070018
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080019import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
20
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070021import static com.android.launcher3.LauncherState.NORMAL;
Sunny Goyalaeb16432017-10-16 11:46:41 -070022
Sunny Goyal3a644ed2015-05-21 10:28:02 -070023import android.animation.AnimatorSet;
24import android.animation.FloatArrayEvaluator;
Sunny Goyalfe0d1f22015-04-28 22:01:31 -070025import android.animation.ObjectAnimator;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070026import android.animation.ValueAnimator;
Winson Chung61fa4192011-06-12 15:15:29 -070027import android.content.Context;
Sunny Goyalfa401a12015-04-10 13:45:42 -070028import android.content.res.ColorStateList;
Tony Wickham855b1b52016-03-28 16:56:30 -070029import android.content.res.Resources;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070030import android.graphics.ColorMatrix;
31import android.graphics.ColorMatrixColorFilter;
Winson Chung61967cb2012-02-28 18:11:33 -080032import android.graphics.Rect;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070033import android.graphics.drawable.Drawable;
Jon Mirandabfaa4a42017-08-21 15:31:51 -070034import android.text.TextUtils;
Winson Chung61fa4192011-06-12 15:15:29 -070035import android.util.AttributeSet;
Sunny Goyal55bdeed2018-09-18 16:17:22 -070036import android.util.Property;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080037import android.view.LayoutInflater;
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -080038import android.view.View;
Sunny Goyal1a70cef2015-04-22 11:29:51 -070039import android.view.View.OnClickListener;
Sunny Goyale78e3d72015-09-24 11:23:31 -070040import android.view.accessibility.AccessibilityEvent;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080041import android.widget.PopupWindow;
Adam Cohend4d7aa52011-07-19 21:47:37 -070042import android.widget.TextView;
Winson Chung61fa4192011-06-12 15:15:29 -070043
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -070044import com.android.launcher3.anim.Interpolators;
Vadim Tryshevfedca432015-08-19 17:55:02 -070045import com.android.launcher3.dragndrop.DragController;
46import com.android.launcher3.dragndrop.DragLayer;
Sunny Goyal94b510c2016-08-16 15:36:48 -070047import com.android.launcher3.dragndrop.DragOptions;
Vadim Tryshevfedca432015-08-19 17:55:02 -070048import com.android.launcher3.dragndrop.DragView;
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -070049import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Tony Wickham6c828672017-02-27 13:30:20 -080050import com.android.launcher3.util.Themes;
Sunny Goyalfa401a12015-04-10 13:45:42 -070051import com.android.launcher3.util.Thunk;
Winson Chung61fa4192011-06-12 15:15:29 -070052
53/**
54 * Implements a DropTarget.
55 */
Sunny Goyal1a70cef2015-04-22 11:29:51 -070056public abstract class ButtonDropTarget extends TextView
57 implements DropTarget, DragController.DragListener, OnClickListener {
Sunny Goyalfa401a12015-04-10 13:45:42 -070058
Sunny Goyal55bdeed2018-09-18 16:17:22 -070059 private static final Property<ButtonDropTarget, Integer> TEXT_COLOR =
60 new Property<ButtonDropTarget, Integer>(Integer.TYPE, "textColor") {
61
62 @Override
63 public Integer get(ButtonDropTarget target) {
64 return target.getTextColor();
65 }
66
67 @Override
68 public void set(ButtonDropTarget target, Integer value) {
69 target.setTextColor(value);
70 }
71 };
72
Sunny Goyalac00cba2017-11-13 15:58:01 -080073 private static final int[] sTempCords = new int[2];
Tony Wickhamb54c4a32015-09-11 08:40:20 -070074 private static final int DRAG_VIEW_DROP_DURATION = 285;
Winson Chung61fa4192011-06-12 15:15:29 -070075
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080076 public static final int TOOLTIP_DEFAULT = 0;
77 public static final int TOOLTIP_LEFT = 1;
78 public static final int TOOLTIP_RIGHT = 2;
79
Sunny Goyal47328fd2016-05-25 18:56:41 -070080 protected final Launcher mLauncher;
Sunny Goyalf37a2142016-03-24 17:28:25 -070081
Winson Chunga62e9fd2011-07-11 15:20:48 -070082 private int mBottomDragPadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070083 protected DropTargetBar mDropTargetBar;
Winson Chung61fa4192011-06-12 15:15:29 -070084
85 /** Whether this drop target is active for the current drag */
86 protected boolean mActive;
Sunny Goyal4583d092016-08-17 11:11:48 -070087 /** Whether an accessible drag is in progress */
88 private boolean mAccessibleDrag;
Tony Wickham855b1b52016-03-28 16:56:30 -070089 /** An item must be dragged at least this many pixels before this drop target is enabled. */
90 private final int mDragDistanceThreshold;
Winson Chung61fa4192011-06-12 15:15:29 -070091
92 /** The paint applied to the drag view on hover */
Winson Chung61967cb2012-02-28 18:11:33 -080093 protected int mHoverColor = 0;
Winson Chung61fa4192011-06-12 15:15:29 -070094
Jon Mirandabfaa4a42017-08-21 15:31:51 -070095 protected CharSequence mText;
Sunny Goyalfa401a12015-04-10 13:45:42 -070096 protected ColorStateList mOriginalTextColor;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070097 protected Drawable mDrawable;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080098 private boolean mTextVisible = true;
99
100 private PopupWindow mToolTip;
101 private int mToolTipLocation;
Sunny Goyalfa401a12015-04-10 13:45:42 -0700102
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700103 private AnimatorSet mCurrentColorAnim;
Sunny Goyal316490e2015-06-02 09:38:28 -0700104 @Thunk ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter;
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700105
Winson Chung61fa4192011-06-12 15:15:29 -0700106 public ButtonDropTarget(Context context, AttributeSet attrs) {
107 this(context, attrs, 0);
108 }
109
110 public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
111 super(context, attrs, defStyle);
Tony2fd02082016-10-07 12:50:01 -0700112 mLauncher = Launcher.getLauncher(context);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700113
Tony Wickham855b1b52016-03-28 16:56:30 -0700114 Resources resources = getResources();
115 mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
Tony Wickham855b1b52016-03-28 16:56:30 -0700116 mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700117 }
118
Sunny Goyalfa401a12015-04-10 13:45:42 -0700119 @Override
120 protected void onFinishInflate() {
121 super.onFinishInflate();
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700122 mText = getText();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700123 mOriginalTextColor = getTextColors();
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800124 setContentDescription(mText);
Winson Chung61fa4192011-06-12 15:15:29 -0700125 }
126
Winson Chung1054d4e2018-03-05 19:39:21 +0000127 protected void updateText(int resId) {
128 setText(resId);
129 mText = getText();
130 setContentDescription(mText);
131 }
132
Sunny Goyalfa401a12015-04-10 13:45:42 -0700133 protected void setDrawable(int resId) {
Sunny Goyale0cab302015-05-20 16:40:30 -0700134 // We do not set the drawable in the xml as that inflates two drawables corresponding to
135 // drawableLeft and drawableStart.
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800136 if (mTextVisible) {
137 setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0);
138 mDrawable = getCompoundDrawablesRelative()[0];
139 } else {
140 setCompoundDrawablesRelativeWithIntrinsicBounds(0, resId, 0, 0);
141 mDrawable = getCompoundDrawablesRelative()[1];
142 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700143 }
144
Sunny Goyal47328fd2016-05-25 18:56:41 -0700145 public void setDropTargetBar(DropTargetBar dropTargetBar) {
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700146 mDropTargetBar = dropTargetBar;
Adam Cohend4d7aa52011-07-19 21:47:37 -0700147 }
148
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800149 private void hideTooltip() {
150 if (mToolTip != null) {
151 mToolTip.dismiss();
152 mToolTip = null;
153 }
154 }
155
Sunny Goyalfa401a12015-04-10 13:45:42 -0700156 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -0700157 public final void onDragEnter(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800158 if (!d.accessibleDrag && !mTextVisible) {
159 // Show tooltip
160 hideTooltip();
161
162 TextView message = (TextView) LayoutInflater.from(getContext()).inflate(
163 R.layout.drop_target_tool_tip, null);
164 message.setText(mText);
165
166 mToolTip = new PopupWindow(message, WRAP_CONTENT, WRAP_CONTENT);
167 int x = 0, y = 0;
168 if (mToolTipLocation != TOOLTIP_DEFAULT) {
169 y = -getMeasuredHeight();
170 message.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
171 if (mToolTipLocation == TOOLTIP_LEFT) {
172 x = - getMeasuredWidth() - message.getMeasuredWidth() / 2;
173 } else {
174 x = getMeasuredWidth() / 2 + message.getMeasuredWidth() / 2;
175 }
176 }
177 mToolTip.showAsDropDown(this, x, y);
178 }
179
Winson Chung61967cb2012-02-28 18:11:33 -0800180 d.dragView.setColor(mHoverColor);
Sunny Goyala52ecb02016-12-16 15:04:51 -0800181 animateTextColor(mHoverColor);
Sunny Goyald21301e2015-09-25 12:17:08 -0700182 if (d.stateAnnouncer != null) {
183 d.stateAnnouncer.cancel();
184 }
Sunny Goyale78e3d72015-09-24 11:23:31 -0700185 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Winson Chung61fa4192011-06-12 15:15:29 -0700186 }
187
Sunny Goyalfa401a12015-04-10 13:45:42 -0700188 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700189 public void onDragOver(DragObject d) {
190 // Do nothing
191 }
192
Sunny Goyal9fc953b2015-08-17 12:24:25 -0700193 protected void resetHoverColor() {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800194 animateTextColor(mOriginalTextColor.getDefaultColor());
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700195 }
196
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700197 private void animateTextColor(int targetColor) {
198 if (mCurrentColorAnim != null) {
199 mCurrentColorAnim.cancel();
200 }
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700201
202 mCurrentColorAnim = new AnimatorSet();
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700203 mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700204
205 if (mSrcFilter == null) {
206 mSrcFilter = new ColorMatrix();
207 mDstFilter = new ColorMatrix();
208 mCurrentFilter = new ColorMatrix();
209 }
210
Mehdi Alizadeh3e024c02018-04-30 11:15:39 -0700211 int defaultTextColor = mOriginalTextColor.getDefaultColor();
212 Themes.setColorChangeOnMatrix(defaultTextColor, getTextColor(), mSrcFilter);
213 Themes.setColorChangeOnMatrix(defaultTextColor, targetColor, mDstFilter);
214
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700215 ValueAnimator anim1 = ValueAnimator.ofObject(
216 new FloatArrayEvaluator(mCurrentFilter.getArray()),
217 mSrcFilter.getArray(), mDstFilter.getArray());
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800218 anim1.addUpdateListener((anim) -> {
219 mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
220 invalidate();
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700221 });
222
223 mCurrentColorAnim.play(anim1);
Sunny Goyal55bdeed2018-09-18 16:17:22 -0700224 mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, TEXT_COLOR, targetColor));
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700225 mCurrentColorAnim.start();
Winson Chung61fa4192011-06-12 15:15:29 -0700226 }
227
Sunny Goyalfa401a12015-04-10 13:45:42 -0700228 @Override
229 public final void onDragExit(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800230 hideTooltip();
231
Sunny Goyalfa401a12015-04-10 13:45:42 -0700232 if (!d.dragComplete) {
233 d.dragView.setColor(0);
234 resetHoverColor();
235 } else {
236 // Restore the hover color
237 d.dragView.setColor(mHoverColor);
238 }
Winson Chung61fa4192011-06-12 15:15:29 -0700239 }
240
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700241 @Override
Sunny Goyal94b510c2016-08-16 15:36:48 -0700242 public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700243 mActive = supportsDrop(dragObject.dragInfo);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700244 mDrawable.setColorFilter(null);
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700245 if (mCurrentColorAnim != null) {
246 mCurrentColorAnim.cancel();
247 mCurrentColorAnim = null;
248 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700249 setTextColor(mOriginalTextColor);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800250 setVisibility(mActive ? View.VISIBLE : View.GONE);
Sunny Goyal94b510c2016-08-16 15:36:48 -0700251
252 mAccessibleDrag = options.isAccessibleDrag;
253 setOnClickListener(mAccessibleDrag ? this : null);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700254 }
255
256 @Override
257 public final boolean acceptDrop(DragObject dragObject) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700258 return supportsDrop(dragObject.dragInfo);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700259 }
260
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700261 protected abstract boolean supportsDrop(ItemInfo info);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700262
Winson Chung1054d4e2018-03-05 19:39:21 +0000263 public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700264
Sunny Goyalfa401a12015-04-10 13:45:42 -0700265 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700266 public boolean isDropEnabled() {
Sunny Goyal4583d092016-08-17 11:11:48 -0700267 return mActive && (mAccessibleDrag ||
268 mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700269 }
270
Sunny Goyalfa401a12015-04-10 13:45:42 -0700271 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700272 public void onDragEnd() {
Sunny Goyalfa401a12015-04-10 13:45:42 -0700273 mActive = false;
Sunny Goyal94b510c2016-08-16 15:36:48 -0700274 setOnClickListener(null);
Winson Chung61fa4192011-06-12 15:15:29 -0700275 }
276
Sunny Goyalfa401a12015-04-10 13:45:42 -0700277 /**
278 * On drop animate the dropView to the icon.
279 */
280 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700281 public void onDrop(final DragObject d, final DragOptions options) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -0700282 if (options.isFlingToDelete) {
283 // FlingAnimation handles the animation and then calls completeDrop().
284 return;
285 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700286 final DragLayer dragLayer = mLauncher.getDragLayer();
287 final Rect from = new Rect();
288 dragLayer.getViewRectRelativeToSelf(d.dragView, from);
289
Sunny Goyal0f76b562016-12-13 19:37:10 -0800290 final Rect to = getIconRect(d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700291 final float scale = (float) to.width() / from.width();
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700292 mDropTargetBar.deferOnDragEnd();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700293
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800294 Runnable onAnimationEndRunnable = () -> {
295 completeDrop(d);
296 mDropTargetBar.onDragEnd();
297 mLauncher.getStateManager().goToState(NORMAL);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700298 };
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800299
Sunny Goyalfa401a12015-04-10 13:45:42 -0700300 dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
Sunny Goyaldec3a902017-01-25 18:23:36 -0800301 DRAG_VIEW_DROP_DURATION,
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -0700302 Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable,
Sunny Goyalfa401a12015-04-10 13:45:42 -0700303 DragLayer.ANIMATION_END_DISAPPEAR, null);
304 }
305
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700306 public abstract int getAccessibilityAction();
307
Sunny Goyale9b651e2015-04-24 11:44:51 -0700308 @Override
309 public void prepareAccessibilityDrop() { }
310
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700311 public abstract void onAccessibilityDrop(View view, ItemInfo item);
312
Sunny Goyal0f76b562016-12-13 19:37:10 -0800313 public abstract void completeDrop(DragObject d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700314
Winson Chung61fa4192011-06-12 15:15:29 -0700315 @Override
Adam Cohen7d30a372013-07-01 17:03:59 -0700316 public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
Winson Chunga62e9fd2011-07-11 15:20:48 -0700317 super.getHitRect(outRect);
318 outRect.bottom += mBottomDragPadding;
Winson Chung156ab5b2013-07-12 14:14:16 -0700319
Sunny Goyalac00cba2017-11-13 15:58:01 -0800320 sTempCords[0] = sTempCords[1] = 0;
321 mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords);
322 outRect.offsetTo(sTempCords[0], sTempCords[1]);
Winson Chunga62e9fd2011-07-11 15:20:48 -0700323 }
324
Sunny Goyal0f76b562016-12-13 19:37:10 -0800325 public Rect getIconRect(DragObject dragObject) {
326 int viewWidth = dragObject.dragView.getMeasuredWidth();
327 int viewHeight = dragObject.dragView.getMeasuredHeight();
328 int drawableWidth = mDrawable.getIntrinsicWidth();
329 int drawableHeight = mDrawable.getIntrinsicHeight();
Winson Chung61967cb2012-02-28 18:11:33 -0800330 DragLayer dragLayer = mLauncher.getDragLayer();
331
332 // Find the rect to animate to (the view is center aligned)
333 Rect to = new Rect();
334 dragLayer.getViewRectRelativeToSelf(this, to);
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800335
336 final int width = drawableWidth;
337 final int height = drawableHeight;
338
339 final int left;
340 final int right;
341
Sunny Goyal70660032015-05-14 00:07:08 -0700342 if (Utilities.isRtl(getResources())) {
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800343 right = to.right - getPaddingRight();
344 left = right - width;
345 } else {
346 left = to.left + getPaddingLeft();
347 right = left + width;
348 }
349
350 final int top = to.top + (getMeasuredHeight() - height) / 2;
351 final int bottom = top + height;
352
353 to.set(left, top, right, bottom);
Winson Chung61967cb2012-02-28 18:11:33 -0800354
355 // Center the destination rect about the trash icon
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800356 final int xOffset = -(viewWidth - width) / 2;
357 final int yOffset = -(viewHeight - height) / 2;
Winson Chung61967cb2012-02-28 18:11:33 -0800358 to.offset(xOffset, yOffset);
359
360 return to;
361 }
362
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700363 @Override
364 public void onClick(View v) {
Sunny Goyalae502842016-06-17 08:43:56 -0700365 mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null);
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700366 }
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700367
368 public int getTextColor() {
369 return getTextColors().getDefaultColor();
370 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700371
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800372 public void setTextVisible(boolean isVisible) {
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800373 CharSequence newText = isVisible ? mText : "";
374 if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800375 mTextVisible = isVisible;
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800376 setText(newText);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800377 if (mTextVisible) {
378 setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
379 } else {
380 setCompoundDrawablesRelativeWithIntrinsicBounds(null, mDrawable, null, null);
381 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700382 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700383 }
384
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800385 public void setToolTipLocation(int location) {
386 mToolTipLocation = location;
387 hideTooltip();
388 }
389
390 public boolean isTextTruncated(int availableWidth) {
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700391 availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth()
392 + getCompoundDrawablePadding());
393 CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth,
394 TextUtils.TruncateAt.END);
395 return !mText.equals(displayedText);
396 }
Winson Chung1054d4e2018-03-05 19:39:21 +0000397
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -0700398 public abstract Target getDropTargetForLogging();
Winson Chung61fa4192011-06-12 15:15:29 -0700399}