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