blob: dd63ebce0bada8e42a580e98abbbace85d4cf85f [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 Goyald1b3f5c2018-01-18 17:14:05 -080036import android.view.LayoutInflater;
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -080037import android.view.View;
Sunny Goyal1a70cef2015-04-22 11:29:51 -070038import android.view.View.OnClickListener;
Sunny Goyale78e3d72015-09-24 11:23:31 -070039import android.view.accessibility.AccessibilityEvent;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080040import android.widget.PopupWindow;
Adam Cohend4d7aa52011-07-19 21:47:37 -070041import android.widget.TextView;
Winson Chung61fa4192011-06-12 15:15:29 -070042
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -070043import com.android.launcher3.anim.Interpolators;
Vadim Tryshevfedca432015-08-19 17:55:02 -070044import com.android.launcher3.dragndrop.DragController;
45import com.android.launcher3.dragndrop.DragLayer;
Sunny Goyal94b510c2016-08-16 15:36:48 -070046import com.android.launcher3.dragndrop.DragOptions;
Vadim Tryshevfedca432015-08-19 17:55:02 -070047import com.android.launcher3.dragndrop.DragView;
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -070048import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Tony Wickham6c828672017-02-27 13:30:20 -080049import com.android.launcher3.util.Themes;
Sunny Goyalfa401a12015-04-10 13:45:42 -070050import com.android.launcher3.util.Thunk;
Winson Chung61fa4192011-06-12 15:15:29 -070051
52/**
53 * Implements a DropTarget.
54 */
Sunny Goyal1a70cef2015-04-22 11:29:51 -070055public abstract class ButtonDropTarget extends TextView
56 implements DropTarget, DragController.DragListener, OnClickListener {
Sunny Goyalfa401a12015-04-10 13:45:42 -070057
Sunny Goyalac00cba2017-11-13 15:58:01 -080058 private static final int[] sTempCords = new int[2];
Tony Wickhamb54c4a32015-09-11 08:40:20 -070059 private static final int DRAG_VIEW_DROP_DURATION = 285;
Winson Chung61fa4192011-06-12 15:15:29 -070060
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080061 public static final int TOOLTIP_DEFAULT = 0;
62 public static final int TOOLTIP_LEFT = 1;
63 public static final int TOOLTIP_RIGHT = 2;
64
Sunny Goyal47328fd2016-05-25 18:56:41 -070065 protected final Launcher mLauncher;
Sunny Goyalf37a2142016-03-24 17:28:25 -070066
Winson Chunga62e9fd2011-07-11 15:20:48 -070067 private int mBottomDragPadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070068 protected DropTargetBar mDropTargetBar;
Winson Chung61fa4192011-06-12 15:15:29 -070069
70 /** Whether this drop target is active for the current drag */
71 protected boolean mActive;
Sunny Goyal4583d092016-08-17 11:11:48 -070072 /** Whether an accessible drag is in progress */
73 private boolean mAccessibleDrag;
Tony Wickham855b1b52016-03-28 16:56:30 -070074 /** An item must be dragged at least this many pixels before this drop target is enabled. */
75 private final int mDragDistanceThreshold;
Winson Chung61fa4192011-06-12 15:15:29 -070076
77 /** The paint applied to the drag view on hover */
Winson Chung61967cb2012-02-28 18:11:33 -080078 protected int mHoverColor = 0;
Winson Chung61fa4192011-06-12 15:15:29 -070079
Jon Mirandabfaa4a42017-08-21 15:31:51 -070080 protected CharSequence mText;
Sunny Goyalfa401a12015-04-10 13:45:42 -070081 protected ColorStateList mOriginalTextColor;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070082 protected Drawable mDrawable;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080083 private boolean mTextVisible = true;
84
85 private PopupWindow mToolTip;
86 private int mToolTipLocation;
Sunny Goyalfa401a12015-04-10 13:45:42 -070087
Sunny Goyal3a644ed2015-05-21 10:28:02 -070088 private AnimatorSet mCurrentColorAnim;
Sunny Goyal316490e2015-06-02 09:38:28 -070089 @Thunk ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070090
Winson Chung61fa4192011-06-12 15:15:29 -070091 public ButtonDropTarget(Context context, AttributeSet attrs) {
92 this(context, attrs, 0);
93 }
94
95 public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
96 super(context, attrs, defStyle);
Tony2fd02082016-10-07 12:50:01 -070097 mLauncher = Launcher.getLauncher(context);
Sunny Goyal47328fd2016-05-25 18:56:41 -070098
Tony Wickham855b1b52016-03-28 16:56:30 -070099 Resources resources = getResources();
100 mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
Tony Wickham855b1b52016-03-28 16:56:30 -0700101 mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700102 }
103
Sunny Goyalfa401a12015-04-10 13:45:42 -0700104 @Override
105 protected void onFinishInflate() {
106 super.onFinishInflate();
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700107 mText = getText();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700108 mOriginalTextColor = getTextColors();
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800109 setContentDescription(mText);
Winson Chung61fa4192011-06-12 15:15:29 -0700110 }
111
Winson Chung1054d4e2018-03-05 19:39:21 +0000112 protected void updateText(int resId) {
113 setText(resId);
114 mText = getText();
115 setContentDescription(mText);
116 }
117
Sunny Goyalfa401a12015-04-10 13:45:42 -0700118 protected void setDrawable(int resId) {
Sunny Goyale0cab302015-05-20 16:40:30 -0700119 // We do not set the drawable in the xml as that inflates two drawables corresponding to
120 // drawableLeft and drawableStart.
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800121 if (mTextVisible) {
122 setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0);
123 mDrawable = getCompoundDrawablesRelative()[0];
124 } else {
125 setCompoundDrawablesRelativeWithIntrinsicBounds(0, resId, 0, 0);
126 mDrawable = getCompoundDrawablesRelative()[1];
127 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700128 }
129
Sunny Goyal47328fd2016-05-25 18:56:41 -0700130 public void setDropTargetBar(DropTargetBar dropTargetBar) {
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700131 mDropTargetBar = dropTargetBar;
Adam Cohend4d7aa52011-07-19 21:47:37 -0700132 }
133
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800134 private void hideTooltip() {
135 if (mToolTip != null) {
136 mToolTip.dismiss();
137 mToolTip = null;
138 }
139 }
140
Sunny Goyalfa401a12015-04-10 13:45:42 -0700141 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -0700142 public final void onDragEnter(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800143 if (!d.accessibleDrag && !mTextVisible) {
144 // Show tooltip
145 hideTooltip();
146
147 TextView message = (TextView) LayoutInflater.from(getContext()).inflate(
148 R.layout.drop_target_tool_tip, null);
149 message.setText(mText);
150
151 mToolTip = new PopupWindow(message, WRAP_CONTENT, WRAP_CONTENT);
152 int x = 0, y = 0;
153 if (mToolTipLocation != TOOLTIP_DEFAULT) {
154 y = -getMeasuredHeight();
155 message.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
156 if (mToolTipLocation == TOOLTIP_LEFT) {
157 x = - getMeasuredWidth() - message.getMeasuredWidth() / 2;
158 } else {
159 x = getMeasuredWidth() / 2 + message.getMeasuredWidth() / 2;
160 }
161 }
162 mToolTip.showAsDropDown(this, x, y);
163 }
164
Winson Chung61967cb2012-02-28 18:11:33 -0800165 d.dragView.setColor(mHoverColor);
Sunny Goyala52ecb02016-12-16 15:04:51 -0800166 animateTextColor(mHoverColor);
Sunny Goyald21301e2015-09-25 12:17:08 -0700167 if (d.stateAnnouncer != null) {
168 d.stateAnnouncer.cancel();
169 }
Sunny Goyale78e3d72015-09-24 11:23:31 -0700170 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Winson Chung61fa4192011-06-12 15:15:29 -0700171 }
172
Sunny Goyalfa401a12015-04-10 13:45:42 -0700173 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700174 public void onDragOver(DragObject d) {
175 // Do nothing
176 }
177
Sunny Goyal9fc953b2015-08-17 12:24:25 -0700178 protected void resetHoverColor() {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800179 animateTextColor(mOriginalTextColor.getDefaultColor());
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700180 }
181
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700182 private void animateTextColor(int targetColor) {
183 if (mCurrentColorAnim != null) {
184 mCurrentColorAnim.cancel();
185 }
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700186
187 mCurrentColorAnim = new AnimatorSet();
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700188 mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700189
190 if (mSrcFilter == null) {
191 mSrcFilter = new ColorMatrix();
192 mDstFilter = new ColorMatrix();
193 mCurrentFilter = new ColorMatrix();
194 }
195
Mehdi Alizadeh3e024c02018-04-30 11:15:39 -0700196 int defaultTextColor = mOriginalTextColor.getDefaultColor();
197 Themes.setColorChangeOnMatrix(defaultTextColor, getTextColor(), mSrcFilter);
198 Themes.setColorChangeOnMatrix(defaultTextColor, targetColor, mDstFilter);
199
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700200 ValueAnimator anim1 = ValueAnimator.ofObject(
201 new FloatArrayEvaluator(mCurrentFilter.getArray()),
202 mSrcFilter.getArray(), mDstFilter.getArray());
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800203 anim1.addUpdateListener((anim) -> {
204 mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
205 invalidate();
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700206 });
207
208 mCurrentColorAnim.play(anim1);
209 mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700210 mCurrentColorAnim.start();
Winson Chung61fa4192011-06-12 15:15:29 -0700211 }
212
Sunny Goyalfa401a12015-04-10 13:45:42 -0700213 @Override
214 public final void onDragExit(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800215 hideTooltip();
216
Sunny Goyalfa401a12015-04-10 13:45:42 -0700217 if (!d.dragComplete) {
218 d.dragView.setColor(0);
219 resetHoverColor();
220 } else {
221 // Restore the hover color
222 d.dragView.setColor(mHoverColor);
223 }
Winson Chung61fa4192011-06-12 15:15:29 -0700224 }
225
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700226 @Override
Sunny Goyal94b510c2016-08-16 15:36:48 -0700227 public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700228 mActive = supportsDrop(dragObject.dragInfo);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700229 mDrawable.setColorFilter(null);
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700230 if (mCurrentColorAnim != null) {
231 mCurrentColorAnim.cancel();
232 mCurrentColorAnim = null;
233 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700234 setTextColor(mOriginalTextColor);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800235 setVisibility(mActive ? View.VISIBLE : View.GONE);
Sunny Goyal94b510c2016-08-16 15:36:48 -0700236
237 mAccessibleDrag = options.isAccessibleDrag;
238 setOnClickListener(mAccessibleDrag ? this : null);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700239 }
240
241 @Override
242 public final boolean acceptDrop(DragObject dragObject) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700243 return supportsDrop(dragObject.dragInfo);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700244 }
245
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700246 protected abstract boolean supportsDrop(ItemInfo info);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700247
Winson Chung1054d4e2018-03-05 19:39:21 +0000248 public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700249
Sunny Goyalfa401a12015-04-10 13:45:42 -0700250 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700251 public boolean isDropEnabled() {
Sunny Goyal4583d092016-08-17 11:11:48 -0700252 return mActive && (mAccessibleDrag ||
253 mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700254 }
255
Sunny Goyalfa401a12015-04-10 13:45:42 -0700256 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700257 public void onDragEnd() {
Sunny Goyalfa401a12015-04-10 13:45:42 -0700258 mActive = false;
Sunny Goyal94b510c2016-08-16 15:36:48 -0700259 setOnClickListener(null);
Winson Chung61fa4192011-06-12 15:15:29 -0700260 }
261
Sunny Goyalfa401a12015-04-10 13:45:42 -0700262 /**
263 * On drop animate the dropView to the icon.
264 */
265 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700266 public void onDrop(final DragObject d, final DragOptions options) {
Tony Wickham6a71a5b2018-08-21 11:40:23 -0700267 if (options.isFlingToDelete) {
268 // FlingAnimation handles the animation and then calls completeDrop().
269 return;
270 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700271 final DragLayer dragLayer = mLauncher.getDragLayer();
272 final Rect from = new Rect();
273 dragLayer.getViewRectRelativeToSelf(d.dragView, from);
274
Sunny Goyal0f76b562016-12-13 19:37:10 -0800275 final Rect to = getIconRect(d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700276 final float scale = (float) to.width() / from.width();
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700277 mDropTargetBar.deferOnDragEnd();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700278
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800279 Runnable onAnimationEndRunnable = () -> {
280 completeDrop(d);
281 mDropTargetBar.onDragEnd();
282 mLauncher.getStateManager().goToState(NORMAL);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700283 };
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800284
Sunny Goyalfa401a12015-04-10 13:45:42 -0700285 dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
Sunny Goyaldec3a902017-01-25 18:23:36 -0800286 DRAG_VIEW_DROP_DURATION,
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -0700287 Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable,
Sunny Goyalfa401a12015-04-10 13:45:42 -0700288 DragLayer.ANIMATION_END_DISAPPEAR, null);
289 }
290
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700291 public abstract int getAccessibilityAction();
292
Sunny Goyale9b651e2015-04-24 11:44:51 -0700293 @Override
294 public void prepareAccessibilityDrop() { }
295
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700296 public abstract void onAccessibilityDrop(View view, ItemInfo item);
297
Sunny Goyal0f76b562016-12-13 19:37:10 -0800298 public abstract void completeDrop(DragObject d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700299
Winson Chung61fa4192011-06-12 15:15:29 -0700300 @Override
Adam Cohen7d30a372013-07-01 17:03:59 -0700301 public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
Winson Chunga62e9fd2011-07-11 15:20:48 -0700302 super.getHitRect(outRect);
303 outRect.bottom += mBottomDragPadding;
Winson Chung156ab5b2013-07-12 14:14:16 -0700304
Sunny Goyalac00cba2017-11-13 15:58:01 -0800305 sTempCords[0] = sTempCords[1] = 0;
306 mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords);
307 outRect.offsetTo(sTempCords[0], sTempCords[1]);
Winson Chunga62e9fd2011-07-11 15:20:48 -0700308 }
309
Sunny Goyal0f76b562016-12-13 19:37:10 -0800310 public Rect getIconRect(DragObject dragObject) {
311 int viewWidth = dragObject.dragView.getMeasuredWidth();
312 int viewHeight = dragObject.dragView.getMeasuredHeight();
313 int drawableWidth = mDrawable.getIntrinsicWidth();
314 int drawableHeight = mDrawable.getIntrinsicHeight();
Winson Chung61967cb2012-02-28 18:11:33 -0800315 DragLayer dragLayer = mLauncher.getDragLayer();
316
317 // Find the rect to animate to (the view is center aligned)
318 Rect to = new Rect();
319 dragLayer.getViewRectRelativeToSelf(this, to);
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800320
321 final int width = drawableWidth;
322 final int height = drawableHeight;
323
324 final int left;
325 final int right;
326
Sunny Goyal70660032015-05-14 00:07:08 -0700327 if (Utilities.isRtl(getResources())) {
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800328 right = to.right - getPaddingRight();
329 left = right - width;
330 } else {
331 left = to.left + getPaddingLeft();
332 right = left + width;
333 }
334
335 final int top = to.top + (getMeasuredHeight() - height) / 2;
336 final int bottom = top + height;
337
338 to.set(left, top, right, bottom);
Winson Chung61967cb2012-02-28 18:11:33 -0800339
340 // Center the destination rect about the trash icon
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800341 final int xOffset = -(viewWidth - width) / 2;
342 final int yOffset = -(viewHeight - height) / 2;
Winson Chung61967cb2012-02-28 18:11:33 -0800343 to.offset(xOffset, yOffset);
344
345 return to;
346 }
347
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700348 @Override
349 public void onClick(View v) {
Sunny Goyalae502842016-06-17 08:43:56 -0700350 mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null);
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700351 }
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700352
353 public int getTextColor() {
354 return getTextColors().getDefaultColor();
355 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700356
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800357 public void setTextVisible(boolean isVisible) {
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800358 CharSequence newText = isVisible ? mText : "";
359 if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800360 mTextVisible = isVisible;
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800361 setText(newText);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800362 if (mTextVisible) {
363 setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
364 } else {
365 setCompoundDrawablesRelativeWithIntrinsicBounds(null, mDrawable, null, null);
366 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700367 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700368 }
369
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800370 public void setToolTipLocation(int location) {
371 mToolTipLocation = location;
372 hideTooltip();
373 }
374
375 public boolean isTextTruncated(int availableWidth) {
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700376 availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth()
377 + getCompoundDrawablePadding());
378 CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth,
379 TextUtils.TruncateAt.END);
380 return !mText.equals(displayedText);
381 }
Winson Chung1054d4e2018-03-05 19:39:21 +0000382
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -0700383 public abstract Target getDropTargetForLogging();
Winson Chung61fa4192011-06-12 15:15:29 -0700384}