diff options
4 files changed, 44 insertions, 8 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 983944628bd9..7222cff32cf7 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -366,7 +366,6 @@ android:name="com.android.systemui.tv.pip.PipOverlayActivity" android:exported="true" android:theme="@style/PipTheme" - android:launchMode="singleTop" android:taskAffinity="" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:resizeableActivity="true" diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java index b5c1f5739e65..fe5409041d12 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java @@ -265,11 +265,7 @@ public class PipManager { */ private void showPipOverlay() { if (DEBUG) Log.d(TAG, "showPipOverlay()"); - Intent intent = new Intent(mContext, PipOverlayActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - final ActivityOptions options = ActivityOptions.makeBasic(); - options.setLaunchStackId(PINNED_STACK_ID); - mContext.startActivity(intent, options.toBundle()); + PipOverlayActivity.showPipOverlay(mContext); } /** @@ -635,7 +631,7 @@ public class PipManager { void onPipActivityClosed(); /** Invoked when the PIP menu gets shown. */ void onShowPipMenu(); - /** Invoked when the PIPed activity is returned back to the fullscreen. */ + /** Invoked when the PIPed activity is about to return back to the fullscreen. */ void onMoveToFullscreen(); /** Invoked when we are above to start resizing the Pip. */ void onPipResizeAboutToStart(); diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipMenuActivity.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipMenuActivity.java index c54e73a7cda6..854e09d9d1a6 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipMenuActivity.java +++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipMenuActivity.java @@ -30,6 +30,7 @@ public class PipMenuActivity extends Activity implements PipManager.Listener { private final PipManager mPipManager = PipManager.getInstance(); private PipControlsView mPipControlsView; + private boolean mRestorePipSizeWhenClose; @Override protected void onCreate(Bundle bundle) { @@ -38,12 +39,21 @@ public class PipMenuActivity extends Activity implements PipManager.Listener { mPipManager.addListener(this); mPipControlsView = (PipControlsView) findViewById(R.id.pip_controls); + mRestorePipSizeWhenClose = true; + } + + private void restorePipAndFinish() { + if (mRestorePipSizeWhenClose) { + // When PIP menu activity is closed, restore to the default position. + mPipManager.resizePinnedStack(PipManager.STATE_PIP_OVERLAY); + } + finish(); } @Override public void onPause() { super.onPause(); - finish(); + restorePipAndFinish(); } @Override @@ -55,6 +65,11 @@ public class PipMenuActivity extends Activity implements PipManager.Listener { } @Override + public void onBackPressed() { + restorePipAndFinish(); + } + + @Override public void onPipEntered() { } @Override @@ -67,6 +82,9 @@ public class PipMenuActivity extends Activity implements PipManager.Listener { @Override public void onMoveToFullscreen() { + // Moving PIP to fullscreen is implemented by resizing PINNED_STACK with null bounds. + // This conflicts with restoring PIP position, so disable it. + mRestorePipSizeWhenClose = false; finish(); } diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipOverlayActivity.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipOverlayActivity.java index 5472ad6718dd..e205ff5749b0 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipOverlayActivity.java +++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipOverlayActivity.java @@ -35,6 +35,14 @@ import static android.app.ActivityManager.StackId.PINNED_STACK_ID; public class PipOverlayActivity extends Activity implements PipManager.Listener { private static final long SHOW_GUIDE_OVERLAY_VIEW_DURATION_MS = 4000; + /** + * A flag to ensure the single instance of PipOverlayActivity to prevent it from restarting. + * Note that {@link PipManager} moves the PIPed activity to fullscreen if the activity is + * restarted. It's because the activity may be started by the Launcher or an intent again, + * but we don't want do so for the PipOverlayActivity. + */ + private static boolean sActivityCreated; + private final PipManager mPipManager = PipManager.getInstance(); private final Handler mHandler = new Handler(); private View mGuideOverlayView; @@ -46,9 +54,23 @@ public class PipOverlayActivity extends Activity implements PipManager.Listener } }; + /** + * Shows PIP overlay UI only if it's not there. + */ + static void showPipOverlay(Context context) { + if (!sActivityCreated) { + Intent intent = new Intent(context, PipOverlayActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + final ActivityOptions options = ActivityOptions.makeBasic(); + options.setLaunchStackId(PINNED_STACK_ID); + context.startActivity(intent, options.toBundle()); + } + } + @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); + sActivityCreated = true; setContentView(R.layout.tv_pip_overlay); mGuideOverlayView = findViewById(R.id.guide_overlay); mPipManager.addListener(this); @@ -71,6 +93,7 @@ public class PipOverlayActivity extends Activity implements PipManager.Listener @Override protected void onDestroy() { super.onDestroy(); + sActivityCreated = false; mHandler.removeCallbacksAndMessages(null); mPipManager.removeListener(this); mPipManager.resumePipResizing( |