• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.quickstep;
17 
18 import android.annotation.TargetApi;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.graphics.Rect;
22 import android.graphics.RectF;
23 import android.graphics.Region;
24 import android.os.Build;
25 import android.os.Handler;
26 import android.view.MotionEvent;
27 import android.view.View;
28 import android.view.animation.Interpolator;
29 
30 import androidx.annotation.NonNull;
31 import androidx.annotation.Nullable;
32 import androidx.annotation.UiThread;
33 
34 import com.android.launcher3.BaseDraggingActivity;
35 import com.android.launcher3.DeviceProfile;
36 import com.android.launcher3.anim.AnimatorPlaybackController;
37 import com.android.quickstep.util.RemoteAnimationProvider;
38 import com.android.quickstep.util.RemoteAnimationTargetSet;
39 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
40 
41 import java.util.function.BiPredicate;
42 import java.util.function.Consumer;
43 
44 /**
45  * Utility class which abstracts out the logical differences between Launcher and RecentsActivity.
46  */
47 @TargetApi(Build.VERSION_CODES.P)
48 public interface ActivityControlHelper<T extends BaseDraggingActivity> {
49 
onTransitionCancelled(T activity, boolean activityVisible)50     void onTransitionCancelled(T activity, boolean activityVisible);
51 
getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect)52     int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect);
53 
onSwipeUpToRecentsComplete(T activity)54     void onSwipeUpToRecentsComplete(T activity);
55 
onSwipeUpToHomeComplete(T activity)56     default void onSwipeUpToHomeComplete(T activity) { }
onAssistantVisibilityChanged(float visibility)57     void onAssistantVisibilityChanged(float visibility);
58 
prepareHomeUI(T activity)59     @NonNull HomeAnimationFactory prepareHomeUI(T activity);
60 
prepareRecentsUI(T activity, boolean activityVisible, boolean animateActivity, Consumer<AnimatorPlaybackController> callback)61     AnimationFactory prepareRecentsUI(T activity, boolean activityVisible,
62             boolean animateActivity, Consumer<AnimatorPlaybackController> callback);
63 
createActivityInitListener(BiPredicate<T, Boolean> onInitListener)64     ActivityInitListener createActivityInitListener(BiPredicate<T, Boolean> onInitListener);
65 
66     @Nullable
getCreatedActivity()67     T getCreatedActivity();
68 
isResumed()69     default boolean isResumed() {
70         BaseDraggingActivity activity = getCreatedActivity();
71         return activity != null && activity.hasBeenResumed();
72     }
73 
74     @UiThread
75     @Nullable
getVisibleRecentsView()76     <T extends View> T getVisibleRecentsView();
77 
78     @UiThread
switchToRecentsIfVisible(Runnable onCompleteCallback)79     boolean switchToRecentsIfVisible(Runnable onCompleteCallback);
80 
getOverviewWindowBounds(Rect homeBounds, RemoteAnimationTargetCompat target)81     Rect getOverviewWindowBounds(Rect homeBounds, RemoteAnimationTargetCompat target);
82 
shouldMinimizeSplitScreen()83     boolean shouldMinimizeSplitScreen();
84 
deferStartingActivity(Region activeNavBarRegion, MotionEvent ev)85     default boolean deferStartingActivity(Region activeNavBarRegion, MotionEvent ev) {
86         return true;
87     }
88 
89     /**
90      * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
91      */
getContainerType()92     int getContainerType();
93 
isInLiveTileMode()94     boolean isInLiveTileMode();
95 
onLaunchTaskFailed(T activity)96     void onLaunchTaskFailed(T activity);
97 
onLaunchTaskSuccess(T activity)98     void onLaunchTaskSuccess(T activity);
99 
100     interface ActivityInitListener {
101 
register()102         void register();
103 
unregister()104         void unregister();
105 
registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider, Context context, Handler handler, long duration)106         void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider,
107                 Context context, Handler handler, long duration);
108     }
109 
110     interface AnimationFactory {
111 
112         enum ShelfAnimState {
113             HIDE(true), PEEK(true), OVERVIEW(false), CANCEL(false);
114 
ShelfAnimState(boolean shouldPreformHaptic)115             ShelfAnimState(boolean shouldPreformHaptic) {
116                 this.shouldPreformHaptic = shouldPreformHaptic;
117             }
118 
119             public final boolean shouldPreformHaptic;
120         }
121 
onRemoteAnimationReceived(RemoteAnimationTargetSet targets)122         default void onRemoteAnimationReceived(RemoteAnimationTargetSet targets) { }
123 
createActivityController(long transitionLength)124         void createActivityController(long transitionLength);
125 
adjustActivityControllerInterpolators()126         default void adjustActivityControllerInterpolators() { }
127 
onTransitionCancelled()128         default void onTransitionCancelled() { }
129 
setShelfState(ShelfAnimState animState, Interpolator interpolator, long duration)130         default void setShelfState(ShelfAnimState animState, Interpolator interpolator,
131                 long duration) { }
132 
133         /**
134          * @param attached Whether to show RecentsView alongside the app window. If false, recents
135          *                 will be hidden by some property we can animate, e.g. alpha.
136          * @param animate Whether to animate recents to/from its new attached state.
137          */
setRecentsAttachedToAppWindow(boolean attached, boolean animate)138         default void setRecentsAttachedToAppWindow(boolean attached, boolean animate) { }
139     }
140 
141     interface HomeAnimationFactory {
142 
143         /** Return the floating view that will animate in sync with the closing window. */
getFloatingView()144         default @Nullable View getFloatingView() {
145             return null;
146         }
147 
getWindowTargetRect()148         @NonNull RectF getWindowTargetRect();
149 
createActivityAnimationToHome()150         @NonNull AnimatorPlaybackController createActivityAnimationToHome();
151 
playAtomicAnimation(float velocity)152         default void playAtomicAnimation(float velocity) {
153             // No-op
154         }
155     }
156 }
157