blob: c35ab97fbb36ce5bb194a40085fdac741205dfd7 [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;
Tony Wickham6c828672017-02-27 13:30:20 -080048import com.android.launcher3.util.Themes;
Sunny Goyalfa401a12015-04-10 13:45:42 -070049import com.android.launcher3.util.Thunk;
Winson Chung61fa4192011-06-12 15:15:29 -070050
51/**
52 * Implements a DropTarget.
53 */
Sunny Goyal1a70cef2015-04-22 11:29:51 -070054public abstract class ButtonDropTarget extends TextView
55 implements DropTarget, DragController.DragListener, OnClickListener {
Sunny Goyalfa401a12015-04-10 13:45:42 -070056
Sunny Goyalac00cba2017-11-13 15:58:01 -080057 private static final int[] sTempCords = new int[2];
Tony Wickhamb54c4a32015-09-11 08:40:20 -070058 private static final int DRAG_VIEW_DROP_DURATION = 285;
Winson Chung61fa4192011-06-12 15:15:29 -070059
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080060 public static final int TOOLTIP_DEFAULT = 0;
61 public static final int TOOLTIP_LEFT = 1;
62 public static final int TOOLTIP_RIGHT = 2;
63
Sunny Goyal47328fd2016-05-25 18:56:41 -070064 protected final Launcher mLauncher;
Sunny Goyalf37a2142016-03-24 17:28:25 -070065
Winson Chunga62e9fd2011-07-11 15:20:48 -070066 private int mBottomDragPadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070067 protected DropTargetBar mDropTargetBar;
Winson Chung61fa4192011-06-12 15:15:29 -070068
69 /** Whether this drop target is active for the current drag */
70 protected boolean mActive;
Sunny Goyal4583d092016-08-17 11:11:48 -070071 /** Whether an accessible drag is in progress */
72 private boolean mAccessibleDrag;
Tony Wickham855b1b52016-03-28 16:56:30 -070073 /** An item must be dragged at least this many pixels before this drop target is enabled. */
74 private final int mDragDistanceThreshold;
Winson Chung61fa4192011-06-12 15:15:29 -070075
76 /** The paint applied to the drag view on hover */
Winson Chung61967cb2012-02-28 18:11:33 -080077 protected int mHoverColor = 0;
Winson Chung61fa4192011-06-12 15:15:29 -070078
Jon Mirandabfaa4a42017-08-21 15:31:51 -070079 protected CharSequence mText;
Sunny Goyalfa401a12015-04-10 13:45:42 -070080 protected ColorStateList mOriginalTextColor;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070081 protected Drawable mDrawable;
Sunny Goyald1b3f5c2018-01-18 17:14:05 -080082 private boolean mTextVisible = true;
83
84 private PopupWindow mToolTip;
85 private int mToolTipLocation;
Sunny Goyalfa401a12015-04-10 13:45:42 -070086
Sunny Goyal3a644ed2015-05-21 10:28:02 -070087 private AnimatorSet mCurrentColorAnim;
Sunny Goyal316490e2015-06-02 09:38:28 -070088 @Thunk ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter;
Sunny Goyal3a644ed2015-05-21 10:28:02 -070089
Winson Chung61fa4192011-06-12 15:15:29 -070090 public ButtonDropTarget(Context context, AttributeSet attrs) {
91 this(context, attrs, 0);
92 }
93
94 public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
95 super(context, attrs, defStyle);
Tony2fd02082016-10-07 12:50:01 -070096 mLauncher = Launcher.getLauncher(context);
Sunny Goyal47328fd2016-05-25 18:56:41 -070097
Tony Wickham855b1b52016-03-28 16:56:30 -070098 Resources resources = getResources();
99 mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
Tony Wickham855b1b52016-03-28 16:56:30 -0700100 mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700101 }
102
Sunny Goyalfa401a12015-04-10 13:45:42 -0700103 @Override
104 protected void onFinishInflate() {
105 super.onFinishInflate();
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700106 mText = getText();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700107 mOriginalTextColor = getTextColors();
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800108 setContentDescription(mText);
Winson Chung61fa4192011-06-12 15:15:29 -0700109 }
110
Winson Chung1054d4e2018-03-05 19:39:21 +0000111 protected void updateText(int resId) {
112 setText(resId);
113 mText = getText();
114 setContentDescription(mText);
115 }
116
Sunny Goyalfa401a12015-04-10 13:45:42 -0700117 protected void setDrawable(int resId) {
Sunny Goyale0cab302015-05-20 16:40:30 -0700118 // We do not set the drawable in the xml as that inflates two drawables corresponding to
119 // drawableLeft and drawableStart.
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800120 if (mTextVisible) {
121 setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0);
122 mDrawable = getCompoundDrawablesRelative()[0];
123 } else {
124 setCompoundDrawablesRelativeWithIntrinsicBounds(0, resId, 0, 0);
125 mDrawable = getCompoundDrawablesRelative()[1];
126 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700127 }
128
Sunny Goyal47328fd2016-05-25 18:56:41 -0700129 public void setDropTargetBar(DropTargetBar dropTargetBar) {
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700130 mDropTargetBar = dropTargetBar;
Adam Cohend4d7aa52011-07-19 21:47:37 -0700131 }
132
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800133 private void hideTooltip() {
134 if (mToolTip != null) {
135 mToolTip.dismiss();
136 mToolTip = null;
137 }
138 }
139
Sunny Goyalfa401a12015-04-10 13:45:42 -0700140 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -0700141 public final void onDragEnter(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800142 if (!d.accessibleDrag && !mTextVisible) {
143 // Show tooltip
144 hideTooltip();
145
146 TextView message = (TextView) LayoutInflater.from(getContext()).inflate(
147 R.layout.drop_target_tool_tip, null);
148 message.setText(mText);
149
150 mToolTip = new PopupWindow(message, WRAP_CONTENT, WRAP_CONTENT);
151 int x = 0, y = 0;
152 if (mToolTipLocation != TOOLTIP_DEFAULT) {
153 y = -getMeasuredHeight();
154 message.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
155 if (mToolTipLocation == TOOLTIP_LEFT) {
156 x = - getMeasuredWidth() - message.getMeasuredWidth() / 2;
157 } else {
158 x = getMeasuredWidth() / 2 + message.getMeasuredWidth() / 2;
159 }
160 }
161 mToolTip.showAsDropDown(this, x, y);
162 }
163
Winson Chung61967cb2012-02-28 18:11:33 -0800164 d.dragView.setColor(mHoverColor);
Sunny Goyala52ecb02016-12-16 15:04:51 -0800165 animateTextColor(mHoverColor);
Sunny Goyald21301e2015-09-25 12:17:08 -0700166 if (d.stateAnnouncer != null) {
167 d.stateAnnouncer.cancel();
168 }
Sunny Goyale78e3d72015-09-24 11:23:31 -0700169 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Winson Chung61fa4192011-06-12 15:15:29 -0700170 }
171
Sunny Goyalfa401a12015-04-10 13:45:42 -0700172 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700173 public void onDragOver(DragObject d) {
174 // Do nothing
175 }
176
Sunny Goyal9fc953b2015-08-17 12:24:25 -0700177 protected void resetHoverColor() {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800178 animateTextColor(mOriginalTextColor.getDefaultColor());
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700179 }
180
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700181 private void animateTextColor(int targetColor) {
182 if (mCurrentColorAnim != null) {
183 mCurrentColorAnim.cancel();
184 }
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700185
186 mCurrentColorAnim = new AnimatorSet();
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700187 mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700188
189 if (mSrcFilter == null) {
190 mSrcFilter = new ColorMatrix();
191 mDstFilter = new ColorMatrix();
192 mCurrentFilter = new ColorMatrix();
193 }
194
Mehdi Alizadeh3e024c02018-04-30 11:15:39 -0700195 int defaultTextColor = mOriginalTextColor.getDefaultColor();
196 Themes.setColorChangeOnMatrix(defaultTextColor, getTextColor(), mSrcFilter);
197 Themes.setColorChangeOnMatrix(defaultTextColor, targetColor, mDstFilter);
198
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700199 ValueAnimator anim1 = ValueAnimator.ofObject(
200 new FloatArrayEvaluator(mCurrentFilter.getArray()),
201 mSrcFilter.getArray(), mDstFilter.getArray());
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800202 anim1.addUpdateListener((anim) -> {
203 mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
204 invalidate();
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700205 });
206
207 mCurrentColorAnim.play(anim1);
208 mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700209 mCurrentColorAnim.start();
Winson Chung61fa4192011-06-12 15:15:29 -0700210 }
211
Sunny Goyalfa401a12015-04-10 13:45:42 -0700212 @Override
213 public final void onDragExit(DragObject d) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800214 hideTooltip();
215
Sunny Goyalfa401a12015-04-10 13:45:42 -0700216 if (!d.dragComplete) {
217 d.dragView.setColor(0);
218 resetHoverColor();
219 } else {
220 // Restore the hover color
221 d.dragView.setColor(mHoverColor);
222 }
Winson Chung61fa4192011-06-12 15:15:29 -0700223 }
224
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700225 @Override
Sunny Goyal94b510c2016-08-16 15:36:48 -0700226 public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700227 mActive = supportsDrop(dragObject.dragInfo);
Sunny Goyal3a644ed2015-05-21 10:28:02 -0700228 mDrawable.setColorFilter(null);
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700229 if (mCurrentColorAnim != null) {
230 mCurrentColorAnim.cancel();
231 mCurrentColorAnim = null;
232 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700233 setTextColor(mOriginalTextColor);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800234 setVisibility(mActive ? View.VISIBLE : View.GONE);
Sunny Goyal94b510c2016-08-16 15:36:48 -0700235
236 mAccessibleDrag = options.isAccessibleDrag;
237 setOnClickListener(mAccessibleDrag ? this : null);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700238 }
239
240 @Override
241 public final boolean acceptDrop(DragObject dragObject) {
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700242 return supportsDrop(dragObject.dragInfo);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700243 }
244
Sunny Goyal1ce9c472017-10-03 16:17:32 -0700245 protected abstract boolean supportsDrop(ItemInfo info);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700246
Winson Chung1054d4e2018-03-05 19:39:21 +0000247 public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700248
Sunny Goyalfa401a12015-04-10 13:45:42 -0700249 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700250 public boolean isDropEnabled() {
Sunny Goyal4583d092016-08-17 11:11:48 -0700251 return mActive && (mAccessibleDrag ||
252 mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold);
Winson Chung61fa4192011-06-12 15:15:29 -0700253 }
254
Sunny Goyalfa401a12015-04-10 13:45:42 -0700255 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700256 public void onDragEnd() {
Sunny Goyalfa401a12015-04-10 13:45:42 -0700257 mActive = false;
Sunny Goyal94b510c2016-08-16 15:36:48 -0700258 setOnClickListener(null);
Winson Chung61fa4192011-06-12 15:15:29 -0700259 }
260
Sunny Goyalfa401a12015-04-10 13:45:42 -0700261 /**
262 * On drop animate the dropView to the icon.
263 */
264 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700265 public void onDrop(final DragObject d, final DragOptions options) {
Sunny Goyalfa401a12015-04-10 13:45:42 -0700266 final DragLayer dragLayer = mLauncher.getDragLayer();
267 final Rect from = new Rect();
268 dragLayer.getViewRectRelativeToSelf(d.dragView, from);
269
Sunny Goyal0f76b562016-12-13 19:37:10 -0800270 final Rect to = getIconRect(d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700271 final float scale = (float) to.width() / from.width();
Tony Wickhamb54c4a32015-09-11 08:40:20 -0700272 mDropTargetBar.deferOnDragEnd();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700273
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800274 Runnable onAnimationEndRunnable = () -> {
275 completeDrop(d);
276 mDropTargetBar.onDragEnd();
277 mLauncher.getStateManager().goToState(NORMAL);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700278 };
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800279
Sunny Goyalfa401a12015-04-10 13:45:42 -0700280 dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
Sunny Goyaldec3a902017-01-25 18:23:36 -0800281 DRAG_VIEW_DROP_DURATION,
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -0700282 Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable,
Sunny Goyalfa401a12015-04-10 13:45:42 -0700283 DragLayer.ANIMATION_END_DISAPPEAR, null);
284 }
285
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700286 public abstract int getAccessibilityAction();
287
Sunny Goyale9b651e2015-04-24 11:44:51 -0700288 @Override
289 public void prepareAccessibilityDrop() { }
290
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700291 public abstract void onAccessibilityDrop(View view, ItemInfo item);
292
Sunny Goyal0f76b562016-12-13 19:37:10 -0800293 public abstract void completeDrop(DragObject d);
Sunny Goyalfa401a12015-04-10 13:45:42 -0700294
Winson Chung61fa4192011-06-12 15:15:29 -0700295 @Override
Adam Cohen7d30a372013-07-01 17:03:59 -0700296 public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) {
Winson Chunga62e9fd2011-07-11 15:20:48 -0700297 super.getHitRect(outRect);
298 outRect.bottom += mBottomDragPadding;
Winson Chung156ab5b2013-07-12 14:14:16 -0700299
Sunny Goyalac00cba2017-11-13 15:58:01 -0800300 sTempCords[0] = sTempCords[1] = 0;
301 mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords);
302 outRect.offsetTo(sTempCords[0], sTempCords[1]);
Winson Chunga62e9fd2011-07-11 15:20:48 -0700303 }
304
Sunny Goyal0f76b562016-12-13 19:37:10 -0800305 public Rect getIconRect(DragObject dragObject) {
306 int viewWidth = dragObject.dragView.getMeasuredWidth();
307 int viewHeight = dragObject.dragView.getMeasuredHeight();
308 int drawableWidth = mDrawable.getIntrinsicWidth();
309 int drawableHeight = mDrawable.getIntrinsicHeight();
Winson Chung61967cb2012-02-28 18:11:33 -0800310 DragLayer dragLayer = mLauncher.getDragLayer();
311
312 // Find the rect to animate to (the view is center aligned)
313 Rect to = new Rect();
314 dragLayer.getViewRectRelativeToSelf(this, to);
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800315
316 final int width = drawableWidth;
317 final int height = drawableHeight;
318
319 final int left;
320 final int right;
321
Sunny Goyal70660032015-05-14 00:07:08 -0700322 if (Utilities.isRtl(getResources())) {
Fabrice Di Megliod6a33c62013-02-06 15:40:46 -0800323 right = to.right - getPaddingRight();
324 left = right - width;
325 } else {
326 left = to.left + getPaddingLeft();
327 right = left + width;
328 }
329
330 final int top = to.top + (getMeasuredHeight() - height) / 2;
331 final int bottom = top + height;
332
333 to.set(left, top, right, bottom);
Winson Chung61967cb2012-02-28 18:11:33 -0800334
335 // Center the destination rect about the trash icon
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800336 final int xOffset = -(viewWidth - width) / 2;
337 final int yOffset = -(viewHeight - height) / 2;
Winson Chung61967cb2012-02-28 18:11:33 -0800338 to.offset(xOffset, yOffset);
339
340 return to;
341 }
342
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700343 @Override
344 public void onClick(View v) {
Sunny Goyalae502842016-06-17 08:43:56 -0700345 mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null);
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700346 }
Sunny Goyalfe0d1f22015-04-28 22:01:31 -0700347
348 public int getTextColor() {
349 return getTextColors().getDefaultColor();
350 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700351
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800352 public void setTextVisible(boolean isVisible) {
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800353 CharSequence newText = isVisible ? mText : "";
354 if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) {
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800355 mTextVisible = isVisible;
Jon Mirandadf1ffb92018-02-06 10:31:38 -0800356 setText(newText);
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800357 if (mTextVisible) {
358 setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null);
359 } else {
360 setCompoundDrawablesRelativeWithIntrinsicBounds(null, mDrawable, null, null);
361 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700362 }
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700363 }
364
Sunny Goyald1b3f5c2018-01-18 17:14:05 -0800365 public void setToolTipLocation(int location) {
366 mToolTipLocation = location;
367 hideTooltip();
368 }
369
370 public boolean isTextTruncated(int availableWidth) {
Jon Mirandabfaa4a42017-08-21 15:31:51 -0700371 availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth()
372 + getCompoundDrawablePadding());
373 CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth,
374 TextUtils.TruncateAt.END);
375 return !mText.equals(displayedText);
376 }
Winson Chung1054d4e2018-03-05 19:39:21 +0000377
378 public abstract int getControlTypeForLogging();
Winson Chung61fa4192011-06-12 15:15:29 -0700379}