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 | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 19 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 20 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.LauncherState.NORMAL; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 22 | |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 23 | import android.animation.AnimatorSet; |
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; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 29 | import android.text.TextUtils; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 31 | import android.util.Property; |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 32 | import android.view.LayoutInflater; |
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 | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 35 | import android.view.accessibility.AccessibilityEvent; |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 36 | import android.widget.PopupWindow; |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 37 | import android.widget.TextView; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 38 | |
Yogisha Dixit | a3a6f51 | 2021-04-28 13:45:37 +0100 | [diff] [blame] | 39 | import androidx.appcompat.content.res.AppCompatResources; |
| 40 | |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 41 | import com.android.launcher3.anim.Interpolators; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 42 | import com.android.launcher3.dragndrop.DragController; |
| 43 | import com.android.launcher3.dragndrop.DragLayer; |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 44 | import com.android.launcher3.dragndrop.DragOptions; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 45 | import com.android.launcher3.model.data.ItemInfo; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Implements a DropTarget. |
| 49 | */ |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 50 | public abstract class ButtonDropTarget extends TextView |
| 51 | implements DropTarget, DragController.DragListener, OnClickListener { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 52 | |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 53 | private static final Property<ButtonDropTarget, Integer> TEXT_COLOR = |
| 54 | new Property<ButtonDropTarget, Integer>(Integer.TYPE, "textColor") { |
| 55 | |
| 56 | @Override |
| 57 | public Integer get(ButtonDropTarget target) { |
| 58 | return target.getTextColor(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void set(ButtonDropTarget target, Integer value) { |
| 63 | target.setTextColor(value); |
| 64 | } |
| 65 | }; |
| 66 | |
Sunny Goyal | ac00cba | 2017-11-13 15:58:01 -0800 | [diff] [blame] | 67 | private static final int[] sTempCords = new int[2]; |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 68 | private static final int DRAG_VIEW_DROP_DURATION = 285; |
Steven Ng | 6a2acfa | 2021-03-19 13:23:53 +0000 | [diff] [blame] | 69 | private static final float DRAG_VIEW_HOVER_OVER_OPACITY = 0.65f; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 70 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 71 | public static final int TOOLTIP_DEFAULT = 0; |
| 72 | public static final int TOOLTIP_LEFT = 1; |
| 73 | public static final int TOOLTIP_RIGHT = 2; |
| 74 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 75 | protected final Launcher mLauncher; |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 76 | |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 77 | private int mBottomDragPadding; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 78 | protected DropTargetBar mDropTargetBar; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 79 | |
| 80 | /** Whether this drop target is active for the current drag */ |
| 81 | protected boolean mActive; |
Sunny Goyal | 4583d09 | 2016-08-17 11:11:48 -0700 | [diff] [blame] | 82 | /** Whether an accessible drag is in progress */ |
| 83 | private boolean mAccessibleDrag; |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 84 | /** An item must be dragged at least this many pixels before this drop target is enabled. */ |
| 85 | private final int mDragDistanceThreshold; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 86 | |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 87 | protected CharSequence mText; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 88 | protected ColorStateList mOriginalTextColor; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 89 | protected Drawable mDrawable; |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 90 | private boolean mTextVisible = true; |
| 91 | |
| 92 | private PopupWindow mToolTip; |
| 93 | private int mToolTipLocation; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 94 | |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 95 | private AnimatorSet mCurrentColorAnim; |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 96 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 97 | public ButtonDropTarget(Context context, AttributeSet attrs) { |
| 98 | this(context, attrs, 0); |
| 99 | } |
| 100 | |
| 101 | public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 102 | super(context, attrs, defStyle); |
Tony | 2fd0208 | 2016-10-07 12:50:01 -0700 | [diff] [blame] | 103 | mLauncher = Launcher.getLauncher(context); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 104 | |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 105 | Resources resources = getResources(); |
| 106 | mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding); |
Tony Wickham | 855b1b5 | 2016-03-28 16:56:30 -0700 | [diff] [blame] | 107 | mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 110 | @Override |
| 111 | protected void onFinishInflate() { |
| 112 | super.onFinishInflate(); |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 113 | mText = getText(); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 114 | mOriginalTextColor = getTextColors(); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 115 | setContentDescription(mText); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 118 | protected void updateText(int resId) { |
| 119 | setText(resId); |
| 120 | mText = getText(); |
| 121 | setContentDescription(mText); |
| 122 | } |
| 123 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 124 | protected void setDrawable(int resId) { |
Sunny Goyal | e0cab30 | 2015-05-20 16:40:30 -0700 | [diff] [blame] | 125 | // We do not set the drawable in the xml as that inflates two drawables corresponding to |
| 126 | // drawableLeft and drawableStart. |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 127 | if (mTextVisible) { |
| 128 | setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0); |
| 129 | mDrawable = getCompoundDrawablesRelative()[0]; |
| 130 | } else { |
| 131 | setCompoundDrawablesRelativeWithIntrinsicBounds(0, resId, 0, 0); |
| 132 | mDrawable = getCompoundDrawablesRelative()[1]; |
| 133 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 136 | public void setDropTargetBar(DropTargetBar dropTargetBar) { |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 137 | mDropTargetBar = dropTargetBar; |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 140 | private void hideTooltip() { |
| 141 | if (mToolTip != null) { |
| 142 | mToolTip.dismiss(); |
| 143 | mToolTip = null; |
| 144 | } |
| 145 | } |
| 146 | |
Yogisha Dixit | a3a6f51 | 2021-04-28 13:45:37 +0100 | [diff] [blame] | 147 | private void setBackgroundDrawable(int resId) { |
| 148 | Drawable bd = AppCompatResources.getDrawable(getContext(), resId); |
| 149 | setBackground(bd); |
| 150 | } |
| 151 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 152 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 153 | public final void onDragEnter(DragObject d) { |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 154 | if (!mAccessibleDrag && !mTextVisible) { |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 155 | // Show tooltip |
| 156 | hideTooltip(); |
| 157 | |
| 158 | TextView message = (TextView) LayoutInflater.from(getContext()).inflate( |
| 159 | R.layout.drop_target_tool_tip, null); |
| 160 | message.setText(mText); |
| 161 | |
| 162 | mToolTip = new PopupWindow(message, WRAP_CONTENT, WRAP_CONTENT); |
| 163 | int x = 0, y = 0; |
| 164 | if (mToolTipLocation != TOOLTIP_DEFAULT) { |
| 165 | y = -getMeasuredHeight(); |
| 166 | message.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); |
| 167 | if (mToolTipLocation == TOOLTIP_LEFT) { |
| 168 | x = - getMeasuredWidth() - message.getMeasuredWidth() / 2; |
| 169 | } else { |
| 170 | x = getMeasuredWidth() / 2 + message.getMeasuredWidth() / 2; |
| 171 | } |
| 172 | } |
| 173 | mToolTip.showAsDropDown(this, x, y); |
| 174 | } |
| 175 | |
Steven Ng | 6a2acfa | 2021-03-19 13:23:53 +0000 | [diff] [blame] | 176 | d.dragView.setAlpha(DRAG_VIEW_HOVER_OVER_OPACITY); |
Yogisha Dixit | a3a6f51 | 2021-04-28 13:45:37 +0100 | [diff] [blame] | 177 | setBackgroundDrawable(R.drawable.drop_target_frame_hover); |
Sunny Goyal | d21301e | 2015-09-25 12:17:08 -0700 | [diff] [blame] | 178 | if (d.stateAnnouncer != null) { |
| 179 | d.stateAnnouncer.cancel(); |
| 180 | } |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 181 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 184 | @Override |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 185 | public void onDragOver(DragObject d) { |
| 186 | // Do nothing |
| 187 | } |
| 188 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 189 | @Override |
| 190 | public final void onDragExit(DragObject d) { |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 191 | hideTooltip(); |
| 192 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 193 | if (!d.dragComplete) { |
Steven Ng | 6a2acfa | 2021-03-19 13:23:53 +0000 | [diff] [blame] | 194 | d.dragView.setAlpha(1f); |
Yogisha Dixit | a3a6f51 | 2021-04-28 13:45:37 +0100 | [diff] [blame] | 195 | setBackgroundDrawable(R.drawable.drop_target_frame); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 196 | } else { |
Steven Ng | 6a2acfa | 2021-03-19 13:23:53 +0000 | [diff] [blame] | 197 | d.dragView.setAlpha(DRAG_VIEW_HOVER_OVER_OPACITY); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 198 | } |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 201 | @Override |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 202 | public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 203 | mActive = !options.isKeyboardDrag && supportsDrop(dragObject.dragInfo); |
Sunny Goyal | 3a644ed | 2015-05-21 10:28:02 -0700 | [diff] [blame] | 204 | mDrawable.setColorFilter(null); |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 205 | if (mCurrentColorAnim != null) { |
| 206 | mCurrentColorAnim.cancel(); |
| 207 | mCurrentColorAnim = null; |
| 208 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 209 | setTextColor(mOriginalTextColor); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 210 | setVisibility(mActive ? View.VISIBLE : View.GONE); |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 211 | |
| 212 | mAccessibleDrag = options.isAccessibleDrag; |
| 213 | setOnClickListener(mAccessibleDrag ? this : null); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public final boolean acceptDrop(DragObject dragObject) { |
Sunny Goyal | 1ce9c47 | 2017-10-03 16:17:32 -0700 | [diff] [blame] | 218 | return supportsDrop(dragObject.dragInfo); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Sunny Goyal | 1ce9c47 | 2017-10-03 16:17:32 -0700 | [diff] [blame] | 221 | protected abstract boolean supportsDrop(ItemInfo info); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 222 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 223 | public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view); |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 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 boolean isDropEnabled() { |
Sunny Goyal | 4583d09 | 2016-08-17 11:11:48 -0700 | [diff] [blame] | 227 | return mActive && (mAccessibleDrag || |
| 228 | mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 231 | @Override |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 232 | public void onDragEnd() { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 233 | mActive = false; |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 234 | setOnClickListener(null); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 237 | /** |
| 238 | * On drop animate the dropView to the icon. |
| 239 | */ |
| 240 | @Override |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 241 | public void onDrop(final DragObject d, final DragOptions options) { |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 242 | if (options.isFlingToDelete) { |
| 243 | // FlingAnimation handles the animation and then calls completeDrop(). |
| 244 | return; |
| 245 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 246 | final DragLayer dragLayer = mLauncher.getDragLayer(); |
| 247 | final Rect from = new Rect(); |
| 248 | dragLayer.getViewRectRelativeToSelf(d.dragView, from); |
| 249 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 250 | final Rect to = getIconRect(d); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 251 | final float scale = (float) to.width() / from.width(); |
Steven Ng | cf93ef6 | 2021-04-22 17:44:22 +0100 | [diff] [blame] | 252 | d.dragView.detachContentView(/* reattachToPreviousParent= */ true); |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 253 | mDropTargetBar.deferOnDragEnd(); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 254 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 255 | Runnable onAnimationEndRunnable = () -> { |
| 256 | completeDrop(d); |
| 257 | mDropTargetBar.onDragEnd(); |
| 258 | mLauncher.getStateManager().goToState(NORMAL); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 259 | }; |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 260 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 261 | 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] | 262 | DRAG_VIEW_DROP_DURATION, |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 263 | Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable, |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 264 | DragLayer.ANIMATION_END_DISAPPEAR, null); |
| 265 | } |
| 266 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 267 | public abstract int getAccessibilityAction(); |
| 268 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 269 | @Override |
| 270 | public void prepareAccessibilityDrop() { } |
| 271 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 272 | public abstract void onAccessibilityDrop(View view, ItemInfo item); |
| 273 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 274 | public abstract void completeDrop(DragObject d); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 275 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 276 | @Override |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 277 | public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) { |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 278 | super.getHitRect(outRect); |
| 279 | outRect.bottom += mBottomDragPadding; |
Winson Chung | 156ab5b | 2013-07-12 14:14:16 -0700 | [diff] [blame] | 280 | |
Sunny Goyal | ac00cba | 2017-11-13 15:58:01 -0800 | [diff] [blame] | 281 | sTempCords[0] = sTempCords[1] = 0; |
| 282 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords); |
| 283 | outRect.offsetTo(sTempCords[0], sTempCords[1]); |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 286 | public Rect getIconRect(DragObject dragObject) { |
| 287 | int viewWidth = dragObject.dragView.getMeasuredWidth(); |
| 288 | int viewHeight = dragObject.dragView.getMeasuredHeight(); |
| 289 | int drawableWidth = mDrawable.getIntrinsicWidth(); |
| 290 | int drawableHeight = mDrawable.getIntrinsicHeight(); |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 291 | DragLayer dragLayer = mLauncher.getDragLayer(); |
| 292 | |
| 293 | // Find the rect to animate to (the view is center aligned) |
| 294 | Rect to = new Rect(); |
| 295 | dragLayer.getViewRectRelativeToSelf(this, to); |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 296 | |
| 297 | final int width = drawableWidth; |
| 298 | final int height = drawableHeight; |
| 299 | |
| 300 | final int left; |
| 301 | final int right; |
| 302 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 303 | if (Utilities.isRtl(getResources())) { |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 304 | right = to.right - getPaddingRight(); |
| 305 | left = right - width; |
| 306 | } else { |
| 307 | left = to.left + getPaddingLeft(); |
| 308 | right = left + width; |
| 309 | } |
| 310 | |
| 311 | final int top = to.top + (getMeasuredHeight() - height) / 2; |
| 312 | final int bottom = top + height; |
| 313 | |
| 314 | to.set(left, top, right, bottom); |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 315 | |
| 316 | // Center the destination rect about the trash icon |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 317 | final int xOffset = -(viewWidth - width) / 2; |
| 318 | final int yOffset = -(viewHeight - height) / 2; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 319 | to.offset(xOffset, yOffset); |
| 320 | |
| 321 | return to; |
| 322 | } |
| 323 | |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 324 | @Override |
| 325 | public void onClick(View v) { |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 326 | mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null); |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 327 | } |
Sunny Goyal | fe0d1f2 | 2015-04-28 22:01:31 -0700 | [diff] [blame] | 328 | |
| 329 | public int getTextColor() { |
| 330 | return getTextColors().getDefaultColor(); |
| 331 | } |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 332 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 333 | public void setTextVisible(boolean isVisible) { |
Jon Miranda | df1ffb9 | 2018-02-06 10:31:38 -0800 | [diff] [blame] | 334 | CharSequence newText = isVisible ? mText : ""; |
| 335 | if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) { |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 336 | mTextVisible = isVisible; |
Jon Miranda | df1ffb9 | 2018-02-06 10:31:38 -0800 | [diff] [blame] | 337 | setText(newText); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 338 | if (mTextVisible) { |
| 339 | setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null); |
| 340 | } else { |
| 341 | setCompoundDrawablesRelativeWithIntrinsicBounds(null, mDrawable, null, null); |
| 342 | } |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 343 | } |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 346 | public void setToolTipLocation(int location) { |
| 347 | mToolTipLocation = location; |
| 348 | hideTooltip(); |
| 349 | } |
| 350 | |
| 351 | public boolean isTextTruncated(int availableWidth) { |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 352 | availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth() |
| 353 | + getCompoundDrawablePadding()); |
| 354 | CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth, |
| 355 | TextUtils.TruncateAt.END); |
| 356 | return !mText.equals(displayedText); |
| 357 | } |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 358 | } |