• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.taskbar.allapps;
17 
18 import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_STASHED_IN_TASKBAR_ALL_APPS;
19 import static com.android.launcher3.util.OnboardingPrefs.ALL_APPS_VISITED_COUNT;
20 
21 import com.android.launcher3.AbstractFloatingView;
22 import com.android.launcher3.allapps.AllAppsTransitionListener;
23 import com.android.launcher3.anim.PendingAnimation;
24 import com.android.launcher3.appprediction.AppsDividerView;
25 import com.android.launcher3.taskbar.NavbarButtonsViewController;
26 import com.android.launcher3.taskbar.TaskbarControllers;
27 import com.android.launcher3.taskbar.TaskbarStashController;
28 import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
29 import com.android.launcher3.taskbar.overlay.TaskbarOverlayController;
30 import com.android.launcher3.util.DisplayController;
31 
32 /**
33  * Handles the {@link TaskbarAllAppsContainerView} behavior and synchronizes its transitions with
34  * taskbar stashing.
35  */
36 final class TaskbarAllAppsViewController {
37 
38     private final TaskbarOverlayContext mContext;
39     private final TaskbarAllAppsSlideInView mSlideInView;
40     private final TaskbarAllAppsContainerView mAppsView;
41     private final TaskbarStashController mTaskbarStashController;
42     private final NavbarButtonsViewController mNavbarButtonsViewController;
43     private final TaskbarOverlayController mOverlayController;
44 
TaskbarAllAppsViewController( TaskbarOverlayContext context, TaskbarAllAppsSlideInView slideInView, TaskbarControllers taskbarControllers, TaskbarSearchSessionController searchSessionController)45     TaskbarAllAppsViewController(
46             TaskbarOverlayContext context,
47             TaskbarAllAppsSlideInView slideInView,
48             TaskbarControllers taskbarControllers,
49             TaskbarSearchSessionController searchSessionController) {
50 
51         mContext = context;
52         mSlideInView = slideInView;
53         mAppsView = mSlideInView.getAppsView();
54         mTaskbarStashController = taskbarControllers.taskbarStashController;
55         mNavbarButtonsViewController = taskbarControllers.navbarButtonsViewController;
56         mOverlayController = taskbarControllers.taskbarOverlayController;
57 
58         mSlideInView.init(new TaskbarAllAppsCallbacks(searchSessionController));
59         setUpAppDivider();
60         setUpTaskbarStashing();
61     }
62 
63     /** Starts the {@link TaskbarAllAppsSlideInView} enter transition. */
show(boolean animate)64     void show(boolean animate) {
65         mSlideInView.show(animate);
66     }
67 
68     /** Closes the {@link TaskbarAllAppsSlideInView}. */
close(boolean animate)69     void close(boolean animate) {
70         mSlideInView.close(animate);
71     }
72 
setUpAppDivider()73     private void setUpAppDivider() {
74         mAppsView.getFloatingHeaderView()
75                 .findFixedRowByType(AppsDividerView.class)
76                 .setShowAllAppsLabel(!mContext.getOnboardingPrefs().hasReachedMaxCount(
77                         ALL_APPS_VISITED_COUNT));
78         mContext.getOnboardingPrefs().incrementEventCount(ALL_APPS_VISITED_COUNT);
79     }
80 
setUpTaskbarStashing()81     private void setUpTaskbarStashing() {
82         if (DisplayController.isTransientTaskbar(mContext)) {
83             mTaskbarStashController.updateStateForFlag(FLAG_STASHED_IN_TASKBAR_ALL_APPS, true);
84             mTaskbarStashController.applyState(mOverlayController.getOpenDuration());
85         }
86 
87         mNavbarButtonsViewController.setSlideInViewVisible(true);
88         mSlideInView.setOnCloseBeginListener(() -> {
89             mNavbarButtonsViewController.setSlideInViewVisible(false);
90             AbstractFloatingView.closeOpenContainer(
91                     mContext, AbstractFloatingView.TYPE_ACTION_POPUP);
92 
93             if (DisplayController.isTransientTaskbar(mContext)) {
94                 mTaskbarStashController.updateStateForFlag(FLAG_STASHED_IN_TASKBAR_ALL_APPS, false);
95                 mTaskbarStashController.applyState(mOverlayController.getCloseDuration());
96             }
97         });
98     }
99 
100     class TaskbarAllAppsCallbacks implements AllAppsTransitionListener {
101         private final TaskbarSearchSessionController mSearchSessionController;
102 
TaskbarAllAppsCallbacks(TaskbarSearchSessionController searchSessionController)103         private TaskbarAllAppsCallbacks(TaskbarSearchSessionController searchSessionController) {
104             mSearchSessionController = searchSessionController;
105         }
106 
getOpenDuration()107         int getOpenDuration() {
108             return mOverlayController.getOpenDuration();
109         }
110 
getCloseDuration()111         int getCloseDuration() {
112             return mOverlayController.getCloseDuration();
113         }
114 
115         @Override
onAllAppsTransitionStart(boolean toAllApps)116         public void onAllAppsTransitionStart(boolean toAllApps) {
117             mSearchSessionController.onAllAppsTransitionStart(toAllApps);
118         }
119 
120         @Override
onAllAppsTransitionEnd(boolean toAllApps)121         public void onAllAppsTransitionEnd(boolean toAllApps) {
122             mSearchSessionController.onAllAppsTransitionEnd(toAllApps);
123         }
124 
125         /** Invoked on back press, returning {@code true} if the search session handled it. */
handleSearchBackInvoked()126         boolean handleSearchBackInvoked() {
127             return mSearchSessionController.handleBackInvoked();
128         }
129 
onAllAppsAnimationPending(PendingAnimation animation, boolean toAllApps)130         void onAllAppsAnimationPending(PendingAnimation animation, boolean toAllApps) {
131             mSearchSessionController.onAllAppsAnimationPending(animation, toAllApps);
132         }
133     }
134 }
135