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.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT; 20 import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; 21 import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; 22 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; 23 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; 24 25 import android.app.ActivityOptions; 26 import android.content.Context; 27 import android.os.Handler; 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 options.setSplitScreenCreateMode(dockTopLeft 50 ? SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT 51 : SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT); 52 return options; 53 } 54 55 /** 56 * @return ActivityOptions for starting a task in freeform. 57 */ makeFreeformOptions()58 public static ActivityOptions makeFreeformOptions() { 59 final ActivityOptions options = ActivityOptions.makeBasic(); 60 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM); 61 return options; 62 } 63 makeRemoteAnimation( RemoteAnimationAdapterCompat remoteAnimationAdapter)64 public static ActivityOptions makeRemoteAnimation( 65 RemoteAnimationAdapterCompat remoteAnimationAdapter) { 66 return ActivityOptions.makeRemoteAnimation(remoteAnimationAdapter.getWrapped()); 67 } 68 makeCustomAnimation(Context context, int enterResId, int exitResId, final Runnable callback, final Handler callbackHandler)69 public static ActivityOptions makeCustomAnimation(Context context, int enterResId, 70 int exitResId, final Runnable callback, final Handler callbackHandler) { 71 return ActivityOptions.makeCustomAnimation(context, enterResId, exitResId, callbackHandler, 72 new ActivityOptions.OnAnimationStartedListener() { 73 @Override 74 public void onAnimationStarted() { 75 if (callback != null) { 76 callbackHandler.post(callback); 77 } 78 } 79 }); 80 } 81 82 /** 83 * Sets the flag to freeze the recents task list reordering as a part of launching the activity. 84 */ 85 public static ActivityOptions setFreezeRecentTasksList(ActivityOptions opts) { 86 opts.setFreezeRecentTasksReordering(); 87 return opts; 88 } 89 } 90