Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 18 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.LauncherState.NORMAL; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 20 | |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 21 | import android.animation.AnimatorSet; |
| 22 | import android.animation.FloatArrayEvaluator; |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
| 25 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 27 | import android.content.res.ColorStateList; |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 29 | import android.content.res.TypedArray; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 30 | import android.graphics.ColorMatrix; |
| 31 | import android.graphics.ColorMatrixColorFilter; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 32 | import android.graphics.Rect; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 34 | import android.text.TextUtils; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 35 | import android.util.AttributeSet; |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 36 | import android.view.View; |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 37 | import android.view.View.OnClickListener; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 38 | import android.view.ViewGroup; |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 39 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 40 | import android.widget.TextView; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 41 | |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 42 | import com.android.launcher3.anim.Interpolators; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 43 | import com.android.launcher3.dragndrop.DragController; |
| 44 | import com.android.launcher3.dragndrop.DragLayer; |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 45 | import com.android.launcher3.dragndrop.DragOptions; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 46 | import com.android.launcher3.dragndrop.DragView; |
Tony Wickham | 6c82867 | 2017-02-27 13:30:20 -0800 | [diff] [blame] | 47 | import com.android.launcher3.util.Themes; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 48 | import com.android.launcher3.util.Thunk; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Implements a DropTarget. |
| 52 | */ |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 53 | public abstract class ButtonDropTarget extends TextView |
| 54 | implements DropTarget, DragController.DragListener, OnClickListener { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 55 | |
Sunny Goyal | ac00cba | 2017-11-13 15:58:01 -0800 | [diff] [blame^] | 56 | private static final int[] sTempCords = new int[2]; |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 57 | private static final int DRAG_VIEW_DROP_DURATION = 285; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 58 | |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 59 | private final boolean mHideParentOnDisable; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 60 | protected final Launcher mLauncher; |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 61 | |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 62 | private int mBottomDragPadding; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 63 | protected DropTargetBar mDropTargetBar; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 64 | |
| 65 | /** Whether this drop target is active for the current drag */ |
| 66 | protected boolean mActive; |
Sunny Goyal | 4583d09 | 2016-08-17 11:11:48 -0700 | [diff] [blame] | 67 | /** Whether an accessible drag is in progress */ |
| 68 | private boolean mAccessibleDrag; |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 69 | /** An item must be dragged at least this many pixels before this drop target is enabled. */ |
| 70 | private final int mDragDistanceThreshold; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 71 | |
| 72 | /** The paint applied to the drag view on hover */ |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 73 | protected int mHoverColor = 0; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 74 | |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 75 | protected CharSequence mText; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 76 | protected ColorStateList mOriginalTextColor; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 77 | protected Drawable mDrawable; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 78 | |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 79 | private AnimatorSet mCurrentColorAnim; |
Sunny Goyal | 316490e | 2015-06-02 09:38:28 -0700 | [diff] [blame] | 80 | @Thunk ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 81 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 82 | public ButtonDropTarget(Context context, AttributeSet attrs) { |
| 83 | this(context, attrs, 0); |
| 84 | } |
| 85 | |
| 86 | public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 87 | super(context, attrs, defStyle); |
Tony | 2fd0208 | 2016-10-07 12:50:01 -0700 | [diff] [blame] | 88 | mLauncher = Launcher.getLauncher(context); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 89 | |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 90 | Resources resources = getResources(); |
| 91 | mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding); |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 92 | |
| 93 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 94 | R.styleable.ButtonDropTarget, defStyle, 0); |
| 95 | mHideParentOnDisable = a.getBoolean(R.styleable.ButtonDropTarget_hideParentOnDisable, false); |
| 96 | a.recycle(); |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 97 | mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 100 | @Override |
| 101 | protected void onFinishInflate() { |
| 102 | super.onFinishInflate(); |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 103 | mText = getText(); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 104 | mOriginalTextColor = getTextColors(); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 107 | protected void setDrawable(int resId) { |
Sunny Goyal | e0cab30 | 2015-05-20 16:40:30 -0700 | [diff] [blame] | 108 | // We do not set the drawable in the xml as that inflates two drawables corresponding to |
| 109 | // drawableLeft and drawableStart. |
Sunny Goyal | 5931ca0 | 2017-06-19 17:29:48 -0700 | [diff] [blame] | 110 | setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0); |
| 111 | mDrawable = getCompoundDrawablesRelative()[0]; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 114 | public void setDropTargetBar(DropTargetBar dropTargetBar) { |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 115 | mDropTargetBar = dropTargetBar; |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 118 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 119 | public final void onDragEnter(DragObject d) { |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 120 | d.dragView.setColor(mHoverColor); |
Sunny Goyal | a52ecb0 | 2016-12-16 15:04:51 -0800 | [diff] [blame] | 121 | animateTextColor(mHoverColor); |
Sunny Goyal | d21301e | 2015-09-25 12:17:08 -0700 | [diff] [blame] | 122 | if (d.stateAnnouncer != null) { |
| 123 | d.stateAnnouncer.cancel(); |
| 124 | } |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 125 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 128 | @Override |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 129 | public void onDragOver(DragObject d) { |
| 130 | // Do nothing |
| 131 | } |
| 132 | |
Sunny Goyal | 9fc953b | 2015-08-17 12:24:25 -0700 | [diff] [blame] | 133 | protected void resetHoverColor() { |
Sunny Goyal | a52ecb0 | 2016-12-16 15:04:51 -0800 | [diff] [blame] | 134 | animateTextColor(mOriginalTextColor.getDefaultColor()); |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 137 | private void animateTextColor(int targetColor) { |
| 138 | if (mCurrentColorAnim != null) { |
| 139 | mCurrentColorAnim.cancel(); |
| 140 | } |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 141 | |
| 142 | mCurrentColorAnim = new AnimatorSet(); |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 143 | mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION); |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 144 | |
| 145 | if (mSrcFilter == null) { |
| 146 | mSrcFilter = new ColorMatrix(); |
| 147 | mDstFilter = new ColorMatrix(); |
| 148 | mCurrentFilter = new ColorMatrix(); |
| 149 | } |
| 150 | |
Tony Wickham | 6c82867 | 2017-02-27 13:30:20 -0800 | [diff] [blame] | 151 | Themes.setColorScaleOnMatrix(getTextColor(), mSrcFilter); |
| 152 | Themes.setColorScaleOnMatrix(targetColor, mDstFilter); |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 153 | ValueAnimator anim1 = ValueAnimator.ofObject( |
| 154 | new FloatArrayEvaluator(mCurrentFilter.getArray()), |
| 155 | mSrcFilter.getArray(), mDstFilter.getArray()); |
| 156 | anim1.addUpdateListener(new AnimatorUpdateListener() { |
| 157 | |
| 158 | @Override |
| 159 | public void onAnimationUpdate(ValueAnimator animation) { |
| 160 | mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter)); |
| 161 | invalidate(); |
| 162 | } |
| 163 | }); |
| 164 | |
| 165 | mCurrentColorAnim.play(anim1); |
| 166 | mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor)); |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 167 | mCurrentColorAnim.start(); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 170 | @Override |
| 171 | public final void onDragExit(DragObject d) { |
| 172 | if (!d.dragComplete) { |
| 173 | d.dragView.setColor(0); |
| 174 | resetHoverColor(); |
| 175 | } else { |
| 176 | // Restore the hover color |
| 177 | d.dragView.setColor(mHoverColor); |
| 178 | } |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 181 | @Override |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 182 | public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { |
Sunny Goyal | 1ce9c47 | 2017-10-03 16:17:32 -0700 | [diff] [blame] | 183 | mActive = supportsDrop(dragObject.dragInfo); |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 184 | mDrawable.setColorFilter(null); |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 185 | if (mCurrentColorAnim != null) { |
| 186 | mCurrentColorAnim.cancel(); |
| 187 | mCurrentColorAnim = null; |
| 188 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 189 | setTextColor(mOriginalTextColor); |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 190 | (mHideParentOnDisable ? ((ViewGroup) getParent()) : this) |
| 191 | .setVisibility(mActive ? View.VISIBLE : View.GONE); |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 192 | |
| 193 | mAccessibleDrag = options.isAccessibleDrag; |
| 194 | setOnClickListener(mAccessibleDrag ? this : null); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public final boolean acceptDrop(DragObject dragObject) { |
Sunny Goyal | 1ce9c47 | 2017-10-03 16:17:32 -0700 | [diff] [blame] | 199 | return supportsDrop(dragObject.dragInfo); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Sunny Goyal | 1ce9c47 | 2017-10-03 16:17:32 -0700 | [diff] [blame] | 202 | protected abstract boolean supportsDrop(ItemInfo info); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 203 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 204 | public boolean supportsAccessibilityDrop(ItemInfo info) { |
| 205 | return supportsDrop(info); |
| 206 | } |
| 207 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 208 | @Override |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 209 | public boolean isDropEnabled() { |
Sunny Goyal | 4583d09 | 2016-08-17 11:11:48 -0700 | [diff] [blame] | 210 | return mActive && (mAccessibleDrag || |
| 211 | mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 214 | @Override |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 215 | public void onDragEnd() { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 216 | mActive = false; |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 217 | setOnClickListener(null); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 220 | /** |
| 221 | * On drop animate the dropView to the icon. |
| 222 | */ |
| 223 | @Override |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 224 | public void onDrop(final DragObject d, final DragOptions options) { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 225 | final DragLayer dragLayer = mLauncher.getDragLayer(); |
| 226 | final Rect from = new Rect(); |
| 227 | dragLayer.getViewRectRelativeToSelf(d.dragView, from); |
| 228 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 229 | final Rect to = getIconRect(d); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 230 | final float scale = (float) to.width() / from.width(); |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 231 | mDropTargetBar.deferOnDragEnd(); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 232 | |
| 233 | Runnable onAnimationEndRunnable = new Runnable() { |
| 234 | @Override |
| 235 | public void run() { |
| 236 | completeDrop(d); |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 237 | mDropTargetBar.onDragEnd(); |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 238 | mLauncher.getStateManager().goToState(NORMAL); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 239 | } |
| 240 | }; |
| 241 | dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, |
Sunny Goyal | dec3a90 | 2017-01-25 18:23:36 -0800 | [diff] [blame] | 242 | DRAG_VIEW_DROP_DURATION, |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 243 | Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable, |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 244 | DragLayer.ANIMATION_END_DISAPPEAR, null); |
| 245 | } |
| 246 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 247 | public abstract int getAccessibilityAction(); |
| 248 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 249 | @Override |
| 250 | public void prepareAccessibilityDrop() { } |
| 251 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 252 | public abstract void onAccessibilityDrop(View view, ItemInfo item); |
| 253 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 254 | public abstract void completeDrop(DragObject d); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 255 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 256 | @Override |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 257 | public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) { |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 258 | super.getHitRect(outRect); |
| 259 | outRect.bottom += mBottomDragPadding; |
Winson Chung | 156ab5b | 2013-07-12 14:14:16 -0700 | [diff] [blame] | 260 | |
Sunny Goyal | ac00cba | 2017-11-13 15:58:01 -0800 | [diff] [blame^] | 261 | sTempCords[0] = sTempCords[1] = 0; |
| 262 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords); |
| 263 | outRect.offsetTo(sTempCords[0], sTempCords[1]); |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 266 | public Rect getIconRect(DragObject dragObject) { |
| 267 | int viewWidth = dragObject.dragView.getMeasuredWidth(); |
| 268 | int viewHeight = dragObject.dragView.getMeasuredHeight(); |
| 269 | int drawableWidth = mDrawable.getIntrinsicWidth(); |
| 270 | int drawableHeight = mDrawable.getIntrinsicHeight(); |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 271 | DragLayer dragLayer = mLauncher.getDragLayer(); |
| 272 | |
| 273 | // Find the rect to animate to (the view is center aligned) |
| 274 | Rect to = new Rect(); |
| 275 | dragLayer.getViewRectRelativeToSelf(this, to); |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 276 | |
| 277 | final int width = drawableWidth; |
| 278 | final int height = drawableHeight; |
| 279 | |
| 280 | final int left; |
| 281 | final int right; |
| 282 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 283 | if (Utilities.isRtl(getResources())) { |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 284 | right = to.right - getPaddingRight(); |
| 285 | left = right - width; |
| 286 | } else { |
| 287 | left = to.left + getPaddingLeft(); |
| 288 | right = left + width; |
| 289 | } |
| 290 | |
| 291 | final int top = to.top + (getMeasuredHeight() - height) / 2; |
| 292 | final int bottom = top + height; |
| 293 | |
| 294 | to.set(left, top, right, bottom); |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 295 | |
| 296 | // Center the destination rect about the trash icon |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 297 | final int xOffset = (int) -(viewWidth - width) / 2; |
| 298 | final int yOffset = (int) -(viewHeight - height) / 2; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 299 | to.offset(xOffset, yOffset); |
| 300 | |
| 301 | return to; |
| 302 | } |
| 303 | |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 304 | @Override |
| 305 | public void onClick(View v) { |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 306 | mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null); |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 307 | } |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 308 | |
| 309 | public int getTextColor() { |
| 310 | return getTextColors().getDefaultColor(); |
| 311 | } |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 312 | |
| 313 | /** |
| 314 | * Returns True if any update was made. |
| 315 | */ |
| 316 | public boolean updateText(boolean hide) { |
| 317 | if ((hide && getText().toString().isEmpty()) || (!hide && mText.equals(getText()))) { |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | setText(hide ? "" : mText); |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | public boolean isTextTruncated() { |
| 326 | int availableWidth = getMeasuredWidth(); |
| 327 | if (mHideParentOnDisable) { |
| 328 | ViewGroup parent = (ViewGroup) getParent(); |
| 329 | availableWidth = parent.getMeasuredWidth() - parent.getPaddingLeft() |
| 330 | - parent.getPaddingRight(); |
| 331 | } |
| 332 | availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth() |
| 333 | + getCompoundDrawablePadding()); |
| 334 | CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth, |
| 335 | TextUtils.TruncateAt.END); |
| 336 | return !mText.equals(displayedText); |
| 337 | } |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 338 | } |