PipMenuActivity.java revision b6de872eb3316d6c5893373ba2848ffee07adb3c
1/* 2 * Copyright (C) 2016 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 17package com.android.systemui.pip.tv; 18 19import android.animation.Animator; 20import android.animation.AnimatorInflater; 21import android.app.Activity; 22import android.content.Intent; 23import android.content.pm.ParceledListSlice; 24import android.os.Bundle; 25import android.view.View; 26 27import com.android.systemui.R; 28 29import java.util.Collections; 30/** 31 * Activity to show the PIP menu to control PIP. 32 */ 33public class PipMenuActivity extends Activity implements PipManager.Listener { 34 private static final String TAG = "PipMenuActivity"; 35 36 static final String EXTRA_CUSTOM_ACTIONS = "custom_actions"; 37 38 private final PipManager mPipManager = PipManager.getInstance(); 39 40 private Animator mFadeInAnimation; 41 private Animator mFadeOutAnimation; 42 private PipControlsView mPipControlsView; 43 private boolean mRestorePipSizeWhenClose; 44 45 @Override 46 protected void onCreate(Bundle bundle) { 47 super.onCreate(bundle); 48 setContentView(R.layout.tv_pip_menu); 49 mPipManager.addListener(this); 50 51 mRestorePipSizeWhenClose = true; 52 mPipControlsView = findViewById(R.id.pip_controls); 53 mFadeInAnimation = AnimatorInflater.loadAnimator( 54 this, R.anim.tv_pip_menu_fade_in_animation); 55 mFadeInAnimation.setTarget(mPipControlsView); 56 mFadeOutAnimation = AnimatorInflater.loadAnimator( 57 this, R.anim.tv_pip_menu_fade_out_animation); 58 mFadeOutAnimation.setTarget(mPipControlsView); 59 60 onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS)); 61 } 62 63 @Override 64 protected void onNewIntent(Intent intent) { 65 super.onNewIntent(intent); 66 67 onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS)); 68 } 69 70 private void restorePipAndFinish() { 71 if (mRestorePipSizeWhenClose) { 72 // When PIP menu activity is closed, restore to the default position. 73 mPipManager.resizePinnedStack(PipManager.STATE_PIP); 74 } 75 finish(); 76 } 77 78 @Override 79 public void onResume() { 80 super.onResume(); 81 mFadeInAnimation.start(); 82 } 83 84 @Override 85 public void onPause() { 86 super.onPause(); 87 mFadeOutAnimation.start(); 88 restorePipAndFinish(); 89 } 90 91 @Override 92 protected void onDestroy() { 93 super.onDestroy(); 94 mPipManager.removeListener(this); 95 mPipManager.resumePipResizing( 96 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH); 97 } 98 99 @Override 100 public void onBackPressed() { 101 restorePipAndFinish(); 102 } 103 104 @Override 105 public void onPipEntered() { } 106 107 @Override 108 public void onPipActivityClosed() { 109 finish(); 110 } 111 112 @Override 113 public void onPipMenuActionsChanged(ParceledListSlice actions) { 114 boolean hasCustomActions = actions != null && !actions.getList().isEmpty(); 115 mPipControlsView.setActions(hasCustomActions ? actions.getList() : Collections.EMPTY_LIST); 116 } 117 118 @Override 119 public void onShowPipMenu() { } 120 121 @Override 122 public void onMoveToFullscreen() { 123 // Moving PIP to fullscreen is implemented by resizing PINNED_STACK with null bounds. 124 // This conflicts with restoring PIP position, so disable it. 125 mRestorePipSizeWhenClose = false; 126 finish(); 127 } 128 129 @Override 130 public void onPipResizeAboutToStart() { 131 finish(); 132 mPipManager.suspendPipResizing( 133 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH); 134 } 135} 136