1 /* 2 * Copyright (C) 2020 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.wm.shell.splitscreen; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.app.ActivityManager; 22 import android.graphics.Rect; 23 24 import com.android.wm.shell.common.annotations.ExternalThread; 25 import com.android.wm.shell.common.split.SplitScreenConstants.SplitPosition; 26 27 import java.util.concurrent.Executor; 28 29 /** 30 * Interface to engage split-screen feature. 31 * TODO: Figure out which of these are actually needed outside of the Shell 32 */ 33 @ExternalThread 34 public interface SplitScreen { 35 /** 36 * Stage type isn't specified normally meaning to use what ever the default is. 37 * E.g. exit split-screen and launch the app in fullscreen. 38 */ 39 int STAGE_TYPE_UNDEFINED = -1; 40 /** 41 * The main stage type. 42 * @see MainStage 43 */ 44 int STAGE_TYPE_MAIN = 0; 45 46 /** 47 * The side stage type. 48 * @see SideStage 49 */ 50 int STAGE_TYPE_SIDE = 1; 51 52 @IntDef(prefix = { "STAGE_TYPE_" }, value = { 53 STAGE_TYPE_UNDEFINED, 54 STAGE_TYPE_MAIN, 55 STAGE_TYPE_SIDE 56 }) 57 @interface StageType {} 58 59 /** Callback interface for listening to changes in a split-screen stage. */ 60 interface SplitScreenListener { onStagePositionChanged(@tageType int stage, @SplitPosition int position)61 default void onStagePositionChanged(@StageType int stage, @SplitPosition int position) {} onTaskStageChanged(int taskId, @StageType int stage, boolean visible)62 default void onTaskStageChanged(int taskId, @StageType int stage, boolean visible) {} onSplitBoundsChanged(Rect rootBounds, Rect mainBounds, Rect sideBounds)63 default void onSplitBoundsChanged(Rect rootBounds, Rect mainBounds, Rect sideBounds) {} onSplitVisibilityChanged(boolean visible)64 default void onSplitVisibilityChanged(boolean visible) {} 65 } 66 67 /** Callback interface for listening to requests to enter split select */ 68 interface SplitSelectListener { onRequestEnterSplitSelect(ActivityManager.RunningTaskInfo taskInfo, int splitPosition, Rect taskBounds)69 default boolean onRequestEnterSplitSelect(ActivityManager.RunningTaskInfo taskInfo, 70 int splitPosition, Rect taskBounds) { 71 return false; 72 } 73 } 74 75 /** Registers listener that gets split screen callback. */ registerSplitScreenListener(@onNull SplitScreenListener listener, @NonNull Executor executor)76 void registerSplitScreenListener(@NonNull SplitScreenListener listener, 77 @NonNull Executor executor); 78 79 /** Unregisters listener that gets split screen callback. */ unregisterSplitScreenListener(@onNull SplitScreenListener listener)80 void unregisterSplitScreenListener(@NonNull SplitScreenListener listener); 81 82 /** Called when device waking up finished. */ onFinishedWakingUp()83 void onFinishedWakingUp(); 84 85 /** Called when requested to go to fullscreen from the current active split app. */ goToFullscreenFromSplit()86 void goToFullscreenFromSplit(); 87 88 /** Get a string representation of a stage type */ stageTypeToString(@tageType int stage)89 static String stageTypeToString(@StageType int stage) { 90 switch (stage) { 91 case STAGE_TYPE_UNDEFINED: return "UNDEFINED"; 92 case STAGE_TYPE_MAIN: return "MAIN"; 93 case STAGE_TYPE_SIDE: return "SIDE"; 94 default: return "UNKNOWN(" + stage + ")"; 95 } 96 } 97 } 98