blob: 158be45e0adbdb3c07bf2f1701c8f8c16dee7289 [file] [log] [blame]
Youngsang Chof1647922015-12-17 13:39:39 -08001/*
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
Winsonbf8c2c02016-10-18 18:56:24 -070017package com.android.systemui.pip.tv;
Youngsang Chof1647922015-12-17 13:39:39 -080018
Jaewan Kim1e59f242016-04-07 16:22:49 +090019import android.animation.Animator;
20import android.animation.AnimatorInflater;
Youngsang Chof1647922015-12-17 13:39:39 -080021import android.app.Activity;
Winson Chungb6de8722017-06-02 12:45:51 -070022import android.content.Intent;
23import android.content.pm.ParceledListSlice;
Youngsang Chof1647922015-12-17 13:39:39 -080024import android.os.Bundle;
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +020025import android.util.Log;
Youngsang Chof1647922015-12-17 13:39:39 -080026
27import com.android.systemui.R;
Dave Mankofff5019142019-12-20 16:22:57 -050028import com.android.systemui.pip.tv.dagger.TvPipComponent;
Jaewan Kim62338192016-02-25 10:00:05 -080029
Winson Chungb6de8722017-06-02 12:45:51 -070030import java.util.Collections;
Dave Mankofff5019142019-12-20 16:22:57 -050031
32import javax.inject.Inject;
33
Youngsang Chof1647922015-12-17 13:39:39 -080034/**
35 * Activity to show the PIP menu to control PIP.
36 */
37public class PipMenuActivity extends Activity implements PipManager.Listener {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +020038 private static final boolean DEBUG = false;
Youngsang Chof1647922015-12-17 13:39:39 -080039 private static final String TAG = "PipMenuActivity";
Youngsang Chof1647922015-12-17 13:39:39 -080040
Winson Chungb6de8722017-06-02 12:45:51 -070041 static final String EXTRA_CUSTOM_ACTIONS = "custom_actions";
42
Dave Mankofff5019142019-12-20 16:22:57 -050043 private final TvPipComponent.Builder mPipComponentBuilder;
44 private TvPipComponent mTvPipComponent;
45 private final PipManager mPipManager;
Youngsang Chof1647922015-12-17 13:39:39 -080046
Jaewan Kim1e59f242016-04-07 16:22:49 +090047 private Animator mFadeInAnimation;
48 private Animator mFadeOutAnimation;
Jaewan Kim10a86912016-04-04 16:01:51 +090049 private boolean mRestorePipSizeWhenClose;
Dave Mankofff5019142019-12-20 16:22:57 -050050 private PipControlsViewController mPipControlsViewController;
51
Dave Mankofff5019142019-12-20 16:22:57 -050052 @Inject
53 public PipMenuActivity(TvPipComponent.Builder pipComponentBuilder, PipManager pipManager) {
54 super();
55 mPipComponentBuilder = pipComponentBuilder;
56 mPipManager = pipManager;
57 }
Jaewan Kim1a9dc562016-02-17 13:41:51 -080058
Youngsang Chof1647922015-12-17 13:39:39 -080059 @Override
60 protected void onCreate(Bundle bundle) {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +020061 if (DEBUG) Log.d(TAG, "onCreate()");
62
Youngsang Chof1647922015-12-17 13:39:39 -080063 super.onCreate(bundle);
Jaewan Kimc1d15242017-07-07 18:12:04 +090064 if (!mPipManager.isPipShown()) {
65 finish();
66 }
Youngsang Chof1647922015-12-17 13:39:39 -080067 setContentView(R.layout.tv_pip_menu);
Dave Mankofff5019142019-12-20 16:22:57 -050068 mTvPipComponent = mPipComponentBuilder.pipControlsView(
69 findViewById(R.id.pip_controls)).build();
70 mPipControlsViewController = mTvPipComponent.getPipControlsViewController();
71
Youngsang Chof1647922015-12-17 13:39:39 -080072 mPipManager.addListener(this);
Jaewan Kim1a9dc562016-02-17 13:41:51 -080073
Jaewan Kim10a86912016-04-04 16:01:51 +090074 mRestorePipSizeWhenClose = true;
Jaewan Kim1e59f242016-04-07 16:22:49 +090075 mFadeInAnimation = AnimatorInflater.loadAnimator(
76 this, R.anim.tv_pip_menu_fade_in_animation);
Dave Mankofff5019142019-12-20 16:22:57 -050077 mFadeInAnimation.setTarget(mPipControlsViewController.getView());
Jaewan Kim1e59f242016-04-07 16:22:49 +090078 mFadeOutAnimation = AnimatorInflater.loadAnimator(
79 this, R.anim.tv_pip_menu_fade_out_animation);
Dave Mankofff5019142019-12-20 16:22:57 -050080 mFadeOutAnimation.setTarget(mPipControlsViewController.getView());
Winson Chungb6de8722017-06-02 12:45:51 -070081
82 onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS));
83 }
84
85 @Override
86 protected void onNewIntent(Intent intent) {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +020087 if (DEBUG) Log.d(TAG, "onNewIntent(), intent=" + intent);
Winson Chungb6de8722017-06-02 12:45:51 -070088 super.onNewIntent(intent);
89
90 onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS));
Jaewan Kim10a86912016-04-04 16:01:51 +090091 }
92
93 private void restorePipAndFinish() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +020094 if (DEBUG) Log.d(TAG, "restorePipAndFinish()");
95
Jaewan Kim10a86912016-04-04 16:01:51 +090096 if (mRestorePipSizeWhenClose) {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +020097 if (DEBUG) Log.d(TAG, " > restoring to the default position");
98
Jaewan Kim10a86912016-04-04 16:01:51 +090099 // When PIP menu activity is closed, restore to the default position.
Jaewan Kime6309232017-04-14 15:26:20 +0900100 mPipManager.resizePinnedStack(PipManager.STATE_PIP);
Jaewan Kim10a86912016-04-04 16:01:51 +0900101 }
102 finish();
Youngsang Chof1647922015-12-17 13:39:39 -0800103 }
104
Jaewan Kim9c23b282016-02-25 20:04:12 -0800105 @Override
Jaewan Kim1e59f242016-04-07 16:22:49 +0900106 public void onResume() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200107 if (DEBUG) Log.d(TAG, "onResume()");
108
Jaewan Kim1e59f242016-04-07 16:22:49 +0900109 super.onResume();
110 mFadeInAnimation.start();
111 }
112
113 @Override
Jaewan Kim9c23b282016-02-25 20:04:12 -0800114 public void onPause() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200115 if (DEBUG) Log.d(TAG, "onPause()");
116
Jaewan Kim9c23b282016-02-25 20:04:12 -0800117 super.onPause();
Jaewan Kim1e59f242016-04-07 16:22:49 +0900118 mFadeOutAnimation.start();
Jaewan Kim10a86912016-04-04 16:01:51 +0900119 restorePipAndFinish();
Jaewan Kim9c23b282016-02-25 20:04:12 -0800120 }
121
Youngsang Chof1647922015-12-17 13:39:39 -0800122 @Override
123 protected void onDestroy() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200124 if (DEBUG) Log.d(TAG, "onDestroy()");
125
Youngsang Chof1647922015-12-17 13:39:39 -0800126 super.onDestroy();
Wale Ogunwale480dca02016-02-06 13:58:29 -0800127 mPipManager.removeListener(this);
128 mPipManager.resumePipResizing(
129 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
Youngsang Chof1647922015-12-17 13:39:39 -0800130 }
131
132 @Override
Jaewan Kim10a86912016-04-04 16:01:51 +0900133 public void onBackPressed() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200134 if (DEBUG) Log.d(TAG, "onBackPressed()");
135
Jaewan Kim10a86912016-04-04 16:01:51 +0900136 restorePipAndFinish();
137 }
138
139 @Override
Sergey Nikolaienkov00861da2020-04-27 10:56:26 +0200140 public void onPipEntered(String packageName) {
141 if (DEBUG) Log.d(TAG, "onPipEntered(), packageName=" + packageName);
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200142 }
Jaewan Kim82ac50d2016-03-21 17:34:28 +0900143
144 @Override
Youngsang Chof1647922015-12-17 13:39:39 -0800145 public void onPipActivityClosed() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200146 if (DEBUG) Log.d(TAG, "onPipActivityClosed()");
147
Youngsang Chof1647922015-12-17 13:39:39 -0800148 finish();
149 }
150
151 @Override
Winson Chungb6de8722017-06-02 12:45:51 -0700152 public void onPipMenuActionsChanged(ParceledListSlice actions) {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200153 if (DEBUG) Log.d(TAG, "onPipMenuActionsChanged()");
154
Winson Chungb6de8722017-06-02 12:45:51 -0700155 boolean hasCustomActions = actions != null && !actions.getList().isEmpty();
Dave Mankofff5019142019-12-20 16:22:57 -0500156 mPipControlsViewController.setActions(
157 hasCustomActions ? actions.getList() : Collections.EMPTY_LIST);
Winson Chungb6de8722017-06-02 12:45:51 -0700158 }
159
160 @Override
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200161 public void onShowPipMenu() {
162 if (DEBUG) Log.d(TAG, "onShowPipMenu()");
163 }
Youngsang Chof1647922015-12-17 13:39:39 -0800164
165 @Override
166 public void onMoveToFullscreen() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200167 if (DEBUG) Log.d(TAG, "onMoveToFullscreen()");
168
Jaewan Kim10a86912016-04-04 16:01:51 +0900169 // Moving PIP to fullscreen is implemented by resizing PINNED_STACK with null bounds.
170 // This conflicts with restoring PIP position, so disable it.
171 mRestorePipSizeWhenClose = false;
Youngsang Chof1647922015-12-17 13:39:39 -0800172 finish();
173 }
Wale Ogunwale480dca02016-02-06 13:58:29 -0800174
175 @Override
176 public void onPipResizeAboutToStart() {
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200177 if (DEBUG) Log.d(TAG, "onPipResizeAboutToStart()");
178
Wale Ogunwale480dca02016-02-06 13:58:29 -0800179 finish();
180 mPipManager.suspendPipResizing(
181 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
182 }
Sergey Nikolaienkovbbb12de2020-04-08 10:47:12 +0200183
184 @Override
185 public void finish() {
186 if (DEBUG) Log.d(TAG, "finish()", new RuntimeException());
187
188 super.finish();
189 }
Youngsang Chof1647922015-12-17 13:39:39 -0800190}