PlaybackGlueHost.java revision d34f4eb6802453f26a0df113017bc5792fc19868
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
17package android.support.v17.leanback.media;
18
19import android.support.v17.leanback.widget.OnActionClickedListener;
20import android.support.v17.leanback.widget.PlaybackRowPresenter;
21import android.support.v17.leanback.widget.Row;
22import android.view.View;
23
24/**
25 * This class represents the UI (e.g. Fragment/Activity) hosting playback controls and
26 * defines the interaction between {@link PlaybackGlue} and the host.
27 * PlaybackGlueHost provides the following functions:
28 * <li>Render UI of PlaybackGlue: {@link #setPlaybackRow(Row)},
29 * {@link #setPlaybackRowPresenter(PlaybackRowPresenter)}.
30 * </li>
31 * <li>Callback for fragment/activity onStart/onStop: {@link #setHostCallback(HostCallback)}.
32 * </li>
33 * <li>Auto fade out controls after a short period: {@link #setFadingEnabled(boolean)}.
34 * </li>
35 * <li>Key listener and ActionListener. {@link #setOnKeyInterceptListener(View.OnKeyListener)},
36 * {@link #setOnActionClickedListener(OnActionClickedListener)}.
37 * </li>
38 *
39 * Subclass of PlaybackGlueHost may implement optional interface e.g. {@link SurfaceHolderGlueHost}
40 * to provide SurfaceView. These optional interface should be used during
41 * {@link PlaybackGlue#setHost(PlaybackGlueHost)}.
42 */
43public abstract class PlaybackGlueHost {
44    PlaybackGlue mGlue;
45
46    /**
47     * Callbacks triggered by the host(e.g. fragment) hosting the video controls/surface.
48     *
49     * @see #setHostCallback(HostCallback)
50     */
51    public abstract static class HostCallback {
52        /**
53         * Callback triggered once the host(fragment) has started.
54         */
55        public void onHostStart() {
56        }
57
58        /**
59         * Callback triggered once the host(fragment) has stopped.
60         */
61        public void onHostStop() {
62        }
63
64        /**
65         * Callback triggered once the host(fragment) has paused.
66         */
67        public void onHostPause() {
68        }
69
70        /**
71         * Callback triggered once the host(fragment) has resumed.
72         */
73        public void onHostResume() {
74        }
75
76        /**
77         * Callback triggered once the host(fragment) has been destroyed.
78         */
79        public void onHostDestroy() {
80        }
81    }
82
83    /**
84     * Enables or disables view fading.  If enabled, the view will be faded in when the
85     * fragment starts and will fade out after a time period.
86     */
87    public void setFadingEnabled(boolean enable) {
88    }
89
90    /**
91     * Fade out views immediately.
92     */
93    public void fadeOut() {
94    }
95
96    /**
97     * Sets the {@link android.view.View.OnKeyListener} on the host. This would trigger
98     * the listener when a {@link android.view.KeyEvent} is unhandled by the host.
99     */
100    public void setOnKeyInterceptListener(View.OnKeyListener onKeyListener) {
101    }
102
103    /**
104     * Sets the {@link View.OnClickListener} on this fragment.
105     */
106    public void setOnActionClickedListener(OnActionClickedListener listener) {}
107
108    /**
109     * Sets the host {@link HostCallback} callback on the host. This method should only be called
110     * by {@link PlaybackGlue}. App should not directly call this method, app should override
111     * {@link PlaybackGlue#onHostStart()} etc.
112     */
113    public void setHostCallback(HostCallback callback) {
114    }
115
116    /**
117     * Notifies host about a change so it can update the view.
118     */
119    public void notifyPlaybackRowChanged() {}
120
121    /**
122     * Sets {@link PlaybackRowPresenter} for rendering the playback controls.
123     */
124    public void setPlaybackRowPresenter(PlaybackRowPresenter presenter) {}
125
126    /**
127     * Sets the {@link Row} that represents the information on control items that needs
128     * to be rendered.
129     */
130    public void setPlaybackRow(Row row) {}
131
132    final void attachToGlue(PlaybackGlue glue) {
133        if (mGlue != null) {
134            mGlue.onDetachedFromHost();
135        }
136        mGlue = glue;
137        if (mGlue != null) {
138            mGlue.onAttachedToHost(this);
139        }
140    }
141
142}
143