1 /*
2  * Copyright (C) 2021 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 package com.android.launcher3.taskbar;
17 
18 import android.graphics.drawable.Drawable;
19 
20 import com.android.launcher3.R;
21 import com.android.launcher3.dragndrop.DragView;
22 
23 /**
24  * A DragView drawn/used by the Taskbar. Note that this is only for the internal drag-and-drop,
25  * while the pre-drag is still in progress (i.e. when the long press popup is still open). After
26  * that ends, we switch to a system drag and drop view instead.
27  */
28 public class TaskbarDragView extends DragView<BaseTaskbarContext> {
TaskbarDragView(BaseTaskbarContext launcher, Drawable drawable, int registrationX, int registrationY, float initialScale, float scaleOnDrop, float finalScaleDps)29     public TaskbarDragView(BaseTaskbarContext launcher, Drawable drawable, int registrationX,
30             int registrationY, float initialScale, float scaleOnDrop, float finalScaleDps) {
31         super(launcher, drawable, registrationX, registrationY, initialScale, scaleOnDrop,
32                 finalScaleDps);
33     }
34 
35     @Override
animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration)36     public void animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration) {
37         Runnable onAnimationEnd = () -> {
38             if (onCompleteRunnable != null) {
39                 onCompleteRunnable.run();
40             }
41             mActivity.getDragLayer().removeView(this);
42         };
43 
44         duration = Math.max(duration,
45                 getResources().getInteger(R.integer.config_dropAnimMinDuration));
46 
47         animate()
48                 .translationX(toTouchX - mRegistrationX)
49                 .translationY(toTouchY - mRegistrationY)
50                 .scaleX(mScaleOnDrop)
51                 .scaleY(mScaleOnDrop)
52                 .withEndAction(onAnimationEnd)
53                 .setDuration(duration)
54                 .start();
55     }
56 }
57