blob: 09827d664b4b7281555b4df4820f7b2494b430c0 [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;
Sunny Goyale396abf2020-04-06 15:11:17 -070049import com.android.launcher3.model.data.ItemInfo;
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -070050import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Tony Wickham6c828672017-02-27 13:30:20 -080051import com.android.launcher3.util.Themes;
Sunny Goyalfa401a12015-04-10 13:45:42 -070052import com.android.launcher3.util.Thunk;
Winson Chung61fa4192011-06-12 15:15:29 -070053
54/**
55 * Implements a DropTarget.
56 */
Sunny Goyal1a70cef2015-04-22 11:29:51 -070057public abstract class ButtonDropTarget extends TextView
58 implements DropTarget, DragController.DragListener, OnClickListener {
Sunny Goyalfa401a12015-04-10 13:45:42 -070059
Sunny Goyal55bdeed2018-09-18 16:17:22 -070060 private static final Property<ButtonDropTarget, Integer> TEXT_COLOR =
61 new Property<ButtonDropTarget, Integer>(Integer.TYPE, "textColor") {
62
63 @Override
64 public Integer get(ButtonDropTarget target) {
65 return target.getTextColor();
66 }
67
68 @Override
69 public void set(ButtonDropTarget target, Integer value) {
70 target.setTextColor(value);
71 }
72 };
73
Sunny Goyalac00cba2017-11-13 15:58:01 -080074 private static final int[] sTempCords = new int[2];
Tony Wickhamb54c4a32015-09-11 08:40:20 -070075 private static final int DRAG_VIEW_DROP_DURATION = 285;
Winson Chung61fa4192011-06-12 15:15:29 -070076
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080077 public static final int TOOLTIP_DEFAULT = 0;
78 public static final int TOOLTIP_LEFT = 1;
79 public static final int TOOLTIP_RIGHT = 2;
80
Sunny Goyal47328fd2016-05-25 18:56:41 -070081 protected final Launcher mLauncher;
Sunny Goyalf37a2142016-03-24 17:28:25 -070082
Winson Chunga62e9fd2011-07-11 15:20:48 -070083 private int mBottomDragPadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070084 protected DropTargetBar mDropTargetBar;
Winson Chung61fa4192011-06-12 15:15:29 -070085
86 /** Whether this drop target is active for the current drag */
87 protected boolean mActive;
Sunny Goyal4583d092016-08-17 11:11:48 -070088 /** Whether an accessible drag is in progress */
89 private boolean mAccessibleDrag;
Tony Wickham855b1b52016-03-28 16:56:30 -070090 /** An item must be dragged at least this many pixels before this drop target is enabled. */
91 private final int mDragDistanceThreshold;
Winson Chung61fa4192011-06-12 15:15:29 -070092
93 /** The paint applied to the drag view on hover */
Winson Chung61967cb2012-02-28 18:11:33 -080094 protected int mHoverColor = 0;
Winson Chung61fa4192011-06-12 15:15:29 -070095
Jon Mirandabfaa4a42017-08-21 15:31:51 -070096 protected CharSequence mText;
Sunny Goyalfa401a12015-04-10 13:45:42 -070097 protected ColorStateList mOriginalTextColor;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070098 protected Drawable mDrawable;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080099 private boolean mTextVisible = true;
100
101 private PopupWindow mToolTip;
102 private int mToolTipLocation;
Sunny Goyalfa401a12015-04-10 13:45:42 -0700103
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700104 private AnimatorSet mCurrentColorAnim;
Sunny Goyal316490e2015-06-02 09:38:28 -0700105 @Thunk ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter;
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700106
Winson Chung61fa4192011-06-12 15:15:29 -0700107 public ButtonDropTarget(Context context, AttributeSet attrs) {
108 this(context, attrs, 0);
109 }
110
111 public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
112 super(context, attrs, defStyle);
Tony2fd02082016-10-07 12:50:01 -0700113 mLauncher = Launcher.getLauncher(context);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700114
Tony Wickham855b1b52016-03-28 16:56:30 -0700115 Resources resources = getResources();
116 mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
Tony Wickham855b1b52016-03-28 16:56:30 -0700117 mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700118 }
119
Sunny Goyalfa401a12015-04-10 13:45:42 -0700120 @Override
121 protected void onFinishInflate() {
122 super.onFinishInflate();
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700123 mText = getText();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700124 mOriginalTextColor = getTextColors();
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800125 setContentDescription(mText);
Winson Chung61fa4192011-06-12 15:15:29 -0700126 }
127
Winson Chung1054d4e2018-03-05 19:39:21 +0000128 protected void updateText(int resId) {
129 setText(resId);
130 mText = getText();
131 setContentDescription(mText);
132 }
133
Sunny Goyalfa401a12015-04-10 13:45:42 -0700134 protected void setDrawable(int resId) {
Sunny Goyale0cab302015-05-20 16:40:30 -0700135 // We do not set the drawable in the xml as that inflates two drawables corresponding to
136 // drawableLeft and drawableStart.
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800137 if (mTextVisible) {
138 setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0);
139 mDrawable = getCompoundDrawablesRelative()[0];
140 } else {
141 setCompoundDrawablesRelativeWithIntrinsicBounds(0, resId, 0, 0);
142 mDrawable = getCompoundDrawablesRelative()[1];
143 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700144 }
145
Sunny Goyal47328fd2016-05-25 18:56:41 -0700146 public void setDropTargetBar(DropTargetBar dropTargetBar) {
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700147 mDropTargetBar = dropTargetBar;
Adam Cohend4d7aa52011-07-19 21:47:37 -0700148 }
149
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800150 private void hideTooltip() {
151 if (mToolTip != null) {
152 mToolTip.dismiss();
153 mToolTip = null;
154 }
155 }
156
Sunny Goyalfa401a12015-04-10 13:45:42 -0700157 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -0700158 public final void onDragEnter(DragObject d) {
Sunny Goyal9b180102020-03-11 10:02:29 -0700159 if (!mAccessibleDrag && !mTextVisible) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800160 // Show tooltip
161 hideTooltip();
162
163 TextView message = (TextView) LayoutInflater.from(getContext()).inflate(
164 R.layout.drop_target_tool_tip, null);
165 message.setText(mText);
166
167 mToolTip = new PopupWindow(message, WRAP_CONTENT, WRAP_CONTENT);
168 int x = 0, y = 0;
169 if (mToolTipLocation != TOOLTIP_DEFAULT) {
170 y = -getMeasuredHeight();
171 message.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
172 if (mToolTipLocation == TOOLTIP_LEFT) {
173 x = - getMeasuredWidth() - message.getMeasuredWidth() / 2;
174 } else {
175 x = getMeasuredWidth() / 2 + message.getMeasuredWidth() / 2;
176 }
177 }
178 mToolTip.showAsDropDown(this, x, y);
179 }
180
Winson Chung61967cb2012-02-28 18:11:33 -0800181 d.dragView.setColor(mHoverColor);
Sunny Goyala52ecb02016-12-16 15:04:51 -0800182 animateTextColor(mHoverColor);
Sunny Goyald21301e2015-09-25 12:17:08 -0700183 if (d.stateAnnouncer != null) {
184 d.stateAnnouncer.cancel();
185 }
Sunny Goyale78e3d72015-09-24 11:23:31 -0700186 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Winson Chung61fa4192011-06-12 15:15:29 -0700187 }
188
Sunny Goyalfa401a12015-04-10 13:45:42 -0700189 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700190 public void onDragOver(DragObject d) {
191 // Do nothing
192 }
193
Sunny Goyal9fc953b2015-08-17 12:24:25 -0700194 protected void resetHoverColor() {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800195 animateTextColor(mOriginalTextColor.getDefaultColor());
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700196 }
197
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700198 private void animateTextColor(int targetColor) {
199 if (mCurrentColorAnim != null) {
200 mCurrentColorAnim.cancel();
201 }
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700202
203 mCurrentColorAnim = new AnimatorSet();
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700204 mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700205
206 if (mSrcFilter == null) {
207 mSrcFilter = new ColorMatrix();
208 mDstFilter = new ColorMatrix();
209 mCurrentFilter = new ColorMatrix();
210 }
211
Mehdi Alizadeh3e024c02018-04-30 11:15:39 -0700212 int defaultTextColor = mOriginalTextColor.getDefaultColor();
213 Themes.setColorChangeOnMatrix(defaultTextColor, getTextColor(), mSrcFilter);
214 Themes.setColorChangeOnMatrix(defaultTextColor, targetColor, mDstFilter);
215
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700216 ValueAnimator anim1 = ValueAnimator.ofObject(
217 new FloatArrayEvaluator(mCurrentFilter.getArray()),
218 mSrcFilter.getArray(), mDstFilter.getArray());
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800219 anim1.addUpdateListener((anim) -> {
220 mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
221 invalidate();
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700222 });
223
224 mCurrentColorAnim.play(anim1);
Sunny Goyal55bdeed2018-09-18 16:17:22 -0700225 mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, TEXT_COLOR, targetColor));
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700226 mCurrentColorAnim.start();
Winson Chung61fa4192011-06-12 15:15:29 -0700227 }
228
Sunny Goyalfa401a12015-04-10 13:45:42 -0700229 @Override
230 public final void onDragExit(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800231 hideTooltip();
232
Sunny Goyalfa401a12015-04-10 13:45:42 -0700233 if (!d.dragComplete) {
234 d.dragView.setColor(0);
235 resetHoverColor();
236 } else {
237 // Restore the hover color
238 d.dragView.setColor(mHoverColor);
239 }
Winson Chung61fa4192011-06-12 15:15:29 -0700240 }
241
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700242 @Override
Sunny Goyal94b510c2016-08-16 15:36:48 -0700243 public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700244 mActive = supportsDrop(dragObject.dragInfo);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700245 mDrawable.setColorFilter(null);
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700246 if (mCurrentColorAnim != null) {
247 mCurrentColorAnim.cancel();
248 mCurrentColorAnim = null;
249 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700250 setTextColor(mOriginalTextColor);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800251 setVisibility(mActive ? View.VISIBLE : View.GONE);
Sunny Goyal94b510c2016-08-16 15:36:48 -0700252
253 mAccessibleDrag = options.isAccessibleDrag;
254 setOnClickListener(mAccessibleDrag ? this : null);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700255 }
256
257 @Override
258 public final boolean acceptDrop(DragObject dragObject) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700259 return supportsDrop(dragObject.dragInfo);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700260 }
261
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700262 protected abstract boolean supportsDrop(ItemInfo info);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700263
Winson Chung1054d4e2018-03-05 19:39:21 +0000264 public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700265
Sunny Goyalfa401a12015-04-10 13:45:42 -0700266 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700267 public boolean isDropEnabled() {
Sunny Goyal4583d092016-08-17 11:11:48 -0700268 return mActive && (mAccessibleDrag ||
269 mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700270 }
271
Sunny Goyalfa401a12015-04-10 13:45:42 -0700272 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700273 public void onDragEnd() {
Sunny Goyalfa401a12015-04-10 13:45:42 -0700274 mActive = false;
Sunny Goyal94b510c2016-08-16 15:36:48 -0700275 setOnClickListener(null);
Winson Chung61fa4192011-06-12 15:15:29 -0700276 }
277
Sunny Goyalfa401a12015-04-10 13:45:42 -0700278 /**
279 * On drop animate the dropView to the icon.
280 */
281 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700282 public void onDrop(final DragObject d, final DragOptions options) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -0700283 if (options.isFlingToDelete) {
284 // FlingAnimation handles the animation and then calls completeDrop().
285 return;
286 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700287 final DragLayer dragLayer = mLauncher.getDragLayer();
288 final Rect from = new Rect();
289 dragLayer.getViewRectRelativeToSelf(d.dragView, from);
290
Sunny Goyal0f76b562016-12-13 19:37:10 -0800291 final Rect to = getIconRect(d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700292 final float scale = (float) to.width() / from.width();
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700293 mDropTargetBar.deferOnDragEnd();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700294
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800295 Runnable onAnimationEndRunnable = () -> {
296 completeDrop(d);
297 mDropTargetBar.onDragEnd();
298 mLauncher.getStateManager().goToState(NORMAL);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700299 };
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800300
Sunny Goyalfa401a12015-04-10 13:45:42 -0700301 dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
Sunny Goyaldec3a902017-01-25 18:23:36 -0800302 DRAG_VIEW_DROP_DURATION,
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -0700303 Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable,
Sunny Goyalfa401a12015-04-10 13:45:42 -0700304 DragLayer.ANIMATION_END_DISAPPEAR, null);
305 }
306
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700307 public abstract int getAccessibilityAction();
308
Sunny Goyale9b651e2015-04-24 11:44:51 -0700309 @Override
310 public void prepareAccessibilityDrop() { }
311
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700312 public abstract void onAccessibilityDrop(View view, ItemInfo item);
313
Sunny Goyal0f76b562016-12-13 19:37:10 -0800314 public abstract void completeDrop(DragObject d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700315
Winson Chung61fa4192011-06-12 15:15:29 -0700316 @Override
Adam Cohen7d30a372013-07-01 17:03:59 -0700317 public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
Winson Chunga62e9fd2011-07-11 15:20:48 -0700318 super.getHitRect(outRect);
319 outRect.bottom += mBottomDragPadding;
Winson Chung156ab5b2013-07-12 14:14:16 -0700320
Sunny Goyalac00cba2017-11-13 15:58:01 -0800321 sTempCords[0] = sTempCords[1] = 0;
322 mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords);
323 outRect.offsetTo(sTempCords[0], sTempCords[1]);
Winson Chunga62e9fd2011-07-11 15:20:48 -0700324 }
325
Sunny Goyal0f76b562016-12-13 19:37:10 -0800326 public Rect getIconRect(DragObject dragObject) {
327 int viewWidth = dragObject.dragView.getMeasuredWidth();
328 int viewHeight = dragObject.dragView.getMeasuredHeight();
329 int drawableWidth = mDrawable.getIntrinsicWidth();
330 int drawableHeight = mDrawable.getIntrinsicHeight();
Winson Chung61967cb2012-02-28 18:11:33 -0800331 DragLayer dragLayer = mLauncher.getDragLayer();
332
333 // Find the rect to animate to (the view is center aligned)
334 Rect to = new Rect();
335 dragLayer.getViewRectRelativeToSelf(this, to);
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800336
337 final int width = drawableWidth;
338 final int height = drawableHeight;
339
340 final int left;
341 final int right;
342
Sunny Goyal70660032015-05-14 00:07:08 -0700343 if (Utilities.isRtl(getResources())) {
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800344 right = to.right - getPaddingRight();
345 left = right - width;
346 } else {
347 left = to.left + getPaddingLeft();
348 right = left + width;
349 }
350
351 final int top = to.top + (getMeasuredHeight() - height) / 2;
352 final int bottom = top + height;
353
354 to.set(left, top, right, bottom);
Winson Chung61967cb2012-02-28 18:11:33 -0800355
356 // Center the destination rect about the trash icon
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800357 final int xOffset = -(viewWidth - width) / 2;
358 final int yOffset = -(viewHeight - height) / 2;
Winson Chung61967cb2012-02-28 18:11:33 -0800359 to.offset(xOffset, yOffset);
360
361 return to;
362 }
363
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700364 @Override
365 public void onClick(View v) {
Sunny Goyalae502842016-06-17 08:43:56 -0700366 mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null);
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700367 }
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700368
369 public int getTextColor() {
370 return getTextColors().getDefaultColor();
371 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700372
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800373 public void setTextVisible(boolean isVisible) {
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800374 CharSequence newText = isVisible ? mText : "";
375 if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800376 mTextVisible = isVisible;
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800377 setText(newText);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800378 if (mTextVisible) {
379 setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
380 } else {
381 setCompoundDrawablesRelativeWithIntrinsicBounds(null, mDrawable, null, null);
382 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700383 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700384 }
385
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800386 public void setToolTipLocation(int location) {
387 mToolTipLocation = location;
388 hideTooltip();
389 }
390
391 public boolean isTextTruncated(int availableWidth) {
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700392 availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth()
393 + getCompoundDrawablePadding());
394 CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth,
395 TextUtils.TruncateAt.END);
396 return !mText.equals(displayedText);
397 }
Winson Chung1054d4e2018-03-05 19:39:21 +0000398
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -0700399 public abstract Target getDropTargetForLogging();
Winson Chung61fa4192011-06-12 15:15:29 -0700400}