blob: ea9275f8a918a5755b7d6a62738074092d0604de [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
17package com.android.systemui.tv.pip;
18
19import android.app.Activity;
Youngsang Chof1647922015-12-17 13:39:39 -080020import android.os.Bundle;
Youngsang Chof1647922015-12-17 13:39:39 -080021
22import com.android.systemui.R;
Jaewan Kim3ebc1e32016-02-26 12:54:33 -080023import com.android.systemui.SystemUI;
24import com.android.systemui.SystemUIApplication;
25import com.android.systemui.recents.Recents;
Youngsang Chof1647922015-12-17 13:39:39 -080026
Jaewan Kim62338192016-02-25 10:00:05 -080027import static android.content.pm.PackageManager.FEATURE_LEANBACK;
28import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
Jaewan Kim62338192016-02-25 10:00:05 -080029
Youngsang Chof1647922015-12-17 13:39:39 -080030/**
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";
Youngsang Chof1647922015-12-17 13:39:39 -080035
36 private final PipManager mPipManager = PipManager.getInstance();
Youngsang Chof1647922015-12-17 13:39:39 -080037
Jaewan Kim8f584b82016-03-22 22:16:59 +090038 private PipControlsView mPipControlsView;
Jaewan Kim88baef62016-03-04 15:08:41 +090039 private boolean mPipMovedToFullscreen;
Jaewan Kim1a9dc562016-02-17 13:41:51 -080040
Youngsang Chof1647922015-12-17 13:39:39 -080041 @Override
42 protected void onCreate(Bundle bundle) {
43 super.onCreate(bundle);
44 setContentView(R.layout.tv_pip_menu);
45 mPipManager.addListener(this);
Jaewan Kim1a9dc562016-02-17 13:41:51 -080046
Jaewan Kim8f584b82016-03-22 22:16:59 +090047 mPipControlsView = (PipControlsView) findViewById(R.id.pip_controls);
Youngsang Chof1647922015-12-17 13:39:39 -080048 }
49
Jaewan Kim9c23b282016-02-25 20:04:12 -080050 private void restorePipAndFinish() {
Jaewan Kim88baef62016-03-04 15:08:41 +090051 if (!mPipMovedToFullscreen) {
Jaewan Kim32686b62016-03-03 19:03:18 +090052 mPipManager.resizePinnedStack(PipManager.STATE_PIP_OVERLAY);
53 }
Jaewan Kim9c23b282016-02-25 20:04:12 -080054 finish();
55 }
56
57 @Override
58 public void onPause() {
59 super.onPause();
60 restorePipAndFinish();
61 }
62
Youngsang Chof1647922015-12-17 13:39:39 -080063 @Override
64 protected void onDestroy() {
Youngsang Chof1647922015-12-17 13:39:39 -080065 super.onDestroy();
Wale Ogunwale480dca02016-02-06 13:58:29 -080066 mPipManager.removeListener(this);
67 mPipManager.resumePipResizing(
68 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
Youngsang Chof1647922015-12-17 13:39:39 -080069 }
70
71 @Override
72 public void onBackPressed() {
Jaewan Kim9c23b282016-02-25 20:04:12 -080073 restorePipAndFinish();
Youngsang Chof1647922015-12-17 13:39:39 -080074 }
75
76 @Override
Jaewan Kim82ac50d2016-03-21 17:34:28 +090077 public void onPipEntered() { }
78
79 @Override
Youngsang Chof1647922015-12-17 13:39:39 -080080 public void onPipActivityClosed() {
81 finish();
82 }
83
84 @Override
85 public void onShowPipMenu() { }
86
87 @Override
88 public void onMoveToFullscreen() {
Jaewan Kim8f584b82016-03-22 22:16:59 +090089 mPipMovedToFullscreen = true;
Youngsang Chof1647922015-12-17 13:39:39 -080090 finish();
91 }
Wale Ogunwale480dca02016-02-06 13:58:29 -080092
93 @Override
Jaewan Kim8f584b82016-03-22 22:16:59 +090094 public void onMediaControllerChanged() { }
Jaewan Kim62338192016-02-25 10:00:05 -080095
96 @Override
Wale Ogunwale480dca02016-02-06 13:58:29 -080097 public void onPipResizeAboutToStart() {
98 finish();
99 mPipManager.suspendPipResizing(
100 PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
101 }
Jaewan Kim3ebc1e32016-02-26 12:54:33 -0800102
103 @Override
104 public void finish() {
105 super.finish();
Jaewan Kim88baef62016-03-04 15:08:41 +0900106 if (mPipManager.isRecentsShown() && !mPipMovedToFullscreen) {
Jaewan Kim3ebc1e32016-02-26 12:54:33 -0800107 SystemUI[] services = ((SystemUIApplication) getApplication()).getServices();
108 for (int i = services.length - 1; i >= 0; i--) {
109 if (services[i] instanceof Recents) {
110 ((Recents) services[i]).showRecents(false, null);
111 break;
112 }
113 }
114 }
115 }
Youngsang Chof1647922015-12-17 13:39:39 -0800116}