1 // CHECKSTYLE:OFF Generated code 2 /* This file is auto-generated from PlaybackTransportControlFragment.java. DO NOT MODIFY. */ 3 4 /* 5 * Copyright (C) 2016 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package com.example.android.leanback; 21 22 import android.content.Context; 23 import android.os.Build; 24 import android.os.Bundle; 25 import android.util.Log; 26 27 import androidx.leanback.app.PlaybackSupportFragmentGlueHost; 28 import androidx.leanback.widget.Action; 29 import androidx.leanback.widget.ArrayObjectAdapter; 30 import androidx.leanback.widget.ClassPresenterSelector; 31 import androidx.leanback.widget.HeaderItem; 32 import androidx.leanback.widget.ListRow; 33 import androidx.leanback.widget.ListRowPresenter; 34 import androidx.leanback.widget.SparseArrayObjectAdapter; 35 36 /** 37 * Example of PlaybackSupportFragment working with a PlaybackControlGlue. 38 */ 39 public class PlaybackTransportControlSupportFragment 40 extends androidx.leanback.app.PlaybackSupportFragment 41 implements PlaybackTransportControlSupportActivity.PictureInPictureListener { 42 private static final String TAG = "TransportFragment"; 43 44 /** 45 * Change this to choose a different overlay background. 46 */ 47 private static final int BACKGROUND_TYPE = BG_DARK; 48 49 /** 50 * Change the number of related content rows. 51 */ 52 private static final int RELATED_CONTENT_ROWS = 3; 53 54 private static final int ROW_CONTROLS = 0; 55 56 private PlaybackTransportControlGlueSample mGlue; 57 getAdapter()58 public SparseArrayObjectAdapter getAdapter() { 59 return (SparseArrayObjectAdapter) super.getAdapter(); 60 } 61 62 @Override onCreate(Bundle savedInstanceState)63 public void onCreate(Bundle savedInstanceState) { 64 Log.i(TAG, "onCreate"); 65 super.onCreate(savedInstanceState); 66 67 setBackgroundType(BACKGROUND_TYPE); 68 69 createComponents(getActivity()); 70 } 71 createComponents(Context context)72 private void createComponents(Context context) { 73 mGlue = new PlaybackTransportControlGlueSample(context, new PlayerAdapter()) { 74 @Override 75 public void onActionClicked(Action action) { 76 if (action.getId() == R.id.lb_control_picture_in_picture) { 77 if (Build.VERSION.SDK_INT >= 24) { 78 getActivity().enterPictureInPictureMode(); 79 } 80 return; 81 } 82 super.onActionClicked(action); 83 } 84 85 }; 86 87 mGlue.setTitle("Title"); 88 mGlue.setSubtitle("Android developer"); 89 mGlue.setHost(new PlaybackSupportFragmentGlueHost(this)); 90 mGlue.setSeekProvider(new PlaybackSeekDataProviderSample( 91 PlayerAdapter.FAUX_DURATION, 100)); 92 93 ClassPresenterSelector selector = new ClassPresenterSelector(); 94 selector.addClassPresenter(ListRow.class, new ListRowPresenter()); 95 setAdapter(new SparseArrayObjectAdapter(selector)); 96 97 // Add related content rows 98 for (int i = 0; i < RELATED_CONTENT_ROWS; ++i) { 99 ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new StringPresenter()); 100 listRowAdapter.add("Some related content"); 101 listRowAdapter.add("Other related content"); 102 HeaderItem header = new HeaderItem(i, "Row " + i); 103 getAdapter().set(ROW_CONTROLS + 1 + i, new ListRow(header, listRowAdapter)); 104 } 105 } 106 107 @Override onStart()108 public void onStart() { 109 super.onStart(); 110 ((PlaybackTransportControlSupportActivity) getActivity()).registerPictureInPictureListener(this); 111 } 112 113 @Override onStop()114 public void onStop() { 115 ((PlaybackTransportControlSupportActivity) getActivity()).unregisterPictureInPictureListener(this); 116 super.onStop(); 117 } 118 119 @Override onPictureInPictureModeChanged(boolean isInPictureInPictureMode)120 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 121 if (isInPictureInPictureMode) { 122 // Hide the controls in picture-in-picture mode. 123 setControlsOverlayAutoHideEnabled(true); 124 hideControlsOverlay(true); 125 } else { 126 setControlsOverlayAutoHideEnabled(mGlue.isPlaying()); 127 } 128 } 129 } 130