• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
19 
20 import android.content.Context;
21 import android.graphics.Point;
22 import android.graphics.Rect;
23 
24 import com.android.launcher3.BaseDraggingActivity;
25 import com.android.launcher3.Launcher;
26 import com.android.launcher3.LauncherState;
27 import com.android.quickstep.views.RecentsView;
28 
29 /**
30  * An Overview state that shows the current task in a modal fashion. Modal state is where the
31  * current task is shown on its own without other tasks visible.
32  */
33 public class OverviewModalTaskState extends OverviewState {
34 
35     private static final int STATE_FLAGS =
36             FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_WORKSPACE_INACCESSIBLE;
37 
OverviewModalTaskState(int id)38     public OverviewModalTaskState(int id) {
39         super(id, LAUNCHER_STATE_OVERVIEW, STATE_FLAGS);
40     }
41 
42     @Override
getTransitionDuration(Context launcher)43     public int getTransitionDuration(Context launcher) {
44         return 300;
45     }
46 
47     @Override
getVisibleElements(Launcher launcher)48     public int getVisibleElements(Launcher launcher) {
49         return OVERVIEW_ACTIONS | CLEAR_ALL_BUTTON;
50     }
51 
52     @Override
getOverviewScaleAndOffset(Launcher launcher)53     public float[] getOverviewScaleAndOffset(Launcher launcher) {
54         return getOverviewScaleAndOffsetForModalState(launcher);
55     }
56 
57     @Override
getOverviewModalness()58     public float getOverviewModalness() {
59         return 1.0f;
60     }
61 
62     @Override
onBackPressed(Launcher launcher)63     public void onBackPressed(Launcher launcher) {
64         launcher.getStateManager().goToState(LauncherState.OVERVIEW);
65         RecentsView recentsView = launcher.<RecentsView>getOverviewPanel();
66         if (recentsView != null) {
67             recentsView.resetModalVisuals();
68         } else {
69             super.onBackPressed(launcher);
70         }
71     }
72 
getOverviewScaleAndOffsetForModalState(BaseDraggingActivity activity)73     public static float[] getOverviewScaleAndOffsetForModalState(BaseDraggingActivity activity) {
74         Point taskSize = activity.<RecentsView>getOverviewPanel().getSelectedTaskSize();
75         Rect modalTaskSize = new Rect();
76         activity.<RecentsView>getOverviewPanel().getModalTaskSize(modalTaskSize);
77 
78         float scale = Math.min((float) modalTaskSize.height() / taskSize.y,
79                 (float) modalTaskSize.width() / taskSize.x);
80 
81         return new float[] {scale, NO_OFFSET};
82     }
83 }
84