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 
17 package com.android.systemui.shared.system;
18 
19 import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
20 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
21 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
22 
23 import android.app.ActivityOptions;
24 import android.content.Context;
25 import android.os.Handler;
26 
27 import com.android.systemui.shared.recents.model.Task;
28 
29 /**
30  * Wrapper around internal ActivityOptions creation.
31  */
32 public abstract class ActivityOptionsCompat {
33 
34     /**
35      * @return ActivityOptions for starting a task in split screen as the primary window.
36      */
makeSplitScreenOptions(boolean dockTopLeft)37     public static ActivityOptions makeSplitScreenOptions(boolean dockTopLeft) {
38         return makeSplitScreenOptions(dockTopLeft, true);
39     }
40 
41     /**
42      * @return ActivityOptions for starting a task in split screen.
43      */
makeSplitScreenOptions(boolean dockTopLeft, boolean isPrimary)44     public static ActivityOptions makeSplitScreenOptions(boolean dockTopLeft, boolean isPrimary) {
45         final ActivityOptions options = ActivityOptions.makeBasic();
46         options.setLaunchWindowingMode(isPrimary
47                 ? WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
48                 : WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
49         return options;
50     }
51 
52     /**
53      * @return ActivityOptions for starting a task in freeform.
54      */
makeFreeformOptions()55     public static ActivityOptions makeFreeformOptions() {
56         final ActivityOptions options = ActivityOptions.makeBasic();
57         options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
58         return options;
59     }
60 
makeRemoteAnimation( RemoteAnimationAdapterCompat remoteAnimationAdapter)61     public static ActivityOptions makeRemoteAnimation(
62             RemoteAnimationAdapterCompat remoteAnimationAdapter) {
63         return ActivityOptions.makeRemoteAnimation(remoteAnimationAdapter.getWrapped(),
64                 remoteAnimationAdapter.getRemoteTransition().getTransition());
65     }
66 
67     /**
68      * Constructs an ActivityOptions object that will delegate its transition handling to a
69      * `remoteTransition`.
70      */
makeRemoteTransition(RemoteTransitionCompat remoteTransition)71     public static ActivityOptions makeRemoteTransition(RemoteTransitionCompat remoteTransition) {
72         return ActivityOptions.makeRemoteTransition(remoteTransition.getTransition());
73     }
74 
75     /**
76      * Returns ActivityOptions for overriding task transition animation.
77      */
makeCustomAnimation(Context context, int enterResId, int exitResId, final Runnable callback, final Handler callbackHandler)78     public static ActivityOptions makeCustomAnimation(Context context, int enterResId,
79             int exitResId, final Runnable callback, final Handler callbackHandler) {
80         return ActivityOptions.makeCustomTaskAnimation(context, enterResId, exitResId,
81                 callbackHandler,
82                 new ActivityOptions.OnAnimationStartedListener() {
83                     @Override
84                     public void onAnimationStarted() {
85                         if (callback != null) {
86                             callbackHandler.post(callback);
87                         }
88                     }
89                 }, null /* finishedListener */);
90     }
91 
92     /**
93      * Sets the flag to freeze the recents task list reordering as a part of launching the activity.
94      */
95     public static ActivityOptions setFreezeRecentTasksList(ActivityOptions opts) {
96         opts.setFreezeRecentTasksReordering();
97         return opts;
98     }
99 
100     /**
101      * Sets the launch event time from launcher.
102      */
103     public static ActivityOptions setLauncherSourceInfo(ActivityOptions opts, long uptimeMillis) {
104         opts.setSourceInfo(ActivityOptions.SourceInfo.TYPE_LAUNCHER, uptimeMillis);
105         return opts;
106     }
107 
108     /**
109      * Sets Task specific information to the activity options
110      */
111     public static void addTaskInfo(ActivityOptions opts, Task.TaskKey taskKey) {
112         if (taskKey.windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
113             // We show non-visible docked tasks in Recents, but we always want to launch
114             // them in the fullscreen stack.
115             opts.setLaunchWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
116         }
117     }
118 }
119