blob: cc68e2e3e4006f3cb043c803e82bf6bb8fed8421 [file] [log] [blame]
Tony Wickhamc7cbf252021-05-24 15:46:48 -07001/*
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 */
16package com.android.launcher3.dragndrop;
17
18import android.graphics.drawable.Drawable;
19import android.view.View;
20
21import com.android.launcher3.Launcher;
22import com.android.launcher3.LauncherState;
23import com.android.launcher3.statemanager.StateManager;
24
25/**
26 * A DragView drawn/used by the Launcher activity.
27 */
28public class LauncherDragView extends DragView<Launcher>
29 implements StateManager.StateListener<LauncherState> {
30
31
32 public LauncherDragView(Launcher launcher, Drawable drawable, int registrationX,
33 int registrationY, float initialScale, float scaleOnDrop, float finalScaleDps) {
34 super(launcher, drawable, registrationX, registrationY, initialScale, scaleOnDrop,
35 finalScaleDps);
36 }
37
38 public LauncherDragView(Launcher 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
46 protected void onAttachedToWindow() {
47 super.onAttachedToWindow();
48 mActivity.getStateManager().addStateListener(this);
49 }
50
51 @Override
52 protected void onDetachedFromWindow() {
53 super.onDetachedFromWindow();
54 mActivity.getStateManager().removeStateListener(this);
55 }
56
57 @Override
58 public void onStateTransitionComplete(LauncherState finalState) {
59 setVisibility((finalState == LauncherState.NORMAL
60 || finalState == LauncherState.SPRING_LOADED) ? VISIBLE : INVISIBLE);
61 }
62
63 @Override
64 public void animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration) {
65 mTempLoc[0] = toTouchX - mRegistrationX;
66 mTempLoc[1] = toTouchY - mRegistrationY;
67 mActivity.getDragLayer().animateViewIntoPosition(this, mTempLoc, 1f, mScaleOnDrop,
68 mScaleOnDrop, DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
69 }
70}