1 /* 2 * Copyright (C) 2024 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.common.split; 18 19 import static com.android.wm.shell.shared.split.SplitScreenConstants.NOT_IN_SPLIT; 20 import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_2_10_90; 21 import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_2_90_10; 22 import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_3_10_45_45; 23 import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_3_45_45_10; 24 import static com.android.wm.shell.shared.split.SplitScreenConstants.SplitScreenState; 25 26 import android.graphics.Rect; 27 import android.graphics.RectF; 28 29 import java.util.List; 30 31 /** 32 * A class that manages the "state" of split screen. See {@link SplitScreenState} for definitions. 33 */ 34 public class SplitState { 35 private @SplitScreenState int mState = NOT_IN_SPLIT; 36 private SplitSpec mSplitSpec; 37 38 /** Updates the current state of split screen on this device. */ set(@plitScreenState int newState)39 public void set(@SplitScreenState int newState) { 40 mState = newState; 41 } 42 43 /** Reports the current state of split screen on this device. */ get()44 public @SplitScreenState int get() { 45 return mState; 46 } 47 48 /** Sets NOT_IN_SPLIT when user exits split. */ exit()49 public void exit() { 50 set(NOT_IN_SPLIT); 51 } 52 53 /** Refresh the valid layouts for this display/orientation. */ populateLayouts(Rect displayBounds, int dividerSize, boolean isLeftRightSplit, Rect pinnedTaskbarInsets)54 public void populateLayouts(Rect displayBounds, int dividerSize, boolean isLeftRightSplit, 55 Rect pinnedTaskbarInsets) { 56 mSplitSpec = 57 new SplitSpec(displayBounds, dividerSize, isLeftRightSplit, pinnedTaskbarInsets); 58 } 59 60 /** Returns the layout associated with a given split state. */ getLayout(@plitScreenState int state)61 public List<RectF> getLayout(@SplitScreenState int state) { 62 return mSplitSpec.getSpec(state); 63 } 64 65 /** Returns the layout associated with the current split state. */ getCurrentLayout()66 public List<RectF> getCurrentLayout() { 67 return getLayout(mState); 68 } 69 70 /** @return {@code true} if at least one app is partially offscreen in the current layout. */ currentStateSupportsOffscreenApps()71 public boolean currentStateSupportsOffscreenApps() { 72 return mState == SNAP_TO_2_10_90 73 || mState == SNAP_TO_2_90_10 74 || mState == SNAP_TO_3_10_45_45 75 || mState == SNAP_TO_3_45_45_10; 76 } 77 } 78