• 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.uioverrides;
17 
18 import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
19 import static com.android.launcher3.anim.Interpolators.DEACCEL_2;
20 import static com.android.launcher3.states.RotationHelper.REQUEST_ROTATE;
21 
22 import android.view.View;
23 
24 import com.android.launcher3.AbstractFloatingView;
25 import com.android.launcher3.DeviceProfile;
26 import com.android.launcher3.Launcher;
27 import com.android.launcher3.LauncherState;
28 import com.android.launcher3.Workspace;
29 import com.android.launcher3.allapps.DiscoveryBounce;
30 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
31 import com.android.quickstep.views.RecentsView;
32 
33 /**
34  * Definition for overview state
35  */
36 public class OverviewState extends LauncherState {
37 
38     private static final int STATE_FLAGS = FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED
39             | FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_DISABLE_ACCESSIBILITY;
40 
OverviewState(int id)41     public OverviewState(int id) {
42         this(id, OVERVIEW_TRANSITION_MS, STATE_FLAGS);
43     }
44 
OverviewState(int id, int transitionDuration, int stateFlags)45     protected OverviewState(int id, int transitionDuration, int stateFlags) {
46         super(id, ContainerType.TASKSWITCHER, transitionDuration, stateFlags);
47     }
48 
49     @Override
getWorkspaceScaleAndTranslation(Launcher launcher)50     public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
51         RecentsView recentsView = launcher.getOverviewPanel();
52         Workspace workspace = launcher.getWorkspace();
53         View workspacePage = workspace.getPageAt(workspace.getCurrentPage());
54         float workspacePageWidth = workspacePage != null && workspacePage.getWidth() != 0
55                 ? workspacePage.getWidth() : launcher.getDeviceProfile().availableWidthPx;
56         recentsView.getTaskSize(sTempRect);
57         float scale = (float) sTempRect.width() / workspacePageWidth;
58         float parallaxFactor = 0.5f;
59         return new float[]{scale, 0, -getDefaultSwipeHeight(launcher) * parallaxFactor};
60     }
61 
62     @Override
getOverviewScaleAndTranslationYFactor(Launcher launcher)63     public float[] getOverviewScaleAndTranslationYFactor(Launcher launcher) {
64         return new float[] {1f, 0f};
65     }
66 
67     @Override
onStateEnabled(Launcher launcher)68     public void onStateEnabled(Launcher launcher) {
69         RecentsView rv = launcher.getOverviewPanel();
70         rv.setOverviewStateEnabled(true);
71         AbstractFloatingView.closeAllOpenViews(launcher);
72     }
73 
74     @Override
onStateDisabled(Launcher launcher)75     public void onStateDisabled(Launcher launcher) {
76         RecentsView rv = launcher.getOverviewPanel();
77         rv.setOverviewStateEnabled(false);
78     }
79 
80     @Override
onStateTransitionEnd(Launcher launcher)81     public void onStateTransitionEnd(Launcher launcher) {
82         launcher.getRotationHelper().setCurrentStateRequest(REQUEST_ROTATE);
83         DiscoveryBounce.showForOverviewIfNeeded(launcher);
84     }
85 
getWorkspacePageAlphaProvider(Launcher launcher)86     public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
87         return new PageAlphaProvider(DEACCEL_2) {
88             @Override
89             public float getPageAlpha(int pageIndex) {
90                 return 0;
91             }
92         };
93     }
94 
95     @Override
96     public int getVisibleElements(Launcher launcher) {
97         if (launcher.getDeviceProfile().isVerticalBarLayout()) {
98             return VERTICAL_SWIPE_INDICATOR;
99         } else {
100             return HOTSEAT_SEARCH_BOX | VERTICAL_SWIPE_INDICATOR |
101                     (launcher.getAppsView().getFloatingHeaderView().hasVisibleContent()
102                             ? ALL_APPS_HEADER_EXTRA : HOTSEAT_ICONS);
103         }
104     }
105 
106     @Override
107     public float getWorkspaceScrimAlpha(Launcher launcher) {
108         return 0.5f;
109     }
110 
111     @Override
112     public float getVerticalProgress(Launcher launcher) {
113         if ((getVisibleElements(launcher) & ALL_APPS_HEADER_EXTRA) == 0) {
114             // We have no all apps content, so we're still at the fully down progress.
115             return super.getVerticalProgress(launcher);
116         }
117         return 1 - (getDefaultSwipeHeight(launcher)
118                 / launcher.getAllAppsController().getShiftRange());
119     }
120 
121     public static float getDefaultSwipeHeight(Launcher launcher) {
122         DeviceProfile dp = launcher.getDeviceProfile();
123         return dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx;
124     }
125 }
126