• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package com.android.quickstep;
18 
19 import static com.android.launcher3.LauncherState.OVERVIEW;
20 
21 import com.android.launcher3.Launcher;
22 import com.android.launcher3.LauncherAppState;
23 import com.android.launcher3.LauncherInitListener;
24 import com.android.launcher3.LauncherState;
25 import com.android.launcher3.anim.AnimatorPlaybackController;
26 import com.android.launcher3.userevent.nano.LauncherLogProto;
27 import com.android.quickstep.views.IconRecentsView;
28 
29 import java.util.function.BiPredicate;
30 import java.util.function.Consumer;
31 
32 /**
33  * {@link ActivityControlHelper} for the in-launcher recents.
34  * TODO: Implement the app to overview animation functionality
35  */
36 public final class LauncherActivityControllerHelper extends GoActivityControlHelper<Launcher> {
37 
38     @Override
prepareRecentsUI(Launcher activity, boolean activityVisible, boolean animateActivity, Consumer<AnimatorPlaybackController> callback)39     public AnimationFactory prepareRecentsUI(Launcher activity,
40             boolean activityVisible, boolean animateActivity,
41             Consumer<AnimatorPlaybackController> callback) {
42         LauncherState fromState = activity.getStateManager().getState();
43         activity.<IconRecentsView>getOverviewPanel().setUsingRemoteAnimation(true);
44         //TODO: Implement this based off where the recents view needs to be for app => recents anim.
45         return new AnimationFactory() {
46             @Override
47             public void createActivityController(long transitionLength) {
48                 callback.accept(activity.getStateManager().createAnimationToNewWorkspace(
49                         fromState, OVERVIEW, transitionLength));
50             }
51 
52             @Override
53             public void onTransitionCancelled() {}
54         };
55     }
56 
57     @Override
58     public ActivityInitListener createActivityInitListener(
59             BiPredicate<Launcher, Boolean> onInitListener) {
60         return new LauncherInitListener(onInitListener);
61     }
62 
63     @Override
64     public Launcher getCreatedActivity() {
65         LauncherAppState app = LauncherAppState.getInstanceNoCreate();
66         if (app == null) {
67             return null;
68         }
69         return (Launcher) app.getModel().getCallback();
70     }
71 
72     private Launcher getVisibleLauncher() {
73         Launcher launcher = getCreatedActivity();
74         return (launcher != null) && launcher.isStarted() && launcher.hasWindowFocus() ?
75                 launcher : null;
76     }
77 
78     @Override
79     public IconRecentsView getVisibleRecentsView() {
80         Launcher launcher = getVisibleLauncher();
81         return launcher != null && launcher.getStateManager().getState().overviewUi
82                 ? launcher.getOverviewPanel() : null;
83     }
84 
85     @Override
86     public boolean switchToRecentsIfVisible(Runnable onCompleteCallback) {
87         Launcher launcher = getVisibleLauncher();
88         if (launcher == null) {
89             return false;
90         }
91         launcher.<IconRecentsView>getOverviewPanel().setUsingRemoteAnimation(false);
92         launcher.getUserEventDispatcher().logActionCommand(
93                 LauncherLogProto.Action.Command.RECENTS_BUTTON,
94                 getContainerType(),
95                 LauncherLogProto.ContainerType.TASKSWITCHER);
96         launcher.getStateManager().goToState(OVERVIEW,
97                 launcher.getStateManager().shouldAnimateStateChange(), onCompleteCallback);
98         return true;
99     }
100 
101     @Override
102     public int getContainerType() {
103         final Launcher launcher = getVisibleLauncher();
104         return launcher != null ? launcher.getStateManager().getState().containerType
105                 : LauncherLogProto.ContainerType.APP;
106     }
107 
108     @Override
109     public void onLaunchTaskSuccess(Launcher launcher) {
110         launcher.getStateManager().moveToRestState();
111     }
112 }
113