1 /* 2 * Copyright (C) 2017 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.states; 17 18 import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; 19 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; 20 21 import android.content.Context; 22 23 import com.android.launcher3.DeviceProfile; 24 import com.android.launcher3.Launcher; 25 import com.android.launcher3.LauncherState; 26 import com.android.launcher3.Workspace; 27 import com.android.launcher3.views.ActivityContext; 28 29 /** 30 * Definition for spring loaded state used during drag and drop. 31 */ 32 public class SpringLoadedState extends LauncherState { 33 34 private static final int STATE_FLAGS = FLAG_MULTI_PAGE 35 | FLAG_WORKSPACE_INACCESSIBLE | FLAG_DISABLE_RESTORE 36 | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_WORKSPACE_HAS_BACKGROUNDS; 37 38 public static final float DEPTH_15_PERCENT = 0.15f; 39 SpringLoadedState(int id)40 public SpringLoadedState(int id) { 41 super(id, LAUNCHER_STATE_HOME, STATE_FLAGS); 42 } 43 44 @Override getTransitionDuration(ActivityContext context, boolean isToState)45 public int getTransitionDuration(ActivityContext context, boolean isToState) { 46 return 150; 47 } 48 49 @Override getWorkspaceScaleAndTranslation(Launcher launcher)50 public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) { 51 DeviceProfile grid = launcher.getDeviceProfile(); 52 Workspace<?> ws = launcher.getWorkspace(); 53 if (ws.getChildCount() == 0) { 54 return super.getWorkspaceScaleAndTranslation(launcher); 55 } 56 57 float shrunkTop = grid.getCellLayoutSpringLoadShrunkTop(); 58 float scale = grid.getWorkspaceSpringLoadScale(launcher); 59 60 float halfHeight = ws.getHeight() / 2; 61 float myCenter = ws.getTop() + halfHeight; 62 float cellTopFromCenter = halfHeight - ws.getChildAt(0).getTop(); 63 float actualCellTop = myCenter - cellTopFromCenter * scale; 64 return new ScaleAndTranslation(scale, 0, shrunkTop - actualCellTop); 65 } 66 67 @Override getDepthUnchecked(Context context)68 protected float getDepthUnchecked(Context context) { 69 if (enableScalingRevealHomeAnimation()) { 70 return DEPTH_15_PERCENT; 71 } else { 72 return 0.5f; 73 } 74 } 75 76 @Override getHotseatScaleAndTranslation(Launcher launcher)77 public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) { 78 return new ScaleAndTranslation(1, 0, 0); 79 } 80 81 @Override getWorkspaceBackgroundAlpha(Launcher launcher)82 public float getWorkspaceBackgroundAlpha(Launcher launcher) { 83 return 0.2f; 84 } 85 } 86