Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 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 | |
Winson | bf8c2c0 | 2016-10-18 18:56:24 -0700 | [diff] [blame] | 17 | package com.android.systemui.pip.tv; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 18 | |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorInflater; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 21 | import android.app.Activity; |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.pm.ParceledListSlice; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 24 | import android.os.Bundle; |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 25 | import android.util.Log; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 26 | |
| 27 | import com.android.systemui.R; |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 28 | import com.android.systemui.pip.tv.dagger.TvPipComponent; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 29 | |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 30 | import java.util.Collections; |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 31 | |
| 32 | import javax.inject.Inject; |
| 33 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Activity to show the PIP menu to control PIP. |
| 36 | */ |
| 37 | public class PipMenuActivity extends Activity implements PipManager.Listener { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 38 | private static final boolean DEBUG = false; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 39 | private static final String TAG = "PipMenuActivity"; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 40 | |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 41 | static final String EXTRA_CUSTOM_ACTIONS = "custom_actions"; |
| 42 | |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 43 | private final TvPipComponent.Builder mPipComponentBuilder; |
| 44 | private TvPipComponent mTvPipComponent; |
| 45 | private final PipManager mPipManager; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 46 | |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 47 | private Animator mFadeInAnimation; |
| 48 | private Animator mFadeOutAnimation; |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 49 | private boolean mRestorePipSizeWhenClose; |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 50 | private PipControlsViewController mPipControlsViewController; |
| 51 | |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 52 | @Inject |
| 53 | public PipMenuActivity(TvPipComponent.Builder pipComponentBuilder, PipManager pipManager) { |
| 54 | super(); |
| 55 | mPipComponentBuilder = pipComponentBuilder; |
| 56 | mPipManager = pipManager; |
| 57 | } |
Jaewan Kim | 1a9dc56 | 2016-02-17 13:41:51 -0800 | [diff] [blame] | 58 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 59 | @Override |
| 60 | protected void onCreate(Bundle bundle) { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 61 | if (DEBUG) Log.d(TAG, "onCreate()"); |
| 62 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 63 | super.onCreate(bundle); |
Jaewan Kim | c1d1524 | 2017-07-07 18:12:04 +0900 | [diff] [blame] | 64 | if (!mPipManager.isPipShown()) { |
| 65 | finish(); |
| 66 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 67 | setContentView(R.layout.tv_pip_menu); |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 68 | mTvPipComponent = mPipComponentBuilder.pipControlsView( |
| 69 | findViewById(R.id.pip_controls)).build(); |
| 70 | mPipControlsViewController = mTvPipComponent.getPipControlsViewController(); |
| 71 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 72 | mPipManager.addListener(this); |
Jaewan Kim | 1a9dc56 | 2016-02-17 13:41:51 -0800 | [diff] [blame] | 73 | |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 74 | mRestorePipSizeWhenClose = true; |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 75 | mFadeInAnimation = AnimatorInflater.loadAnimator( |
| 76 | this, R.anim.tv_pip_menu_fade_in_animation); |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 77 | mFadeInAnimation.setTarget(mPipControlsViewController.getView()); |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 78 | mFadeOutAnimation = AnimatorInflater.loadAnimator( |
| 79 | this, R.anim.tv_pip_menu_fade_out_animation); |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 80 | mFadeOutAnimation.setTarget(mPipControlsViewController.getView()); |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 81 | |
| 82 | onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS)); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | protected void onNewIntent(Intent intent) { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 87 | if (DEBUG) Log.d(TAG, "onNewIntent(), intent=" + intent); |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 88 | super.onNewIntent(intent); |
| 89 | |
| 90 | onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS)); |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | private void restorePipAndFinish() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 94 | if (DEBUG) Log.d(TAG, "restorePipAndFinish()"); |
| 95 | |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 96 | if (mRestorePipSizeWhenClose) { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 97 | if (DEBUG) Log.d(TAG, " > restoring to the default position"); |
| 98 | |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 99 | // When PIP menu activity is closed, restore to the default position. |
Jaewan Kim | e630923 | 2017-04-14 15:26:20 +0900 | [diff] [blame] | 100 | mPipManager.resizePinnedStack(PipManager.STATE_PIP); |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 101 | } |
| 102 | finish(); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Jaewan Kim | 9c23b28 | 2016-02-25 20:04:12 -0800 | [diff] [blame] | 105 | @Override |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 106 | public void onResume() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 107 | if (DEBUG) Log.d(TAG, "onResume()"); |
| 108 | |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 109 | super.onResume(); |
| 110 | mFadeInAnimation.start(); |
| 111 | } |
| 112 | |
| 113 | @Override |
Jaewan Kim | 9c23b28 | 2016-02-25 20:04:12 -0800 | [diff] [blame] | 114 | public void onPause() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 115 | if (DEBUG) Log.d(TAG, "onPause()"); |
| 116 | |
Jaewan Kim | 9c23b28 | 2016-02-25 20:04:12 -0800 | [diff] [blame] | 117 | super.onPause(); |
Jaewan Kim | 1e59f24 | 2016-04-07 16:22:49 +0900 | [diff] [blame] | 118 | mFadeOutAnimation.start(); |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 119 | restorePipAndFinish(); |
Jaewan Kim | 9c23b28 | 2016-02-25 20:04:12 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 122 | @Override |
| 123 | protected void onDestroy() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 124 | if (DEBUG) Log.d(TAG, "onDestroy()"); |
| 125 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 126 | super.onDestroy(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 127 | mPipManager.removeListener(this); |
| 128 | mPipManager.resumePipResizing( |
| 129 | PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 133 | public void onBackPressed() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 134 | if (DEBUG) Log.d(TAG, "onBackPressed()"); |
| 135 | |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 136 | restorePipAndFinish(); |
| 137 | } |
| 138 | |
| 139 | @Override |
Sergey Nikolaienkov | 00861da | 2020-04-27 10:56:26 +0200 | [diff] [blame] | 140 | public void onPipEntered(String packageName) { |
| 141 | if (DEBUG) Log.d(TAG, "onPipEntered(), packageName=" + packageName); |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 142 | } |
Jaewan Kim | 82ac50d | 2016-03-21 17:34:28 +0900 | [diff] [blame] | 143 | |
| 144 | @Override |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 145 | public void onPipActivityClosed() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 146 | if (DEBUG) Log.d(TAG, "onPipActivityClosed()"); |
| 147 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 148 | finish(); |
| 149 | } |
| 150 | |
| 151 | @Override |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 152 | public void onPipMenuActionsChanged(ParceledListSlice actions) { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 153 | if (DEBUG) Log.d(TAG, "onPipMenuActionsChanged()"); |
| 154 | |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 155 | boolean hasCustomActions = actions != null && !actions.getList().isEmpty(); |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 156 | mPipControlsViewController.setActions( |
| 157 | hasCustomActions ? actions.getList() : Collections.EMPTY_LIST); |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | @Override |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 161 | public void onShowPipMenu() { |
| 162 | if (DEBUG) Log.d(TAG, "onShowPipMenu()"); |
| 163 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 164 | |
| 165 | @Override |
| 166 | public void onMoveToFullscreen() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 167 | if (DEBUG) Log.d(TAG, "onMoveToFullscreen()"); |
| 168 | |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 169 | // 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 Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 172 | finish(); |
| 173 | } |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 174 | |
| 175 | @Override |
| 176 | public void onPipResizeAboutToStart() { |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 177 | if (DEBUG) Log.d(TAG, "onPipResizeAboutToStart()"); |
| 178 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 179 | finish(); |
| 180 | mPipManager.suspendPipResizing( |
| 181 | PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH); |
| 182 | } |
Sergey Nikolaienkov | bbb12de | 2020-04-08 10:47:12 +0200 | [diff] [blame] | 183 | |
| 184 | @Override |
| 185 | public void finish() { |
| 186 | if (DEBUG) Log.d(TAG, "finish()", new RuntimeException()); |
| 187 | |
| 188 | super.finish(); |
| 189 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 190 | } |