1 /* 2 * Copyright (C) 2021 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.pip; 18 19 import android.annotation.IntDef; 20 import android.app.PictureInPictureParams; 21 import android.content.ComponentName; 22 import android.content.pm.ActivityInfo; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * Used to keep track of PiP leash state as it appears and animates by {@link PipTaskOrganizer} and 29 * {@link PipTransition}. 30 */ 31 public class PipTransitionState { 32 33 public static final int UNDEFINED = 0; 34 public static final int TASK_APPEARED = 1; 35 public static final int ENTRY_SCHEDULED = 2; 36 public static final int ENTERING_PIP = 3; 37 public static final int ENTERED_PIP = 4; 38 public static final int EXITING_PIP = 5; 39 40 /** 41 * If set to {@code true}, no entering PiP transition would be kicked off and most likely 42 * it's due to the fact that Launcher is handling the transition directly when swiping 43 * auto PiP-able Activity to home. 44 * See also {@link PipTaskOrganizer#startSwipePipToHome(ComponentName, ActivityInfo, 45 * PictureInPictureParams)}. 46 */ 47 private boolean mInSwipePipToHomeTransition; 48 49 // Not a complete set of states but serves what we want right now. 50 @IntDef(prefix = { "TRANSITION_STATE_" }, value = { 51 UNDEFINED, 52 TASK_APPEARED, 53 ENTRY_SCHEDULED, 54 ENTERING_PIP, 55 ENTERED_PIP, 56 EXITING_PIP 57 }) 58 @Retention(RetentionPolicy.SOURCE) 59 public @interface TransitionState {} 60 61 private @TransitionState int mState; 62 PipTransitionState()63 public PipTransitionState() { 64 mState = UNDEFINED; 65 } 66 setTransitionState(@ransitionState int state)67 public void setTransitionState(@TransitionState int state) { 68 mState = state; 69 } 70 getTransitionState()71 public @TransitionState int getTransitionState() { 72 return mState; 73 } 74 isInPip()75 public boolean isInPip() { 76 return mState >= TASK_APPEARED 77 && mState != EXITING_PIP; 78 } 79 setInSwipePipToHomeTransition(boolean inSwipePipToHomeTransition)80 public void setInSwipePipToHomeTransition(boolean inSwipePipToHomeTransition) { 81 mInSwipePipToHomeTransition = inSwipePipToHomeTransition; 82 } 83 getInSwipePipToHomeTransition()84 public boolean getInSwipePipToHomeTransition() { 85 return mInSwipePipToHomeTransition; 86 } 87 /** 88 * Resize request can be initiated in other component, ignore if we are no longer in PIP, 89 * still waiting for animation or we're exiting from it. 90 * 91 * @return {@code true} if the resize request should be blocked/ignored. 92 */ shouldBlockResizeRequest()93 public boolean shouldBlockResizeRequest() { 94 return mState < ENTERING_PIP 95 || mState == EXITING_PIP; 96 } 97 } 98