| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.pip; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.app.PictureInPictureParams; |
| 22 |
import android.content.ComponentName; |
| 23 |
import android.content.pm.ActivityInfo; |
| 24 |
|
| 25 |
import java.lang.annotation.Retention; |
| 26 |
import java.lang.annotation.RetentionPolicy; |
| 27 |
import java.util.ArrayList; |
| 28 |
import java.util.List; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class PipTransitionState { |
| 35 |
|
| 36 |
public static final int UNDEFINED = 0; |
| 37 |
public static final int TASK_APPEARED = 1; |
| 38 |
public static final int ENTRY_SCHEDULED = 2; |
| 39 |
public static final int ENTERING_PIP = 3; |
| 40 |
public static final int ENTERED_PIP = 4; |
| 41 |
public static final int EXITING_PIP = 5; |
| 42 |
|
| 43 |
private final List<OnPipTransitionStateChangedListener> mOnPipTransitionStateChangedListeners = |
| 44 |
new ArrayList<>(); |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
private boolean mInSwipePipToHomeTransition; |
| 54 |
|
| 55 |
|
| 56 |
@IntDef(prefix = { "TRANSITION_STATE_" }, value = { |
| 57 |
UNDEFINED, |
| 58 |
TASK_APPEARED, |
| 59 |
ENTRY_SCHEDULED, |
| 60 |
ENTERING_PIP, |
| 61 |
ENTERED_PIP, |
| 62 |
EXITING_PIP |
| 63 |
}) |
| 64 |
@Retention(RetentionPolicy.SOURCE) |
| 65 |
public @interface TransitionState {} |
| 66 |
|
| 67 |
private @TransitionState int mState; |
| 68 |
|
| 69 |
public PipTransitionState() { |
| 70 |
mState = UNDEFINED; |
| 71 |
} |
| 72 |
|
| 73 |
public void setTransitionState(@TransitionState int state) { |
| 74 |
if (mState != state) { |
| 75 |
for (int i = 0; i < mOnPipTransitionStateChangedListeners.size(); i++) { |
| 76 |
mOnPipTransitionStateChangedListeners.get(i).onPipTransitionStateChanged( |
| 77 |
mState, state); |
| 78 |
} |
| 79 |
mState = state; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
public @TransitionState int getTransitionState() { |
| 84 |
return mState; |
| 85 |
} |
| 86 |
|
| 87 |
public boolean isInPip() { |
| 88 |
return isInPip(mState); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
public boolean hasEnteredPip() { |
| 93 |
return hasEnteredPip(mState); |
| 94 |
} |
| 95 |
|
| 96 |
public void setInSwipePipToHomeTransition(boolean inSwipePipToHomeTransition) { |
| 97 |
mInSwipePipToHomeTransition = inSwipePipToHomeTransition; |
| 98 |
} |
| 99 |
|
| 100 |
public boolean getInSwipePipToHomeTransition() { |
| 101 |
return mInSwipePipToHomeTransition; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public boolean shouldBlockResizeRequest() { |
| 110 |
return mState < ENTERING_PIP |
| 111 |
|| mState == EXITING_PIP; |
| 112 |
} |
| 113 |
|
| 114 |
public void addOnPipTransitionStateChangedListener( |
| 115 |
@NonNull OnPipTransitionStateChangedListener listener) { |
| 116 |
mOnPipTransitionStateChangedListeners.add(listener); |
| 117 |
} |
| 118 |
|
| 119 |
public void removeOnPipTransitionStateChangedListener( |
| 120 |
@NonNull OnPipTransitionStateChangedListener listener) { |
| 121 |
mOnPipTransitionStateChangedListeners.remove(listener); |
| 122 |
} |
| 123 |
|
| 124 |
public static boolean isInPip(@TransitionState int state) { |
| 125 |
return state >= TASK_APPEARED && state != EXITING_PIP; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
public static boolean hasEnteredPip(@TransitionState int state) { |
| 130 |
return state == ENTERED_PIP; |
| 131 |
} |
| 132 |
|
| 133 |
public interface OnPipTransitionStateChangedListener { |
| 134 |
void onPipTransitionStateChanged(@TransitionState int oldState, |
| 135 |
@TransitionState int newState); |
| 136 |
} |
| 137 |
} |