Merge "PIP: Fix regressions caused by previous commit a0d4d25" into nyc-dev

This commit is contained in:
Jaewan Kim
2016-04-06 05:46:55 +00:00
committed by Android (Google) Code Review
4 changed files with 44 additions and 8 deletions

View File

@@ -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"

View File

@@ -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();

View File

@@ -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
@@ -54,6 +64,11 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {
PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
}
@Override
public void onBackPressed() {
restorePipAndFinish();
}
@Override
public void onPipEntered() { }
@@ -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();
}

View File

@@ -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(