1 /*
2  * Copyright (C) 2022 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.secondarydisplay;
18 
19 import android.graphics.drawable.Drawable;
20 import android.view.View;
21 
22 import com.android.launcher3.R;
23 import com.android.launcher3.dragndrop.DragView;
24 
25 /**
26  * A DragView drawn/used by the Secondary Launcher activity.
27  */
28 public class SecondaryDragView extends DragView<SecondaryDisplayLauncher> {
29 
SecondaryDragView(SecondaryDisplayLauncher launcher, Drawable drawable, int registrationX, int registrationY, float initialScale, float scaleOnDrop, float finalScaleDps)30     public SecondaryDragView(SecondaryDisplayLauncher launcher,
31             Drawable drawable,
32             int registrationX, int registrationY, float initialScale, float scaleOnDrop,
33             float finalScaleDps) {
34         super(launcher, drawable, registrationX, registrationY, initialScale, scaleOnDrop,
35                 finalScaleDps);
36     }
37 
SecondaryDragView(SecondaryDisplayLauncher launcher, View content, int width, int height, int registrationX, int registrationY, float initialScale, float scaleOnDrop, float finalScaleDps)38     public SecondaryDragView(SecondaryDisplayLauncher launcher, View content, int width, int height,
39             int registrationX, int registrationY, float initialScale, float scaleOnDrop,
40             float finalScaleDps) {
41         super(launcher, content, width, height, registrationX, registrationY, initialScale,
42                 scaleOnDrop, finalScaleDps);
43     }
44 
45     @Override
animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration)46     public void animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration) {
47         Runnable onAnimationEnd = () -> {
48             if (onCompleteRunnable != null) {
49                 onCompleteRunnable.run();
50             }
51             mActivity.getDragLayer().removeView(this);
52         };
53 
54         duration = Math.max(duration,
55                 getResources().getInteger(R.integer.config_dropAnimMinDuration));
56 
57         animate()
58                 .translationX(toTouchX - mRegistrationX)
59                 .translationY(toTouchY - mRegistrationY)
60                 .scaleX(mScaleOnDrop)
61                 .scaleY(mScaleOnDrop)
62                 .withEndAction(onAnimationEnd)
63                 .setDuration(duration)
64                 .start();
65     }
66 }
67