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.states;
17 
18 import static com.android.launcher3.anim.Interpolators.DEACCEL_2;
19 import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS;
20 import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
21 
22 import android.content.Context;
23 
24 import com.android.launcher3.Launcher;
25 import com.android.launcher3.LauncherState;
26 import com.android.launcher3.allapps.AllAppsContainerView;
27 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
28 import com.android.quickstep.SysUINavigationMode;
29 
30 /**
31  * Definition for AllApps state
32  */
33 public class AllAppsState extends LauncherState {
34 
35     private static final int STATE_FLAGS = FLAG_WORKSPACE_INACCESSIBLE | FLAG_CLOSE_POPUPS;
36 
37     private static final PageAlphaProvider PAGE_ALPHA_PROVIDER = new PageAlphaProvider(DEACCEL_2) {
38         @Override
39         public float getPageAlpha(int pageIndex) {
40             return 0;
41         }
42     };
43 
AllAppsState(int id)44     public AllAppsState(int id) {
45         super(id, ContainerType.ALLAPPS, STATE_FLAGS);
46     }
47 
48     @Override
getTransitionDuration(Context context)49     public int getTransitionDuration(Context context) {
50         return 320;
51     }
52 
53     @Override
getDescription(Launcher launcher)54     public String getDescription(Launcher launcher) {
55         AllAppsContainerView appsView = launcher.getAppsView();
56         return appsView.getDescription();
57     }
58 
59     @Override
getVerticalProgress(Launcher launcher)60     public float getVerticalProgress(Launcher launcher) {
61         return 0f;
62     }
63 
64     @Override
getWorkspaceScaleAndTranslation(Launcher launcher)65     public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
66         ScaleAndTranslation scaleAndTranslation = LauncherState.OVERVIEW
67                 .getWorkspaceScaleAndTranslation(launcher);
68         if (SysUINavigationMode.getMode(launcher) == NO_BUTTON && !ENABLE_OVERVIEW_ACTIONS.get()) {
69             float normalScale = 1;
70             // Scale down halfway to where we'd be in overview, to prepare for a potential pause.
71             scaleAndTranslation.scale = (scaleAndTranslation.scale + normalScale) / 2;
72         } else {
73             scaleAndTranslation.scale = 1;
74         }
75         return scaleAndTranslation;
76     }
77 
78     @Override
getDepthUnchecked(Context context)79     protected float getDepthUnchecked(Context context) {
80         return 1f;
81     }
82 
83     @Override
getWorkspacePageAlphaProvider(Launcher launcher)84     public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
85         return PAGE_ALPHA_PROVIDER;
86     }
87 
88     @Override
getVisibleElements(Launcher launcher)89     public int getVisibleElements(Launcher launcher) {
90         return ALL_APPS_HEADER | ALL_APPS_HEADER_EXTRA | ALL_APPS_CONTENT;
91     }
92 
93     @Override
getOverviewScaleAndOffset(Launcher launcher)94     public float[] getOverviewScaleAndOffset(Launcher launcher) {
95         return new float[] {0.9f, 0};
96     }
97 
98     @Override
getHistoryForState(LauncherState previousState)99     public LauncherState getHistoryForState(LauncherState previousState) {
100         return previousState == OVERVIEW ? OVERVIEW : NORMAL;
101     }
102 }
103