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