• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.support.v17.leanback.app.PlaybackSupportFragmentGlueHost;
26 import android.support.v17.leanback.widget.Action;
27 import android.support.v17.leanback.widget.ArrayObjectAdapter;
28 import android.support.v17.leanback.widget.ClassPresenterSelector;
29 import android.support.v17.leanback.widget.HeaderItem;
30 import android.support.v17.leanback.widget.ListRow;
31 import android.support.v17.leanback.widget.ListRowPresenter;
32 import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
33 import android.util.Log;
34 
35 /**
36  * Example of PlaybackSupportFragment working with a PlaybackControlGlue.
37  */
38 public class PlaybackTransportControlSupportFragment
39         extends android.support.v17.leanback.app.PlaybackSupportFragment
40         implements PlaybackTransportControlSupportActivity.PictureInPictureListener {
41     private static final String TAG = "TransportFragment";
42 
43     /**
44      * Change this to choose a different overlay background.
45      */
46     private static final int BACKGROUND_TYPE = BG_DARK;
47 
48     /**
49      * Change the number of related content rows.
50      */
51     private static final int RELATED_CONTENT_ROWS = 3;
52 
53     private static final int ROW_CONTROLS = 0;
54 
55     private PlaybackTransportControlGlueSample mGlue;
56 
getAdapter()57     public SparseArrayObjectAdapter getAdapter() {
58         return (SparseArrayObjectAdapter) super.getAdapter();
59     }
60 
61     @Override
onCreate(Bundle savedInstanceState)62     public void onCreate(Bundle savedInstanceState) {
63         Log.i(TAG, "onCreate");
64         super.onCreate(savedInstanceState);
65 
66         setBackgroundType(BACKGROUND_TYPE);
67 
68         createComponents(getActivity());
69     }
70 
createComponents(Context context)71     private void createComponents(Context context) {
72         mGlue = new PlaybackTransportControlGlueSample(context, new PlayerAdapter()) {
73             @Override
74             public void onActionClicked(Action action) {
75                 if (action.getId() == R.id.lb_control_picture_in_picture) {
76                     if (Build.VERSION.SDK_INT >= 24) {
77                         getActivity().enterPictureInPictureMode();
78                     }
79                     return;
80                 }
81                 super.onActionClicked(action);
82             }
83 
84         };
85 
86         mGlue.setTitle("Title");
87         mGlue.setSubtitle("Android developer");
88         mGlue.setHost(new PlaybackSupportFragmentGlueHost(this));
89         mGlue.setSeekProvider(new PlaybackSeekDataProviderSample(
90                 PlayerAdapter.FAUX_DURATION, 100));
91 
92         ClassPresenterSelector selector = new ClassPresenterSelector();
93         selector.addClassPresenter(ListRow.class, new ListRowPresenter());
94         setAdapter(new SparseArrayObjectAdapter(selector));
95 
96         // Add related content rows
97         for (int i = 0; i < RELATED_CONTENT_ROWS; ++i) {
98             ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new StringPresenter());
99             listRowAdapter.add("Some related content");
100             listRowAdapter.add("Other related content");
101             HeaderItem header = new HeaderItem(i, "Row " + i);
102             getAdapter().set(ROW_CONTROLS + 1 + i, new ListRow(header, listRowAdapter));
103         }
104     }
105 
106     @Override
onStart()107     public void onStart() {
108         super.onStart();
109         ((PlaybackTransportControlSupportActivity) getActivity()).registerPictureInPictureListener(this);
110     }
111 
112     @Override
onStop()113     public void onStop() {
114         ((PlaybackTransportControlSupportActivity) getActivity()).unregisterPictureInPictureListener(this);
115         super.onStop();
116     }
117 
118     @Override
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)119     public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
120         if (isInPictureInPictureMode) {
121             // Hide the controls in picture-in-picture mode.
122             setControlsOverlayAutoHideEnabled(true);
123             hideControlsOverlay(true);
124         } else {
125             setControlsOverlayAutoHideEnabled(mGlue.isPlaying());
126         }
127     }
128 }
129