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