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 17 package com.example.android.leanback; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 22 import java.util.ArrayList; 23 import java.util.List; 24 25 /** 26 * Host PlaybackFragment and provide PIP events. 27 */ 28 public class PlaybackActivity extends Activity { 29 private List<PictureInPictureListener> mListeners = new ArrayList<>(); 30 31 /** Called when the activity is first created. */ 32 @Override onCreate(Bundle savedInstanceState)33 public void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 setContentView(R.layout.playback_activity); 36 } 37 38 @Override onPictureInPictureModeChanged(boolean isInPictureInPictureMode)39 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 40 for (PictureInPictureListener listener : mListeners) { 41 listener.onPictureInPictureModeChanged(isInPictureInPictureMode); 42 } 43 } 44 45 /** 46 * Register a PIP listener. 47 */ registerPictureInPictureListener(PictureInPictureListener listener)48 public void registerPictureInPictureListener(PictureInPictureListener listener) { 49 mListeners.add(listener); 50 } 51 52 /** 53 * Unregister a PIP listener. 54 */ unregisterPictureInPictureListener(PictureInPictureListener listener)55 public void unregisterPictureInPictureListener(PictureInPictureListener listener) { 56 mListeners.remove(listener); 57 } 58 59 /** 60 * Interface of PIP event on Activity. 61 */ 62 public interface PictureInPictureListener { 63 /** 64 * Called when Activity's PIP mode is changed. 65 */ onPictureInPictureModeChanged(boolean isInPictureInPictureMode)66 void onPictureInPictureModeChanged(boolean isInPictureInPictureMode); 67 } 68 } 69