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