Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
| 17 | package com.android.launcher3; |
| 18 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 19 | import static com.android.launcher3.ButtonDropTarget.TOOLTIP_DEFAULT; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.anim.AlphaUpdateListener.updateVisibility; |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 21 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 22 | import android.animation.TimeInterpolator; |
| 23 | import android.content.Context; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 24 | import android.graphics.Rect; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 25 | import android.util.AttributeSet; |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 26 | import android.util.Log; |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 27 | import android.util.TypedValue; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 28 | import android.view.Gravity; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.view.ViewDebug; |
| 31 | import android.view.ViewPropertyAnimator; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 32 | import android.widget.FrameLayout; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 33 | |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 34 | import androidx.annotation.NonNull; |
| 35 | |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 36 | import com.android.launcher3.anim.Interpolators; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 37 | import com.android.launcher3.dragndrop.DragController; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 38 | import com.android.launcher3.dragndrop.DragController.DragListener; |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 39 | import com.android.launcher3.dragndrop.DragOptions; |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 40 | import com.android.launcher3.testing.TestProtocol; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 41 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 42 | import java.util.Arrays; |
| 43 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 44 | /* |
| 45 | * The top bar containing various drop targets: Delete/App Info/Uninstall. |
| 46 | */ |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 47 | public class DropTargetBar extends FrameLayout |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 48 | implements DragListener, Insettable { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 49 | |
| 50 | protected static final int DEFAULT_DRAG_FADE_DURATION = 175; |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 51 | protected static final TimeInterpolator DEFAULT_INTERPOLATOR = Interpolators.ACCEL; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 52 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 53 | private final Runnable mFadeAnimationEndRunnable = |
Sunny Goyal | 18d7184 | 2018-03-27 13:44:00 -0700 | [diff] [blame] | 54 | () -> updateVisibility(DropTargetBar.this); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 55 | |
| 56 | @ViewDebug.ExportedProperty(category = "launcher") |
| 57 | protected boolean mDeferOnDragEnd; |
| 58 | |
| 59 | @ViewDebug.ExportedProperty(category = "launcher") |
| 60 | protected boolean mVisible = false; |
| 61 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 62 | private ButtonDropTarget[] mDropTargets; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 63 | private ViewPropertyAnimator mCurrentAnimation; |
| 64 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 65 | private boolean mIsVertical = true; |
| 66 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 67 | public DropTargetBar(Context context, AttributeSet attrs) { |
| 68 | super(context, attrs); |
| 69 | } |
| 70 | |
| 71 | public DropTargetBar(Context context, AttributeSet attrs, int defStyle) { |
| 72 | super(context, attrs, defStyle); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | protected void onFinishInflate() { |
| 77 | super.onFinishInflate(); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 78 | mDropTargets = new ButtonDropTarget[getChildCount()]; |
| 79 | for (int i = 0; i < mDropTargets.length; i++) { |
| 80 | mDropTargets[i] = (ButtonDropTarget) getChildAt(i); |
| 81 | mDropTargets[i].setDropTargetBar(this); |
| 82 | } |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 85 | @Override |
| 86 | public void setInsets(Rect insets) { |
| 87 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); |
| 88 | DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile(); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 89 | mIsVertical = grid.isVerticalBarLayout(); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 90 | |
| 91 | lp.leftMargin = insets.left; |
| 92 | lp.topMargin = insets.top; |
| 93 | lp.bottomMargin = insets.bottom; |
| 94 | lp.rightMargin = insets.right; |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 95 | int tooltipLocation = TOOLTIP_DEFAULT; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 96 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 97 | int horizontalMargin; |
| 98 | if (grid.isTablet) { |
| 99 | // XXX: If the icon size changes across orientations, we will have to take |
| 100 | // that into account here too. |
| 101 | horizontalMargin = ((grid.widthPx - 2 * grid.edgeMarginPx |
| 102 | - (grid.inv.numColumns * grid.cellWidthPx)) |
| 103 | / (2 * (grid.inv.numColumns + 1))) |
| 104 | + grid.edgeMarginPx; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 105 | } else { |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 106 | horizontalMargin = getContext().getResources() |
| 107 | .getDimensionPixelSize(R.dimen.drop_target_bar_margin_horizontal); |
Pat Manning | e372366 | 2022-03-25 16:07:46 +0000 | [diff] [blame] | 108 | } |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 109 | lp.topMargin += grid.dropTargetBarTopMarginPx; |
| 110 | lp.bottomMargin += grid.dropTargetBarBottomMarginPx; |
| 111 | lp.width = grid.availableWidthPx - 2 * horizontalMargin; |
| 112 | if (mIsVertical) { |
| 113 | lp.leftMargin = (grid.widthPx - lp.width) / 2; |
| 114 | lp.rightMargin = (grid.widthPx - lp.width) / 2; |
| 115 | } |
| 116 | lp.height = grid.dropTargetBarSizePx; |
| 117 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; |
| 118 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 119 | setLayoutParams(lp); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 120 | for (ButtonDropTarget button : mDropTargets) { |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 121 | button.setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.dropTargetTextSizePx); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 122 | button.setToolTipLocation(tooltipLocation); |
| 123 | } |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 126 | public void setup(DragController dragController) { |
| 127 | dragController.addDragListener(this); |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 128 | for (int i = 0; i < mDropTargets.length; i++) { |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 129 | dragController.addDragListener(mDropTargets[i]); |
| 130 | dragController.addDropTarget(mDropTargets[i]); |
| 131 | } |
| 132 | } |
| 133 | |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 134 | @Override |
| 135 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 136 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 137 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 138 | |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 139 | int visibleCount = getVisibleButtonsCount(); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 140 | if (visibleCount > 0) { |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 141 | int availableWidth = width / visibleCount; |
| 142 | boolean textVisible = true; |
Sebastian Franco | d2d8e97 | 2022-04-04 14:51:53 -0700 | [diff] [blame] | 143 | boolean textResized = false; |
| 144 | float textSize = mDropTargets[0].getTextSize(); |
| 145 | for (ButtonDropTarget button : mDropTargets) { |
| 146 | if (button.getVisibility() == GONE) { |
| 147 | continue; |
| 148 | } |
| 149 | if (button.isTextTruncated(availableWidth)) { |
| 150 | textSize = Math.min(textSize, button.resizeTextToFit(availableWidth)); |
| 151 | textResized = true; |
| 152 | } |
| 153 | textVisible = textVisible && !button.isTextTruncated(availableWidth); |
| 154 | } |
| 155 | |
| 156 | if (textResized) { |
| 157 | for (ButtonDropTarget button : mDropTargets) { |
| 158 | button.setTextSize(textSize); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 159 | } |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 162 | int widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST); |
| 163 | int heightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); |
| 164 | for (ButtonDropTarget button : mDropTargets) { |
| 165 | if (button.getVisibility() != GONE) { |
| 166 | button.setTextVisible(textVisible); |
| 167 | button.measure(widthSpec, heightSpec); |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | } |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 171 | setMeasuredDimension(width, height); |
| 172 | } |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 173 | |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 174 | @Override |
| 175 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 176 | int visibleCount = getVisibleButtonsCount(); |
| 177 | if (visibleCount == 0) { |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 178 | return; |
| 179 | } |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 180 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 181 | Launcher launcher = Launcher.getLauncher(getContext()); |
Shikha Malhotra | f78da1b | 2022-04-11 10:23:18 +0000 | [diff] [blame] | 182 | Workspace<?> workspace = launcher.getWorkspace(); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 183 | DeviceProfile dp = launcher.getDeviceProfile(); |
| 184 | int buttonHorizontalPadding = dp.dropTargetHorizontalPaddingPx; |
| 185 | int buttonVerticalPadding = dp.dropTargetVerticalPaddingPx; |
| 186 | int barCenter = (right - left) / 2; |
Pat Manning | 1acf2b1 | 2022-02-25 15:41:55 +0000 | [diff] [blame] | 187 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 188 | ButtonDropTarget[] visibleButtons = Arrays.stream(mDropTargets) |
| 189 | .filter(b -> b.getVisibility() != GONE) |
| 190 | .toArray(ButtonDropTarget[]::new); |
| 191 | Arrays.stream(visibleButtons).forEach( |
| 192 | b -> b.setPadding(buttonHorizontalPadding, buttonVerticalPadding, |
| 193 | buttonHorizontalPadding, buttonVerticalPadding)); |
| 194 | |
| 195 | if (visibleCount == 1) { |
| 196 | ButtonDropTarget button = visibleButtons[0]; |
| 197 | button.layout(barCenter - (button.getMeasuredWidth() / 2), 0, |
| 198 | barCenter + (button.getMeasuredWidth() / 2), button.getMeasuredHeight()); |
| 199 | } else if (visibleCount == 2) { |
| 200 | int buttonGap = dp.dropTargetGapPx; |
| 201 | |
| 202 | if (dp.isTwoPanels) { |
| 203 | ButtonDropTarget leftButton = visibleButtons[0]; |
| 204 | leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0, |
| 205 | barCenter - (buttonGap / 2), leftButton.getMeasuredHeight()); |
| 206 | |
| 207 | ButtonDropTarget rightButton = visibleButtons[1]; |
| 208 | rightButton.layout(barCenter + (buttonGap / 2), 0, |
| 209 | barCenter + rightButton.getMeasuredWidth() + (buttonGap / 2), |
| 210 | rightButton.getMeasuredHeight()); |
| 211 | } else if (dp.isTablet) { |
| 212 | int numberOfMargins = visibleCount - 1; |
| 213 | int buttonWidths = Arrays.stream(mDropTargets) |
| 214 | .filter(b -> b.getVisibility() != GONE) |
| 215 | .mapToInt(ButtonDropTarget::getMeasuredWidth) |
| 216 | .sum(); |
| 217 | int totalWidth = buttonWidths + (numberOfMargins * buttonGap); |
| 218 | int buttonsStartMargin = barCenter - (totalWidth / 2); |
| 219 | |
| 220 | int start = buttonsStartMargin; |
| 221 | for (ButtonDropTarget button : visibleButtons) { |
| 222 | int margin = (start != buttonsStartMargin) ? buttonGap : 0; |
| 223 | button.layout(start + margin, 0, start + margin + button.getMeasuredWidth(), |
| 224 | button.getMeasuredHeight()); |
| 225 | start += button.getMeasuredWidth() + margin; |
Pat Manning | 1acf2b1 | 2022-02-25 15:41:55 +0000 | [diff] [blame] | 226 | } |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 227 | } else if (mIsVertical) { |
| 228 | // Center buttons over workspace, not screen. |
| 229 | int verticalCenter = (workspace.getRight() - workspace.getLeft()) / 2; |
| 230 | ButtonDropTarget leftButton = visibleButtons[0]; |
| 231 | leftButton.layout(verticalCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), |
| 232 | 0, verticalCenter - (buttonGap / 2), leftButton.getMeasuredHeight()); |
| 233 | |
| 234 | ButtonDropTarget rightButton = visibleButtons[1]; |
| 235 | rightButton.layout(verticalCenter + (buttonGap / 2), 0, |
| 236 | verticalCenter + rightButton.getMeasuredWidth() + (buttonGap / 2), |
| 237 | rightButton.getMeasuredHeight()); |
| 238 | } else if (dp.isPhone) { |
| 239 | // Buttons aligned to outer edges of scaled workspace. |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 240 | float scale = dp.getWorkspaceSpringLoadScale(); |
| 241 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 242 | int workspaceWidth = (int) (launcher.getWorkspace().getNormalChildWidth() * scale); |
| 243 | int start = barCenter - (workspaceWidth / 2); |
| 244 | int end = barCenter + (workspaceWidth / 2); |
| 245 | |
| 246 | ButtonDropTarget leftButton = visibleButtons[0]; |
| 247 | ButtonDropTarget rightButton = visibleButtons[1]; |
| 248 | |
| 249 | // If the text within the buttons is too long, the buttons can overlap |
| 250 | int overlap = start + leftButton.getMeasuredWidth() + rightButton.getMeasuredWidth() |
| 251 | - end; |
| 252 | if (overlap > 0) { |
Pat Manning | 7013ee7 | 2022-04-12 11:50:09 +0100 | [diff] [blame] | 253 | end += overlap; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | leftButton.layout(start, 0, start + leftButton.getMeasuredWidth(), |
| 257 | leftButton.getMeasuredHeight()); |
| 258 | rightButton.layout(end - rightButton.getMeasuredWidth(), 0, end, |
| 259 | rightButton.getMeasuredHeight()); |
Sunny Goyal | d1b3f5c | 2018-01-18 17:14:05 -0800 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | private int getVisibleButtonsCount() { |
| 265 | int visibleCount = 0; |
| 266 | for (ButtonDropTarget buttons : mDropTargets) { |
| 267 | if (buttons.getVisibility() != GONE) { |
| 268 | visibleCount++; |
| 269 | } |
| 270 | } |
| 271 | return visibleCount; |
Jon Miranda | bfaa4a4 | 2017-08-21 15:31:51 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Hyunyoung Song | 497708c | 2019-05-01 16:16:53 -0700 | [diff] [blame] | 274 | public void animateToVisibility(boolean isVisible) { |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 275 | if (TestProtocol.sDebugTracing) { |
| 276 | Log.d(TestProtocol.NO_DROP_TARGET, "8"); |
| 277 | } |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 278 | if (mVisible != isVisible) { |
| 279 | mVisible = isVisible; |
| 280 | |
| 281 | // Cancel any existing animation |
| 282 | if (mCurrentAnimation != null) { |
| 283 | mCurrentAnimation.cancel(); |
| 284 | mCurrentAnimation = null; |
| 285 | } |
| 286 | |
| 287 | float finalAlpha = mVisible ? 1 : 0; |
| 288 | if (Float.compare(getAlpha(), finalAlpha) != 0) { |
| 289 | setVisibility(View.VISIBLE); |
| 290 | mCurrentAnimation = animate().alpha(finalAlpha) |
| 291 | .setInterpolator(DEFAULT_INTERPOLATOR) |
| 292 | .setDuration(DEFAULT_DRAG_FADE_DURATION) |
| 293 | .withEndAction(mFadeAnimationEndRunnable); |
| 294 | } |
| 295 | |
| 296 | } |
| 297 | } |
| 298 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 299 | /* |
| 300 | * DragController.DragListener implementation |
| 301 | */ |
| 302 | @Override |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 303 | public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 304 | if (TestProtocol.sDebugTracing) { |
| 305 | Log.d(TestProtocol.NO_DROP_TARGET, "7"); |
| 306 | } |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 307 | animateToVisibility(true); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * This is called to defer hiding the delete drop target until the drop animation has completed, |
| 312 | * instead of hiding immediately when the drag has ended. |
| 313 | */ |
| 314 | protected void deferOnDragEnd() { |
| 315 | mDeferOnDragEnd = true; |
| 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public void onDragEnd() { |
| 320 | if (!mDeferOnDragEnd) { |
| 321 | animateToVisibility(false); |
| 322 | } else { |
| 323 | mDeferOnDragEnd = false; |
| 324 | } |
| 325 | } |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 326 | |
| 327 | public ButtonDropTarget[] getDropTargets() { |
| 328 | return mDropTargets; |
| 329 | } |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 330 | |
| 331 | @Override |
| 332 | protected void onVisibilityChanged(@NonNull View changedView, int visibility) { |
| 333 | super.onVisibilityChanged(changedView, visibility); |
Vadim Tryshev | 8629be7 | 2021-10-26 19:57:49 +0000 | [diff] [blame] | 334 | if (TestProtocol.sDebugTracing) { |
| 335 | if (visibility == VISIBLE) { |
| 336 | Log.d(TestProtocol.NO_DROP_TARGET, "9"); |
| 337 | } else { |
| 338 | Log.d(TestProtocol.NO_DROP_TARGET, "Hiding drop target", new Exception()); |
| 339 | } |
vadimt | 89d9423 | 2021-09-01 12:33:00 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 342 | } |