Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 17 | package android.media.tv; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 18 | |
Jae Seo | c8b7356 | 2015-04-23 10:53:58 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Dongwon Kang | 4bf607b | 2015-04-23 19:44:59 +0900 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 22 | import android.content.Context; |
Dongwon Kang | 5f3cb4a | 2014-11-19 18:12:44 +0900 | [diff] [blame] | 23 | import android.graphics.Canvas; |
| 24 | import android.graphics.PorterDuff; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 25 | import android.graphics.Rect; |
Dongwon Kang | 5f3cb4a | 2014-11-19 18:12:44 +0900 | [diff] [blame] | 26 | import android.graphics.Region; |
Jae Seo | 3d04b76 | 2015-05-12 20:05:00 -0700 | [diff] [blame] | 27 | import android.media.PlaybackParams; |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 28 | import android.media.tv.TvInputManager.Session; |
| 29 | import android.media.tv.TvInputManager.Session.FinishedInputEventCallback; |
| 30 | import android.media.tv.TvInputManager.SessionCallback; |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 31 | import android.net.Uri; |
Youngsang Cho | 832860f | 2014-05-21 20:54:03 +0900 | [diff] [blame] | 32 | import android.os.Bundle; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 33 | import android.os.Handler; |
Sungsoo Lim | d6672b5 | 2014-04-30 10:43:26 +0900 | [diff] [blame] | 34 | import android.text.TextUtils; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 35 | import android.util.AttributeSet; |
| 36 | import android.util.Log; |
Jae Seo | 411d58d | 2015-04-22 16:21:08 -0700 | [diff] [blame] | 37 | import android.util.Pair; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 38 | import android.view.InputEvent; |
| 39 | import android.view.KeyEvent; |
| 40 | import android.view.MotionEvent; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 41 | import android.view.Surface; |
| 42 | import android.view.SurfaceHolder; |
| 43 | import android.view.SurfaceView; |
Youngsang Cho | 07b7c5f | 2014-06-27 16:21:07 +0900 | [diff] [blame] | 44 | import android.view.View; |
Jae Seo | 1bfce9f | 2014-06-03 23:58:49 -0700 | [diff] [blame] | 45 | import android.view.ViewGroup; |
Chulwoo Lee | c3e00c3 | 2014-05-14 11:31:51 +0900 | [diff] [blame] | 46 | import android.view.ViewRootImpl; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 47 | |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 48 | import java.lang.ref.WeakReference; |
Jae Seo | 411d58d | 2015-04-22 16:21:08 -0700 | [diff] [blame] | 49 | import java.util.ArrayDeque; |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 50 | import java.util.List; |
Jae Seo | 411d58d | 2015-04-22 16:21:08 -0700 | [diff] [blame] | 51 | import java.util.Queue; |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 52 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 53 | /** |
Jae Seo | 9551e92 | 2014-08-05 19:06:47 -0700 | [diff] [blame] | 54 | * Displays TV contents. The TvView class provides a high level interface for applications to show |
| 55 | * TV programs from various TV sources that implement {@link TvInputService}. (Note that the list of |
| 56 | * TV inputs available on the system can be obtained by calling |
| 57 | * {@link TvInputManager#getTvInputList() TvInputManager.getTvInputList()}.) |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 58 | * |
| 59 | * <p>Once the application supplies the URI for a specific TV channel to {@link #tune(String, Uri)} |
Jae Seo | 9551e92 | 2014-08-05 19:06:47 -0700 | [diff] [blame] | 60 | * method, it takes care of underlying service binding (and unbinding if the current TvView is |
| 61 | * already bound to a service) and automatically allocates/deallocates resources needed. In addition |
| 62 | * to a few essential methods to control how the contents are presented, it also provides a way to |
| 63 | * dispatch input events to the connected TvInputService in order to enable custom key actions for |
| 64 | * the TV input. |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 65 | */ |
Jae Seo | 1bfce9f | 2014-06-03 23:58:49 -0700 | [diff] [blame] | 66 | public class TvView extends ViewGroup { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 67 | private static final String TAG = "TvView"; |
Jae Seo | ee2ec05 | 2014-09-14 10:30:05 -0700 | [diff] [blame] | 68 | private static final boolean DEBUG = false; |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 69 | |
Youngsang Cho | bf0a4eb | 2014-08-05 13:32:41 +0900 | [diff] [blame] | 70 | private static final int ZORDER_MEDIA = 0; |
| 71 | private static final int ZORDER_MEDIA_OVERLAY = 1; |
| 72 | private static final int ZORDER_ON_TOP = 2; |
| 73 | |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 74 | private static final WeakReference<TvView> NULL_TV_VIEW = new WeakReference<>(null); |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 75 | |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 76 | private static final Object sMainTvViewLock = new Object(); |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 77 | private static WeakReference<TvView> sMainTvView = NULL_TV_VIEW; |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 78 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 79 | private final Handler mHandler = new Handler(); |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 80 | private Session mSession; |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 81 | private SurfaceView mSurfaceView; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 82 | private Surface mSurface; |
| 83 | private boolean mOverlayViewCreated; |
| 84 | private Rect mOverlayViewFrame; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 85 | private final TvInputManager mTvInputManager; |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 86 | private MySessionCallback mSessionCallback; |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 87 | private TvInputCallback mCallback; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 88 | private OnUnhandledInputEventListener mOnUnhandledInputEventListener; |
Jae Seo | 1da8fb3 | 2015-04-21 10:50:59 -0700 | [diff] [blame] | 89 | private Float mStreamVolume; |
| 90 | private Boolean mCaptionEnabled; |
Jae Seo | 411d58d | 2015-04-22 16:21:08 -0700 | [diff] [blame] | 91 | private final Queue<Pair<String, Bundle>> mPendingAppPrivateCommands = new ArrayDeque<>(); |
Jae Seo | 887f521 | 2014-10-23 13:52:42 -0700 | [diff] [blame] | 92 | |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 93 | private boolean mSurfaceChanged; |
| 94 | private int mSurfaceFormat; |
| 95 | private int mSurfaceWidth; |
| 96 | private int mSurfaceHeight; |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 97 | private final AttributeSet mAttrs; |
| 98 | private final int mDefStyleAttr; |
Youngsang Cho | bf0a4eb | 2014-08-05 13:32:41 +0900 | [diff] [blame] | 99 | private int mWindowZOrder; |
Youngsang Cho | ff04ae7 | 2014-07-02 17:08:23 +0900 | [diff] [blame] | 100 | private boolean mUseRequestedSurfaceLayout; |
| 101 | private int mSurfaceViewLeft; |
| 102 | private int mSurfaceViewRight; |
| 103 | private int mSurfaceViewTop; |
| 104 | private int mSurfaceViewBottom; |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 105 | private TimeShiftPositionCallback mTimeShiftPositionCallback; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 106 | |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 107 | private final SurfaceHolder.Callback mSurfaceHolderCallback = new SurfaceHolder.Callback() { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 108 | @Override |
| 109 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 110 | if (DEBUG) { |
| 111 | Log.d(TAG, "surfaceChanged(holder=" + holder + ", format=" + format + ", width=" |
| 112 | + width + ", height=" + height + ")"); |
| 113 | } |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 114 | mSurfaceFormat = format; |
| 115 | mSurfaceWidth = width; |
| 116 | mSurfaceHeight = height; |
| 117 | mSurfaceChanged = true; |
| 118 | dispatchSurfaceChanged(mSurfaceFormat, mSurfaceWidth, mSurfaceHeight); |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void surfaceCreated(SurfaceHolder holder) { |
| 123 | mSurface = holder.getSurface(); |
| 124 | setSessionSurface(mSurface); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 129 | mSurface = null; |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 130 | mSurfaceChanged = false; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 131 | setSessionSurface(null); |
| 132 | } |
| 133 | }; |
| 134 | |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 135 | private final FinishedInputEventCallback mFinishedInputEventCallback = |
| 136 | new FinishedInputEventCallback() { |
| 137 | @Override |
| 138 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 139 | if (DEBUG) { |
| 140 | Log.d(TAG, "onFinishedInputEvent(token=" + token + ", handled=" + handled + ")"); |
| 141 | } |
| 142 | if (handled) { |
| 143 | return; |
| 144 | } |
| 145 | // TODO: Re-order unhandled events. |
| 146 | InputEvent event = (InputEvent) token; |
| 147 | if (dispatchUnhandledInputEvent(event)) { |
| 148 | return; |
| 149 | } |
Chulwoo Lee | c3e00c3 | 2014-05-14 11:31:51 +0900 | [diff] [blame] | 150 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 151 | if (viewRootImpl != null) { |
| 152 | viewRootImpl.dispatchUnhandledInputEvent(event); |
| 153 | } |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 154 | } |
| 155 | }; |
| 156 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 157 | public TvView(Context context) { |
| 158 | this(context, null, 0); |
| 159 | } |
| 160 | |
| 161 | public TvView(Context context, AttributeSet attrs) { |
| 162 | this(context, attrs, 0); |
| 163 | } |
| 164 | |
| 165 | public TvView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 166 | super(context, attrs, defStyleAttr); |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 167 | mAttrs = attrs; |
| 168 | mDefStyleAttr = defStyleAttr; |
| 169 | resetSurfaceView(); |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 170 | mTvInputManager = (TvInputManager) getContext().getSystemService(Context.TV_INPUT_SERVICE); |
| 171 | } |
| 172 | |
| 173 | /** |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 174 | * Sets the callback to be invoked when an event is dispatched to this TvView. |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 175 | * |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 176 | * @param callback The callback to receive events. A value of {@code null} removes the existing |
| 177 | * callback. |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 178 | */ |
Dongwon Kang | 4bf607b | 2015-04-23 19:44:59 +0900 | [diff] [blame] | 179 | public void setCallback(@Nullable TvInputCallback callback) { |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 180 | mCallback = callback; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 181 | } |
| 182 | |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 183 | /** |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 184 | * Sets this as the main {@link TvView}. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 185 | * |
| 186 | * <p>The main {@link TvView} is a {@link TvView} whose corresponding TV input determines the |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 187 | * HDMI-CEC active source device. For an HDMI port input, one of source devices that is |
| 188 | * connected to that HDMI port becomes the active source. For an HDMI-CEC logical device input, |
| 189 | * the corresponding HDMI-CEC logical device becomes the active source. For any non-HDMI input |
| 190 | * (including the tuner, composite, S-Video, etc.), the internal device (= TV itself) becomes |
| 191 | * the active source. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 192 | * |
| 193 | * <p>First tuned {@link TvView} becomes main automatically, and keeps to be main until either |
Jae Seo | 6e4cbfd | 2015-06-21 16:40:34 -0700 | [diff] [blame] | 194 | * {@link #reset} is called for the main {@link TvView} or {@code setMain()} is called for other |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 195 | * {@link TvView}. |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 196 | * @hide |
| 197 | */ |
| 198 | @SystemApi |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 199 | public void setMain() { |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 200 | synchronized (sMainTvViewLock) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 201 | sMainTvView = new WeakReference<>(this); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 202 | if (hasWindowFocus() && mSession != null) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 203 | mSession.setMain(); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /** |
Youngsang Cho | bf0a4eb | 2014-08-05 13:32:41 +0900 | [diff] [blame] | 209 | * Sets the Z order of a window owning the surface of this TvView above the normal TvView |
| 210 | * but below an application. |
| 211 | * |
| 212 | * @see SurfaceView#setZOrderMediaOverlay |
| 213 | * @hide |
| 214 | */ |
| 215 | @SystemApi |
| 216 | public void setZOrderMediaOverlay(boolean isMediaOverlay) { |
| 217 | if (isMediaOverlay) { |
| 218 | mWindowZOrder = ZORDER_MEDIA_OVERLAY; |
| 219 | removeSessionOverlayView(); |
| 220 | } else { |
| 221 | mWindowZOrder = ZORDER_MEDIA; |
| 222 | createSessionOverlayView(); |
| 223 | } |
| 224 | if (mSurfaceView != null) { |
| 225 | // ZOrderOnTop(false) removes WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
| 226 | // from WindowLayoutParam as well as changes window type. |
| 227 | mSurfaceView.setZOrderOnTop(false); |
| 228 | mSurfaceView.setZOrderMediaOverlay(isMediaOverlay); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Sets the Z order of a window owning the surface of this TvView on top of an application. |
| 234 | * |
| 235 | * @see SurfaceView#setZOrderOnTop |
| 236 | * @hide |
| 237 | */ |
| 238 | @SystemApi |
| 239 | public void setZOrderOnTop(boolean onTop) { |
| 240 | if (onTop) { |
| 241 | mWindowZOrder = ZORDER_ON_TOP; |
| 242 | removeSessionOverlayView(); |
| 243 | } else { |
| 244 | mWindowZOrder = ZORDER_MEDIA; |
| 245 | createSessionOverlayView(); |
| 246 | } |
| 247 | if (mSurfaceView != null) { |
| 248 | mSurfaceView.setZOrderMediaOverlay(false); |
| 249 | mSurfaceView.setZOrderOnTop(onTop); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /** |
Jae Seo | 1da8fb3 | 2015-04-21 10:50:59 -0700 | [diff] [blame] | 254 | * Sets the relative stream volume of this TvView. |
Jae Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 255 | * |
Jae Seo | 1da8fb3 | 2015-04-21 10:50:59 -0700 | [diff] [blame] | 256 | * <p>This method is primarily used to handle audio focus changes or mute a specific TvView when |
| 257 | * multiple views are displayed. If the method has not yet been called, the TvView assumes the |
| 258 | * default value of {@code 1.0f}. |
| 259 | * |
| 260 | * @param volume A volume value between {@code 0.0f} to {@code 1.0f}. |
Jae Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 261 | */ |
| 262 | public void setStreamVolume(float volume) { |
| 263 | if (DEBUG) Log.d(TAG, "setStreamVolume(" + volume + ")"); |
Dongwon Kang | 336cdf2 | 2014-06-08 18:20:55 +0900 | [diff] [blame] | 264 | mStreamVolume = volume; |
Jae Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 265 | if (mSession == null) { |
Dongwon Kang | 336cdf2 | 2014-06-08 18:20:55 +0900 | [diff] [blame] | 266 | // Volume will be set once the connection has been made. |
Jae Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 267 | return; |
| 268 | } |
| 269 | mSession.setStreamVolume(volume); |
| 270 | } |
| 271 | |
| 272 | /** |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 273 | * Tunes to a given channel. |
| 274 | * |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 275 | * @param inputId The ID of the TV input for the given channel. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 276 | * @param channelUri The URI of a channel. |
| 277 | */ |
Jae Seo | c8b7356 | 2015-04-23 10:53:58 -0700 | [diff] [blame] | 278 | public void tune(@NonNull String inputId, Uri channelUri) { |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 279 | tune(inputId, channelUri, null); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Tunes to a given channel. |
| 284 | * |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 285 | * @param inputId The ID of TV input for the given channel. |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 286 | * @param channelUri The URI of a channel. |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 287 | * @param params Extra parameters. |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 288 | * @hide |
| 289 | */ |
| 290 | @SystemApi |
| 291 | public void tune(String inputId, Uri channelUri, Bundle params) { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 292 | if (DEBUG) Log.d(TAG, "tune(" + channelUri + ")"); |
| 293 | if (TextUtils.isEmpty(inputId)) { |
| 294 | throw new IllegalArgumentException("inputId cannot be null or an empty string"); |
| 295 | } |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 296 | synchronized (sMainTvViewLock) { |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 297 | if (sMainTvView.get() == null) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 298 | sMainTvView = new WeakReference<>(this); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 299 | } |
| 300 | } |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 301 | if (mSessionCallback != null && TextUtils.equals(mSessionCallback.mInputId, inputId)) { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 302 | if (mSession != null) { |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 303 | mSession.tune(channelUri, params); |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 304 | } else { |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 305 | // createSession() was called but the actual session for the given inputId has not |
| 306 | // yet been created. Just replace the existing tuning params in the callback with |
| 307 | // the new ones and tune later in onSessionCreated(). It is not necessary to create |
| 308 | // a new callback because this tuning request was made on the same inputId. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 309 | mSessionCallback.mChannelUri = channelUri; |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 310 | mSessionCallback.mTuneParams = params; |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 311 | } |
| 312 | } else { |
Ji-Hwan Lee | d0f0058 | 2014-08-27 02:55:10 +0900 | [diff] [blame] | 313 | resetInternal(); |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 314 | // In case createSession() is called multiple times across different inputId's before |
| 315 | // any session is created (e.g. when quickly tuning to a channel from input A and then |
| 316 | // to another channel from input B), only the callback for the last createSession() |
| 317 | // should be invoked. (The previous callbacks are simply ignored.) To do that, we create |
| 318 | // a new callback each time and keep mSessionCallback pointing to the last one. If |
| 319 | // MySessionCallback.this is different from mSessionCallback, we know that this callback |
| 320 | // is obsolete and should ignore it. |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 321 | mSessionCallback = new MySessionCallback(inputId, channelUri, params); |
Jae Seo | 9127e45 | 2014-09-10 13:11:13 -0700 | [diff] [blame] | 322 | if (mTvInputManager != null) { |
| 323 | mTvInputManager.createSession(inputId, mSessionCallback, mHandler); |
| 324 | } |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Resets this TvView. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 330 | * |
| 331 | * <p>This method is primarily used to un-tune the current TvView. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 332 | */ |
| 333 | public void reset() { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 334 | if (DEBUG) Log.d(TAG, "reset()"); |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 335 | synchronized (sMainTvViewLock) { |
| 336 | if (this == sMainTvView.get()) { |
| 337 | sMainTvView = NULL_TV_VIEW; |
| 338 | } |
| 339 | } |
Ji-Hwan Lee | d0f0058 | 2014-08-27 02:55:10 +0900 | [diff] [blame] | 340 | resetInternal(); |
| 341 | } |
| 342 | |
| 343 | private void resetInternal() { |
Jae Seo | b1ae00e | 2015-06-23 02:39:36 -0700 | [diff] [blame] | 344 | mSessionCallback = null; |
Jae Seo | 1734507 | 2015-06-20 23:02:29 -0700 | [diff] [blame] | 345 | mPendingAppPrivateCommands.clear(); |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 346 | if (mSession != null) { |
Jae Seo | 1734507 | 2015-06-20 23:02:29 -0700 | [diff] [blame] | 347 | setSessionSurface(null); |
| 348 | removeSessionOverlayView(); |
| 349 | mUseRequestedSurfaceLayout = false; |
| 350 | mSession.release(); |
| 351 | mSession = null; |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 352 | resetSurfaceView(); |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | /** |
Sungsoo Lim | 9bf671f | 2014-07-19 12:59:51 +0900 | [diff] [blame] | 357 | * Requests to unblock TV content according to the given rating. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 358 | * |
| 359 | * <p>This notifies TV input that blocked content is now OK to play. |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 360 | * |
Sungsoo Lim | 9bf671f | 2014-07-19 12:59:51 +0900 | [diff] [blame] | 361 | * @param unblockedRating A TvContentRating to unblock. |
Jae Seo | 91a801d | 2014-07-24 13:49:03 -0700 | [diff] [blame] | 362 | * @see TvInputService.Session#notifyContentBlocked(TvContentRating) |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 363 | * @hide |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 364 | * @deprecated Use {@link #unblockContent} instead. |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 365 | */ |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 366 | @Deprecated |
Jae Seo | 15bbf3b | 2014-07-20 19:28:08 -0700 | [diff] [blame] | 367 | @SystemApi |
Sungsoo Lim | 9bf671f | 2014-07-19 12:59:51 +0900 | [diff] [blame] | 368 | public void requestUnblockContent(TvContentRating unblockedRating) { |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 369 | unblockContent(unblockedRating); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Requests to unblock TV content according to the given rating. |
| 374 | * |
| 375 | * <p>This notifies TV input that blocked content is now OK to play. |
| 376 | * |
| 377 | * @param unblockedRating A TvContentRating to unblock. |
| 378 | * @see TvInputService.Session#notifyContentBlocked(TvContentRating) |
| 379 | * @hide |
| 380 | */ |
| 381 | @SystemApi |
| 382 | public void unblockContent(TvContentRating unblockedRating) { |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 383 | if (mSession != null) { |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 384 | mSession.unblockContent(unblockedRating); |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | /** |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 389 | * Enables or disables the caption in this TvView. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 390 | * |
| 391 | * <p>Note that this method does not take any effect unless the current TvView is tuned. |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 392 | * |
| 393 | * @param enabled {@code true} to enable, {@code false} to disable. |
| 394 | */ |
| 395 | public void setCaptionEnabled(boolean enabled) { |
Jae Seo | 1da8fb3 | 2015-04-21 10:50:59 -0700 | [diff] [blame] | 396 | if (DEBUG) Log.d(TAG, "setCaptionEnabled(" + enabled + ")"); |
| 397 | mCaptionEnabled = enabled; |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 398 | if (mSession != null) { |
| 399 | mSession.setCaptionEnabled(enabled); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | /** |
Dongwon Kang | 1f81b10 | 2014-08-05 15:13:15 +0900 | [diff] [blame] | 404 | * Selects a track. |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 405 | * |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 406 | * @param type The type of the track to select. The type can be {@link TvTrackInfo#TYPE_AUDIO}, |
| 407 | * {@link TvTrackInfo#TYPE_VIDEO} or {@link TvTrackInfo#TYPE_SUBTITLE}. |
| 408 | * @param trackId The ID of the track to select. {@code null} means to unselect the current |
| 409 | * track for a given type. |
| 410 | * @see #getTracks |
| 411 | * @see #getSelectedTrack |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 412 | */ |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 413 | public void selectTrack(int type, String trackId) { |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 414 | if (mSession != null) { |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 415 | mSession.selectTrack(type, trackId); |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | /** |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 420 | * Returns the list of tracks. Returns {@code null} if the information is not available. |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 421 | * |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 422 | * @param type The type of the tracks. The type can be {@link TvTrackInfo#TYPE_AUDIO}, |
| 423 | * {@link TvTrackInfo#TYPE_VIDEO} or {@link TvTrackInfo#TYPE_SUBTITLE}. |
| 424 | * @see #selectTrack |
| 425 | * @see #getSelectedTrack |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 426 | */ |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 427 | public List<TvTrackInfo> getTracks(int type) { |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 428 | if (mSession == null) { |
| 429 | return null; |
| 430 | } |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 431 | return mSession.getTracks(type); |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 435 | * Returns the ID of the selected track for a given type. Returns {@code null} if the |
| 436 | * information is not available or the track is not selected. |
| 437 | * |
| 438 | * @param type The type of the selected tracks. The type can be {@link TvTrackInfo#TYPE_AUDIO}, |
| 439 | * {@link TvTrackInfo#TYPE_VIDEO} or {@link TvTrackInfo#TYPE_SUBTITLE}. |
| 440 | * @see #selectTrack |
| 441 | * @see #getTracks |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 442 | */ |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 443 | public String getSelectedTrack(int type) { |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 444 | if (mSession == null) { |
| 445 | return null; |
| 446 | } |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 447 | return mSession.getSelectedTrack(type); |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 451 | * Plays a given recorded TV program. |
| 452 | * |
| 453 | * @param inputId The ID of the TV input that created the given recorded program. |
| 454 | * @param recordedProgramUri The URI of a recorded program. |
| 455 | */ |
| 456 | public void timeShiftPlay(String inputId, Uri recordedProgramUri) { |
| 457 | if (DEBUG) Log.d(TAG, "timeShiftPlay(" + recordedProgramUri + ")"); |
| 458 | if (TextUtils.isEmpty(inputId)) { |
| 459 | throw new IllegalArgumentException("inputId cannot be null or an empty string"); |
| 460 | } |
| 461 | synchronized (sMainTvViewLock) { |
| 462 | if (sMainTvView.get() == null) { |
| 463 | sMainTvView = new WeakReference<>(this); |
| 464 | } |
| 465 | } |
| 466 | if (mSessionCallback != null && TextUtils.equals(mSessionCallback.mInputId, inputId)) { |
| 467 | if (mSession != null) { |
| 468 | mSession.timeShiftPlay(recordedProgramUri); |
| 469 | } else { |
| 470 | mSessionCallback.mRecordedProgramUri = recordedProgramUri; |
| 471 | } |
| 472 | } else { |
| 473 | resetInternal(); |
| 474 | mSessionCallback = new MySessionCallback(inputId, recordedProgramUri); |
| 475 | if (mTvInputManager != null) { |
| 476 | mTvInputManager.createSession(inputId, mSessionCallback, mHandler); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /** |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 482 | * Pauses playback. No-op if it is already paused. Call {@link #timeShiftResume} to resume. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 483 | */ |
| 484 | public void timeShiftPause() { |
| 485 | if (mSession != null) { |
| 486 | mSession.timeShiftPause(); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 491 | * Resumes playback. No-op if it is already resumed. Call {@link #timeShiftPause} to pause. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 492 | */ |
| 493 | public void timeShiftResume() { |
| 494 | if (mSession != null) { |
| 495 | mSession.timeShiftResume(); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | /** |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 500 | * Seeks to a specified time position. {@code timeMs} must be equal to or greater than the start |
| 501 | * position returned by {@link TimeShiftPositionCallback#onTimeShiftStartPositionChanged} and |
| 502 | * equal to or less than the current time. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 503 | * |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 504 | * @param timeMs The time position to seek to, in milliseconds since the epoch. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 505 | */ |
| 506 | public void timeShiftSeekTo(long timeMs) { |
| 507 | if (mSession != null) { |
| 508 | mSession.timeShiftSeekTo(timeMs); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | /** |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 513 | * Sets playback rate using {@link android.media.PlaybackParams}. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 514 | * |
Jae Seo | 3d04b76 | 2015-05-12 20:05:00 -0700 | [diff] [blame] | 515 | * @param params The playback params. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 516 | */ |
Jae Seo | 3d04b76 | 2015-05-12 20:05:00 -0700 | [diff] [blame] | 517 | public void timeShiftSetPlaybackParams(@NonNull PlaybackParams params) { |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 518 | if (mSession != null) { |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 519 | mSession.timeShiftSetPlaybackParams(params); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
| 523 | /** |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 524 | * Sets the callback to be invoked when the time shift position is changed. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 525 | * |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 526 | * @param callback The callback to receive time shift position changes. A value of {@code null} |
| 527 | * removes the existing callback. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 528 | */ |
Dongwon Kang | 4bf607b | 2015-04-23 19:44:59 +0900 | [diff] [blame] | 529 | public void setTimeShiftPositionCallback(@Nullable TimeShiftPositionCallback callback) { |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 530 | mTimeShiftPositionCallback = callback; |
| 531 | ensurePositionTracking(); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 534 | private void ensurePositionTracking() { |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 535 | if (mSession == null) { |
| 536 | return; |
| 537 | } |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 538 | mSession.timeShiftEnablePositionTracking(mTimeShiftPositionCallback != null); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
Jae Seo | e3c11e8 | 2016-02-08 23:18:49 -0800 | [diff] [blame] | 542 | * Calls {@link TvInputService.Session#appPrivateCommand(String, Bundle)} for the current |
| 543 | * session. |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 544 | * |
Jae Seo | 887f521 | 2014-10-23 13:52:42 -0700 | [diff] [blame] | 545 | * @param action The name of the private command to send. This <em>must</em> be a scoped name, |
| 546 | * i.e. prefixed with a package name you own, so that different developers will not |
| 547 | * create conflicting commands. |
| 548 | * @param data An optional bundle to send with the command. |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 549 | * @hide |
| 550 | */ |
| 551 | @SystemApi |
Jae Seo | c8b7356 | 2015-04-23 10:53:58 -0700 | [diff] [blame] | 552 | public void sendAppPrivateCommand(@NonNull String action, Bundle data) { |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 553 | if (TextUtils.isEmpty(action)) { |
| 554 | throw new IllegalArgumentException("action cannot be null or an empty string"); |
| 555 | } |
| 556 | if (mSession != null) { |
| 557 | mSession.sendAppPrivateCommand(action, data); |
Jae Seo | 887f521 | 2014-10-23 13:52:42 -0700 | [diff] [blame] | 558 | } else { |
Jae Seo | 411d58d | 2015-04-22 16:21:08 -0700 | [diff] [blame] | 559 | Log.w(TAG, "sendAppPrivateCommand - session not yet created (action \"" + action |
| 560 | + "\" pending)"); |
| 561 | mPendingAppPrivateCommands.add(Pair.create(action, data)); |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
| 565 | /** |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 566 | * Dispatches an unhandled input event to the next receiver. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 567 | * |
| 568 | * <p>Except system keys, TvView always consumes input events in the normal flow. This is called |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 569 | * asynchronously from where the event is dispatched. It gives the host application a chance to |
| 570 | * dispatch the unhandled input events. |
| 571 | * |
| 572 | * @param event The input event. |
| 573 | * @return {@code true} if the event was handled by the view, {@code false} otherwise. |
| 574 | */ |
| 575 | public boolean dispatchUnhandledInputEvent(InputEvent event) { |
| 576 | if (mOnUnhandledInputEventListener != null) { |
| 577 | if (mOnUnhandledInputEventListener.onUnhandledInputEvent(event)) { |
| 578 | return true; |
| 579 | } |
| 580 | } |
| 581 | return onUnhandledInputEvent(event); |
| 582 | } |
| 583 | |
| 584 | /** |
Dongwon Kang | 1f81b10 | 2014-08-05 15:13:15 +0900 | [diff] [blame] | 585 | * Called when an unhandled input event also has not been handled by the user provided |
| 586 | * callback. This is the last chance to handle the unhandled input event in the TvView. |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 587 | * |
| 588 | * @param event The input event. |
| 589 | * @return If you handled the event, return {@code true}. If you want to allow the event to be |
| 590 | * handled by the next receiver, return {@code false}. |
| 591 | */ |
| 592 | public boolean onUnhandledInputEvent(InputEvent event) { |
| 593 | return false; |
| 594 | } |
| 595 | |
| 596 | /** |
Dongwon Kang | 1f81b10 | 2014-08-05 15:13:15 +0900 | [diff] [blame] | 597 | * Registers a callback to be invoked when an input event is not handled by the bound TV input. |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 598 | * |
Dongwon Kang | 1f81b10 | 2014-08-05 15:13:15 +0900 | [diff] [blame] | 599 | * @param listener The callback to be invoked when the unhandled input event is received. |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 600 | */ |
| 601 | public void setOnUnhandledInputEventListener(OnUnhandledInputEventListener listener) { |
| 602 | mOnUnhandledInputEventListener = listener; |
| 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 607 | if (super.dispatchKeyEvent(event)) { |
| 608 | return true; |
| 609 | } |
| 610 | if (DEBUG) Log.d(TAG, "dispatchKeyEvent(" + event + ")"); |
| 611 | if (mSession == null) { |
| 612 | return false; |
| 613 | } |
Youngsang Cho | f982613 | 2014-05-13 01:34:49 +0900 | [diff] [blame] | 614 | InputEvent copiedEvent = event.copy(); |
| 615 | int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback, |
| 616 | mHandler); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 617 | return ret != Session.DISPATCH_NOT_HANDLED; |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public boolean dispatchTouchEvent(MotionEvent event) { |
| 622 | if (super.dispatchTouchEvent(event)) { |
| 623 | return true; |
| 624 | } |
| 625 | if (DEBUG) Log.d(TAG, "dispatchTouchEvent(" + event + ")"); |
| 626 | if (mSession == null) { |
| 627 | return false; |
| 628 | } |
Youngsang Cho | f982613 | 2014-05-13 01:34:49 +0900 | [diff] [blame] | 629 | InputEvent copiedEvent = event.copy(); |
| 630 | int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback, |
| 631 | mHandler); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 632 | return ret != Session.DISPATCH_NOT_HANDLED; |
| 633 | } |
| 634 | |
| 635 | @Override |
| 636 | public boolean dispatchTrackballEvent(MotionEvent event) { |
| 637 | if (super.dispatchTrackballEvent(event)) { |
| 638 | return true; |
| 639 | } |
| 640 | if (DEBUG) Log.d(TAG, "dispatchTrackballEvent(" + event + ")"); |
| 641 | if (mSession == null) { |
| 642 | return false; |
| 643 | } |
Youngsang Cho | f982613 | 2014-05-13 01:34:49 +0900 | [diff] [blame] | 644 | InputEvent copiedEvent = event.copy(); |
| 645 | int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback, |
| 646 | mHandler); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 647 | return ret != Session.DISPATCH_NOT_HANDLED; |
| 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
| 652 | if (super.dispatchGenericMotionEvent(event)) { |
| 653 | return true; |
| 654 | } |
| 655 | if (DEBUG) Log.d(TAG, "dispatchGenericMotionEvent(" + event + ")"); |
| 656 | if (mSession == null) { |
| 657 | return false; |
| 658 | } |
Youngsang Cho | f982613 | 2014-05-13 01:34:49 +0900 | [diff] [blame] | 659 | InputEvent copiedEvent = event.copy(); |
| 660 | int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback, |
| 661 | mHandler); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 662 | return ret != Session.DISPATCH_NOT_HANDLED; |
| 663 | } |
| 664 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 665 | @Override |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 666 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 667 | super.dispatchWindowFocusChanged(hasFocus); |
| 668 | // Other app may have shown its own main TvView. |
| 669 | // Set main again to regain main session. |
| 670 | synchronized (sMainTvViewLock) { |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 671 | if (hasFocus && this == sMainTvView.get() && mSession != null) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 672 | mSession.setMain(); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | @Override |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 678 | protected void onAttachedToWindow() { |
| 679 | super.onAttachedToWindow(); |
| 680 | createSessionOverlayView(); |
| 681 | } |
| 682 | |
| 683 | @Override |
| 684 | protected void onDetachedFromWindow() { |
| 685 | removeSessionOverlayView(); |
| 686 | super.onDetachedFromWindow(); |
| 687 | } |
| 688 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 689 | @Override |
Jae Seo | 1bfce9f | 2014-06-03 23:58:49 -0700 | [diff] [blame] | 690 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Youngsang Cho | ff04ae7 | 2014-07-02 17:08:23 +0900 | [diff] [blame] | 691 | if (DEBUG) { |
| 692 | Log.d(TAG, "onLayout (left=" + left + ", top=" + top + ", right=" + right |
| 693 | + ", bottom=" + bottom + ",)"); |
| 694 | } |
| 695 | if (mUseRequestedSurfaceLayout) { |
| 696 | mSurfaceView.layout(mSurfaceViewLeft, mSurfaceViewTop, mSurfaceViewRight, |
| 697 | mSurfaceViewBottom); |
| 698 | } else { |
| 699 | mSurfaceView.layout(0, 0, right - left, bottom - top); |
| 700 | } |
Jae Seo | 1bfce9f | 2014-06-03 23:58:49 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | @Override |
| 704 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 705 | mSurfaceView.measure(widthMeasureSpec, heightMeasureSpec); |
| 706 | int width = mSurfaceView.getMeasuredWidth(); |
| 707 | int height = mSurfaceView.getMeasuredHeight(); |
| 708 | int childState = mSurfaceView.getMeasuredState(); |
| 709 | setMeasuredDimension(resolveSizeAndState(width, widthMeasureSpec, childState), |
| 710 | resolveSizeAndState(height, heightMeasureSpec, |
| 711 | childState << MEASURED_HEIGHT_STATE_SHIFT)); |
| 712 | } |
| 713 | |
| 714 | @Override |
Dongwon Kang | 5f3cb4a | 2014-11-19 18:12:44 +0900 | [diff] [blame] | 715 | public boolean gatherTransparentRegion(Region region) { |
| 716 | if (mWindowZOrder != ZORDER_ON_TOP) { |
| 717 | if (region != null) { |
| 718 | int width = getWidth(); |
| 719 | int height = getHeight(); |
| 720 | if (width > 0 && height > 0) { |
| 721 | int location[] = new int[2]; |
| 722 | getLocationInWindow(location); |
| 723 | int left = location[0]; |
| 724 | int top = location[1]; |
| 725 | region.op(left, top, left + width, top + height, Region.Op.UNION); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | return super.gatherTransparentRegion(region); |
| 730 | } |
| 731 | |
| 732 | @Override |
| 733 | public void draw(Canvas canvas) { |
| 734 | if (mWindowZOrder != ZORDER_ON_TOP) { |
| 735 | // Punch a hole so that the underlying overlay view and surface can be shown. |
| 736 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 737 | } |
| 738 | super.draw(canvas); |
| 739 | } |
| 740 | |
| 741 | @Override |
| 742 | protected void dispatchDraw(Canvas canvas) { |
| 743 | if (mWindowZOrder != ZORDER_ON_TOP) { |
| 744 | // Punch a hole so that the underlying overlay view and surface can be shown. |
| 745 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 746 | } |
| 747 | super.dispatchDraw(canvas); |
| 748 | } |
| 749 | |
| 750 | @Override |
Christofer Ã…kersten | 6a1f264 | 2014-07-28 20:47:19 +0900 | [diff] [blame] | 751 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 752 | super.onVisibilityChanged(changedView, visibility); |
Jae Seo | 1bfce9f | 2014-06-03 23:58:49 -0700 | [diff] [blame] | 753 | mSurfaceView.setVisibility(visibility); |
Youngsang Cho | 07b7c5f | 2014-06-27 16:21:07 +0900 | [diff] [blame] | 754 | if (visibility == View.VISIBLE) { |
| 755 | createSessionOverlayView(); |
| 756 | } else { |
| 757 | removeSessionOverlayView(); |
| 758 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 759 | } |
| 760 | |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 761 | private void resetSurfaceView() { |
| 762 | if (mSurfaceView != null) { |
| 763 | mSurfaceView.getHolder().removeCallback(mSurfaceHolderCallback); |
| 764 | removeView(mSurfaceView); |
| 765 | } |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 766 | mSurface = null; |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 767 | mSurfaceView = new SurfaceView(getContext(), mAttrs, mDefStyleAttr) { |
| 768 | @Override |
| 769 | protected void updateWindow(boolean force, boolean redrawNeeded) { |
| 770 | super.updateWindow(force, redrawNeeded); |
| 771 | relayoutSessionOverlayView(); |
| 772 | }}; |
| 773 | mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback); |
Youngsang Cho | bf0a4eb | 2014-08-05 13:32:41 +0900 | [diff] [blame] | 774 | if (mWindowZOrder == ZORDER_MEDIA_OVERLAY) { |
| 775 | mSurfaceView.setZOrderMediaOverlay(true); |
| 776 | } else if (mWindowZOrder == ZORDER_ON_TOP) { |
| 777 | mSurfaceView.setZOrderOnTop(true); |
| 778 | } |
Youngsang Cho | 71b282f | 2014-07-28 17:10:29 +0900 | [diff] [blame] | 779 | addView(mSurfaceView); |
| 780 | } |
| 781 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 782 | private void setSessionSurface(Surface surface) { |
| 783 | if (mSession == null) { |
| 784 | return; |
| 785 | } |
| 786 | mSession.setSurface(surface); |
| 787 | } |
| 788 | |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 789 | private void dispatchSurfaceChanged(int format, int width, int height) { |
| 790 | if (mSession == null) { |
| 791 | return; |
| 792 | } |
| 793 | mSession.dispatchSurfaceChanged(format, width, height); |
| 794 | } |
| 795 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 796 | private void createSessionOverlayView() { |
| 797 | if (mSession == null || !isAttachedToWindow() |
Youngsang Cho | bf0a4eb | 2014-08-05 13:32:41 +0900 | [diff] [blame] | 798 | || mOverlayViewCreated || mWindowZOrder != ZORDER_MEDIA) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 799 | return; |
| 800 | } |
| 801 | mOverlayViewFrame = getViewFrameOnScreen(); |
| 802 | mSession.createOverlayView(this, mOverlayViewFrame); |
| 803 | mOverlayViewCreated = true; |
| 804 | } |
| 805 | |
| 806 | private void removeSessionOverlayView() { |
| 807 | if (mSession == null || !mOverlayViewCreated) { |
| 808 | return; |
| 809 | } |
| 810 | mSession.removeOverlayView(); |
| 811 | mOverlayViewCreated = false; |
| 812 | mOverlayViewFrame = null; |
| 813 | } |
| 814 | |
| 815 | private void relayoutSessionOverlayView() { |
Youngsang Cho | bf0a4eb | 2014-08-05 13:32:41 +0900 | [diff] [blame] | 816 | if (mSession == null || !isAttachedToWindow() || !mOverlayViewCreated |
| 817 | || mWindowZOrder != ZORDER_MEDIA) { |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 818 | return; |
| 819 | } |
| 820 | Rect viewFrame = getViewFrameOnScreen(); |
| 821 | if (viewFrame.equals(mOverlayViewFrame)) { |
| 822 | return; |
| 823 | } |
| 824 | mSession.relayoutOverlayView(viewFrame); |
| 825 | mOverlayViewFrame = viewFrame; |
| 826 | } |
| 827 | |
| 828 | private Rect getViewFrameOnScreen() { |
| 829 | int[] location = new int[2]; |
| 830 | getLocationOnScreen(location); |
| 831 | return new Rect(location[0], location[1], |
| 832 | location[0] + getWidth(), location[1] + getHeight()); |
| 833 | } |
| 834 | |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 835 | /** |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 836 | * Callback used to receive time shift position changes. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 837 | */ |
| 838 | public abstract static class TimeShiftPositionCallback { |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 839 | |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 840 | /** |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 841 | * This is called when the start playback position is changed. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 842 | * |
| 843 | * <p>The start playback position of the time shifted program can be adjusted by the TV |
| 844 | * input when it cannot retain the whole recorded program due to some reason (e.g. |
| 845 | * limitation on storage space). The application should not allow the user to seek to a |
| 846 | * position earlier than the start position. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 847 | * |
Jae Seo | 3d04b76 | 2015-05-12 20:05:00 -0700 | [diff] [blame] | 848 | * <p>Note that {@code timeMs} is not relative time in the program but wall-clock time, |
| 849 | * which is intended to avoid calling this method unnecessarily around program boundaries. |
| 850 | * |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 851 | * @param inputId The ID of the TV input bound to this view. |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 852 | * @param timeMs The start playback position of the time shifted program, in milliseconds |
| 853 | * since the epoch. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 854 | */ |
| 855 | public void onTimeShiftStartPositionChanged(String inputId, long timeMs) { |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * This is called when the current playback position is changed. |
| 860 | * |
Jae Seo | 3d04b76 | 2015-05-12 20:05:00 -0700 | [diff] [blame] | 861 | * <p>Note that {@code timeMs} is not relative time in the program but wall-clock time, |
| 862 | * which is intended to avoid calling this method unnecessarily around program boundaries. |
| 863 | * |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 864 | * @param inputId The ID of the TV input bound to this view. |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 865 | * @param timeMs The current playback position of the time shifted program, in milliseconds |
| 866 | * since the epoch. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 867 | */ |
| 868 | public void onTimeShiftCurrentPositionChanged(String inputId, long timeMs) { |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /** |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 873 | * Callback used to receive various status updates on the {@link TvView}. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 874 | */ |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 875 | public abstract static class TvInputCallback { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 876 | |
| 877 | /** |
Jae Seo | 1553a52 | 2014-08-18 23:14:12 -0700 | [diff] [blame] | 878 | * This is invoked when an error occurred while establishing a connection to the underlying |
| 879 | * TV input. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 880 | * |
| 881 | * @param inputId The ID of the TV input bound to this view. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 882 | */ |
Jae Seo | 1553a52 | 2014-08-18 23:14:12 -0700 | [diff] [blame] | 883 | public void onConnectionFailed(String inputId) { |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * This is invoked when the existing connection to the underlying TV input is lost. |
| 888 | * |
| 889 | * @param inputId The ID of the TV input bound to this view. |
| 890 | */ |
| 891 | public void onDisconnected(String inputId) { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /** |
Dongwon Kang | b93ccca | 2014-06-26 17:59:27 +0900 | [diff] [blame] | 895 | * This is invoked when the channel of this TvView is changed by the underlying TV input |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 896 | * without any {@link TvView#tune(String, Uri)} request. |
Dongwon Kang | b93ccca | 2014-06-26 17:59:27 +0900 | [diff] [blame] | 897 | * |
| 898 | * @param inputId The ID of the TV input bound to this view. |
| 899 | * @param channelUri The URI of a channel. |
| 900 | */ |
| 901 | public void onChannelRetuned(String inputId, Uri channelUri) { |
| 902 | } |
| 903 | |
| 904 | /** |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 905 | * This is called when the track information has been changed. |
| 906 | * |
| 907 | * @param inputId The ID of the TV input bound to this view. |
| 908 | * @param tracks A list which includes track information. |
| 909 | */ |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 910 | public void onTracksChanged(String inputId, List<TvTrackInfo> tracks) { |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /** |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 914 | * This is called when there is a change on the selected tracks. |
| 915 | * |
| 916 | * @param inputId The ID of the TV input bound to this view. |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 917 | * @param type The type of the track selected. The type can be |
| 918 | * {@link TvTrackInfo#TYPE_AUDIO}, {@link TvTrackInfo#TYPE_VIDEO} or |
| 919 | * {@link TvTrackInfo#TYPE_SUBTITLE}. |
| 920 | * @param trackId The ID of the track selected. |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 921 | */ |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 922 | public void onTrackSelected(String inputId, int type, String trackId) { |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | /** |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 926 | * This is invoked when the video size has been changed. It is also called when the first |
| 927 | * time video size information becomes available after this view is tuned to a specific |
| 928 | * channel. |
| 929 | * |
| 930 | * @param inputId The ID of the TV input bound to this view. |
| 931 | * @param width The width of the video. |
| 932 | * @param height The height of the video. |
| 933 | */ |
| 934 | public void onVideoSizeChanged(String inputId, int width, int height) { |
| 935 | } |
| 936 | |
| 937 | /** |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 938 | * This is called when the video is available, so the TV input starts the playback. |
| 939 | * |
| 940 | * @param inputId The ID of the TV input bound to this view. |
| 941 | */ |
| 942 | public void onVideoAvailable(String inputId) { |
| 943 | } |
| 944 | |
| 945 | /** |
| 946 | * This is called when the video is not available, so the TV input stops the playback. |
| 947 | * |
| 948 | * @param inputId The ID of the TV input bound to this view. |
| 949 | * @param reason The reason why the TV input stopped the playback: |
| 950 | * <ul> |
| 951 | * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN} |
Jae Seo | 6e62a15 | 2014-07-29 17:25:47 +0900 | [diff] [blame] | 952 | * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNING} |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 953 | * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL} |
| 954 | * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING} |
Dongwon Kang | ff1f29e | 2015-04-07 17:31:16 -0700 | [diff] [blame] | 955 | * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY} |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 956 | * </ul> |
| 957 | */ |
| 958 | public void onVideoUnavailable(String inputId, int reason) { |
| 959 | } |
| 960 | |
| 961 | /** |
Jae Seo | bbcd206 | 2014-07-18 16:12:38 -0700 | [diff] [blame] | 962 | * This is called when the current program content turns out to be allowed to watch since |
| 963 | * its content rating is not blocked by parental controls. |
| 964 | * |
| 965 | * @param inputId The ID of the TV input bound to this view. |
| 966 | */ |
| 967 | public void onContentAllowed(String inputId) { |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * This is called when the current program content turns out to be not allowed to watch |
| 972 | * since its content rating is blocked by parental controls. |
Jae Seo | 6057102 | 2014-07-14 16:07:19 -0700 | [diff] [blame] | 973 | * |
| 974 | * @param inputId The ID of the TV input bound to this view. |
| 975 | * @param rating The content rating of the blocked program. |
| 976 | */ |
| 977 | public void onContentBlocked(String inputId, TvContentRating rating) { |
| 978 | } |
| 979 | |
| 980 | /** |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 981 | * This is invoked when a custom event from the bound TV input is sent to this view. |
| 982 | * |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 983 | * @param inputId The ID of the TV input bound to this view. |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 984 | * @param eventType The type of the event. |
| 985 | * @param eventArgs Optional arguments of the event. |
| 986 | * @hide |
| 987 | */ |
Jae Seo | 15bbf3b | 2014-07-20 19:28:08 -0700 | [diff] [blame] | 988 | @SystemApi |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 989 | public void onEvent(String inputId, String eventType, Bundle eventArgs) { |
| 990 | } |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 991 | |
| 992 | /** |
| 993 | * This is called when the time shift status is changed. |
| 994 | * |
| 995 | * @param inputId The ID of the TV input bound to this view. |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 996 | * @param status The current time shift status. Should be one of the followings. |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 997 | * <ul> |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 998 | * <li>{@link TvInputManager#TIME_SHIFT_STATUS_UNSUPPORTED} |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 999 | * <li>{@link TvInputManager#TIME_SHIFT_STATUS_UNAVAILABLE} |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1000 | * <li>{@link TvInputManager#TIME_SHIFT_STATUS_AVAILABLE} |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1001 | * </ul> |
| 1002 | */ |
| 1003 | public void onTimeShiftStatusChanged(String inputId, int status) { |
| 1004 | } |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /** |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 1008 | * Interface definition for a callback to be invoked when the unhandled input event is received. |
| 1009 | */ |
| 1010 | public interface OnUnhandledInputEventListener { |
| 1011 | /** |
| 1012 | * Called when an input event was not handled by the bound TV input. |
Dongwon Kang | 0610e12 | 2015-04-23 17:01:17 +0900 | [diff] [blame] | 1013 | * |
| 1014 | * <p>This is called asynchronously from where the event is dispatched. It gives the host |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 1015 | * application a chance to handle the unhandled input events. |
| 1016 | * |
| 1017 | * @param event The input event. |
| 1018 | * @return If you handled the event, return {@code true}. If you want to allow the event to |
| 1019 | * be handled by the next receiver, return {@code false}. |
| 1020 | */ |
| 1021 | boolean onUnhandledInputEvent(InputEvent event); |
| 1022 | } |
| 1023 | |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1024 | private class MySessionCallback extends SessionCallback { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 1025 | final String mInputId; |
| 1026 | Uri mChannelUri; |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 1027 | Bundle mTuneParams; |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1028 | Uri mRecordedProgramUri; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1029 | |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 1030 | MySessionCallback(String inputId, Uri channelUri, Bundle tuneParams) { |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 1031 | mInputId = inputId; |
| 1032 | mChannelUri = channelUri; |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 1033 | mTuneParams = tuneParams; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1034 | } |
| 1035 | |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1036 | MySessionCallback(String inputId, Uri recordedProgramUri) { |
| 1037 | mInputId = inputId; |
| 1038 | mRecordedProgramUri = recordedProgramUri; |
| 1039 | } |
| 1040 | |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1041 | @Override |
| 1042 | public void onSessionCreated(Session session) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1043 | if (DEBUG) { |
| 1044 | Log.d(TAG, "onSessionCreated()"); |
| 1045 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1046 | if (this != mSessionCallback) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1047 | Log.w(TAG, "onSessionCreated - session already created"); |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1048 | // This callback is obsolete. |
Youngsang Cho | c31c450 | 2014-05-13 21:13:47 +0900 | [diff] [blame] | 1049 | if (session != null) { |
| 1050 | session.release(); |
| 1051 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1052 | return; |
| 1053 | } |
| 1054 | mSession = session; |
| 1055 | if (session != null) { |
Jae Seo | 411d58d | 2015-04-22 16:21:08 -0700 | [diff] [blame] | 1056 | // Sends the pending app private commands first. |
| 1057 | for (Pair<String, Bundle> command : mPendingAppPrivateCommands) { |
| 1058 | mSession.sendAppPrivateCommand(command.first, command.second); |
| 1059 | } |
| 1060 | mPendingAppPrivateCommands.clear(); |
| 1061 | |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1062 | synchronized (sMainTvViewLock) { |
Ji-Hwan Lee | c7f440d | 2014-08-21 17:53:15 +0900 | [diff] [blame] | 1063 | if (hasWindowFocus() && TvView.this == sMainTvView.get()) { |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 1064 | mSession.setMain(); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 1065 | } |
| 1066 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1067 | // mSurface may not be ready yet as soon as starting an application. |
| 1068 | // In the case, we don't send Session.setSurface(null) unnecessarily. |
| 1069 | // setSessionSurface will be called in surfaceCreated. |
| 1070 | if (mSurface != null) { |
| 1071 | setSessionSurface(mSurface); |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1072 | if (mSurfaceChanged) { |
| 1073 | dispatchSurfaceChanged(mSurfaceFormat, mSurfaceWidth, mSurfaceHeight); |
| 1074 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1075 | } |
| 1076 | createSessionOverlayView(); |
Jae Seo | 1da8fb3 | 2015-04-21 10:50:59 -0700 | [diff] [blame] | 1077 | if (mStreamVolume != null) { |
Dongwon Kang | 336cdf2 | 2014-06-08 18:20:55 +0900 | [diff] [blame] | 1078 | mSession.setStreamVolume(mStreamVolume); |
| 1079 | } |
Jae Seo | 1da8fb3 | 2015-04-21 10:50:59 -0700 | [diff] [blame] | 1080 | if (mCaptionEnabled != null) { |
| 1081 | mSession.setCaptionEnabled(mCaptionEnabled); |
| 1082 | } |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 1083 | if (mChannelUri != null) { |
| 1084 | mSession.tune(mChannelUri, mTuneParams); |
| 1085 | } else { |
| 1086 | mSession.timeShiftPlay(mRecordedProgramUri); |
| 1087 | } |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1088 | ensurePositionTracking(); |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 1089 | } else { |
Youngsang Cho | 7cf6705 | 2014-08-26 23:12:59 +0900 | [diff] [blame] | 1090 | mSessionCallback = null; |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1091 | if (mCallback != null) { |
| 1092 | mCallback.onConnectionFailed(mInputId); |
Jae Seo | b8a6441 | 2014-06-03 15:34:50 -0700 | [diff] [blame] | 1093 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1094 | } |
| 1095 | } |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1096 | |
| 1097 | @Override |
| 1098 | public void onSessionReleased(Session session) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1099 | if (DEBUG) { |
| 1100 | Log.d(TAG, "onSessionReleased()"); |
| 1101 | } |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1102 | if (this != mSessionCallback) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1103 | Log.w(TAG, "onSessionReleased - session not created"); |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1104 | return; |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1105 | } |
Chulwoo Lee | ffad70b | 2014-08-26 19:07:22 +0900 | [diff] [blame] | 1106 | mOverlayViewCreated = false; |
| 1107 | mOverlayViewFrame = null; |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1108 | mSessionCallback = null; |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1109 | mSession = null; |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1110 | if (mCallback != null) { |
| 1111 | mCallback.onDisconnected(mInputId); |
Sungsoo Lim | 2b35a72 | 2014-04-17 17:09:15 +0900 | [diff] [blame] | 1112 | } |
| 1113 | } |
Youngsang Cho | 832860f | 2014-05-21 20:54:03 +0900 | [diff] [blame] | 1114 | |
| 1115 | @Override |
Dongwon Kang | b93ccca | 2014-06-26 17:59:27 +0900 | [diff] [blame] | 1116 | public void onChannelRetuned(Session session, Uri channelUri) { |
| 1117 | if (DEBUG) { |
| 1118 | Log.d(TAG, "onChannelChangedByTvInput(" + channelUri + ")"); |
| 1119 | } |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1120 | if (this != mSessionCallback) { |
| 1121 | Log.w(TAG, "onChannelRetuned - session not created"); |
| 1122 | return; |
| 1123 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1124 | if (mCallback != null) { |
| 1125 | mCallback.onChannelRetuned(mInputId, channelUri); |
Dongwon Kang | b93ccca | 2014-06-26 17:59:27 +0900 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | @Override |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 1130 | public void onTracksChanged(Session session, List<TvTrackInfo> tracks) { |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1131 | if (DEBUG) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1132 | Log.d(TAG, "onTracksChanged(" + tracks + ")"); |
| 1133 | } |
| 1134 | if (this != mSessionCallback) { |
| 1135 | Log.w(TAG, "onTracksChanged - session not created"); |
| 1136 | return; |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1137 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1138 | if (mCallback != null) { |
| 1139 | mCallback.onTracksChanged(mInputId, tracks); |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
Jae Seo | 6057102 | 2014-07-14 16:07:19 -0700 | [diff] [blame] | 1143 | @Override |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 1144 | public void onTrackSelected(Session session, int type, String trackId) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1145 | if (DEBUG) { |
| 1146 | Log.d(TAG, "onTrackSelected(type=" + type + ", trackId=" + trackId + ")"); |
| 1147 | } |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 1148 | if (this != mSessionCallback) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1149 | Log.w(TAG, "onTrackSelected - session not created"); |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 1150 | return; |
| 1151 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1152 | if (mCallback != null) { |
| 1153 | mCallback.onTrackSelected(mInputId, type, trackId); |
Jae Seo | d5ce975 | 2014-07-24 15:54:23 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | @Override |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1158 | public void onVideoSizeChanged(Session session, int width, int height) { |
| 1159 | if (DEBUG) { |
| 1160 | Log.d(TAG, "onVideoSizeChanged()"); |
| 1161 | } |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1162 | if (this != mSessionCallback) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1163 | Log.w(TAG, "onVideoSizeChanged - session not created"); |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 1164 | return; |
| 1165 | } |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1166 | if (mCallback != null) { |
| 1167 | mCallback.onVideoSizeChanged(mInputId, width, height); |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | @Override |
| 1172 | public void onVideoAvailable(Session session) { |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 1173 | if (DEBUG) { |
| 1174 | Log.d(TAG, "onVideoAvailable()"); |
| 1175 | } |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1176 | if (this != mSessionCallback) { |
| 1177 | Log.w(TAG, "onVideoAvailable - session not created"); |
| 1178 | return; |
| 1179 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1180 | if (mCallback != null) { |
| 1181 | mCallback.onVideoAvailable(mInputId); |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
Jae Seo | 6057102 | 2014-07-14 16:07:19 -0700 | [diff] [blame] | 1185 | @Override |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 1186 | public void onVideoUnavailable(Session session, int reason) { |
| 1187 | if (DEBUG) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1188 | Log.d(TAG, "onVideoUnavailable(reason=" + reason + ")"); |
| 1189 | } |
| 1190 | if (this != mSessionCallback) { |
| 1191 | Log.w(TAG, "onVideoUnavailable - session not created"); |
| 1192 | return; |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 1193 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1194 | if (mCallback != null) { |
| 1195 | mCallback.onVideoUnavailable(mInputId, reason); |
Dongwon Kang | 9b08edf | 2014-07-04 09:32:40 +0900 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 1199 | @Override |
Jae Seo | bbcd206 | 2014-07-18 16:12:38 -0700 | [diff] [blame] | 1200 | public void onContentAllowed(Session session) { |
Jae Seo | bbcd206 | 2014-07-18 16:12:38 -0700 | [diff] [blame] | 1201 | if (DEBUG) { |
| 1202 | Log.d(TAG, "onContentAllowed()"); |
| 1203 | } |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1204 | if (this != mSessionCallback) { |
| 1205 | Log.w(TAG, "onContentAllowed - session not created"); |
| 1206 | return; |
| 1207 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1208 | if (mCallback != null) { |
| 1209 | mCallback.onContentAllowed(mInputId); |
Jae Seo | bbcd206 | 2014-07-18 16:12:38 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | @Override |
Jae Seo | 6057102 | 2014-07-14 16:07:19 -0700 | [diff] [blame] | 1214 | public void onContentBlocked(Session session, TvContentRating rating) { |
| 1215 | if (DEBUG) { |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1216 | Log.d(TAG, "onContentBlocked(rating=" + rating + ")"); |
| 1217 | } |
| 1218 | if (this != mSessionCallback) { |
| 1219 | Log.w(TAG, "onContentBlocked - session not created"); |
| 1220 | return; |
Jae Seo | 6057102 | 2014-07-14 16:07:19 -0700 | [diff] [blame] | 1221 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1222 | if (mCallback != null) { |
| 1223 | mCallback.onContentBlocked(mInputId, rating); |
Jae Seo | 6057102 | 2014-07-14 16:07:19 -0700 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | |
Jae Seo | bbcd206 | 2014-07-18 16:12:38 -0700 | [diff] [blame] | 1227 | @Override |
Youngsang Cho | ff04ae7 | 2014-07-02 17:08:23 +0900 | [diff] [blame] | 1228 | public void onLayoutSurface(Session session, int left, int top, int right, int bottom) { |
| 1229 | if (DEBUG) { |
| 1230 | Log.d(TAG, "onLayoutSurface (left=" + left + ", top=" + top + ", right=" |
| 1231 | + right + ", bottom=" + bottom + ",)"); |
| 1232 | } |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1233 | if (this != mSessionCallback) { |
| 1234 | Log.w(TAG, "onLayoutSurface - session not created"); |
| 1235 | return; |
| 1236 | } |
Youngsang Cho | ff04ae7 | 2014-07-02 17:08:23 +0900 | [diff] [blame] | 1237 | mSurfaceViewLeft = left; |
| 1238 | mSurfaceViewTop = top; |
| 1239 | mSurfaceViewRight = right; |
| 1240 | mSurfaceViewBottom = bottom; |
| 1241 | mUseRequestedSurfaceLayout = true; |
| 1242 | requestLayout(); |
| 1243 | } |
| 1244 | |
| 1245 | @Override |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 1246 | public void onSessionEvent(Session session, String eventType, Bundle eventArgs) { |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 1247 | if (DEBUG) { |
| 1248 | Log.d(TAG, "onSessionEvent(" + eventType + ")"); |
| 1249 | } |
Jae Seo | 6320fc4 | 2014-10-21 16:17:25 -0700 | [diff] [blame] | 1250 | if (this != mSessionCallback) { |
| 1251 | Log.w(TAG, "onSessionEvent - session not created"); |
| 1252 | return; |
| 1253 | } |
Jae Seo | 2778f5a | 2014-09-04 14:37:09 -0700 | [diff] [blame] | 1254 | if (mCallback != null) { |
| 1255 | mCallback.onEvent(mInputId, eventType, eventArgs); |
Youngsang Cho | 832860f | 2014-05-21 20:54:03 +0900 | [diff] [blame] | 1256 | } |
| 1257 | } |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1258 | |
| 1259 | @Override |
| 1260 | public void onTimeShiftStatusChanged(Session session, int status) { |
| 1261 | if (DEBUG) { |
| 1262 | Log.d(TAG, "onTimeShiftStatusChanged()"); |
| 1263 | } |
| 1264 | if (this != mSessionCallback) { |
| 1265 | Log.w(TAG, "onTimeShiftStatusChanged - session not created"); |
| 1266 | return; |
| 1267 | } |
| 1268 | if (mCallback != null) { |
| 1269 | mCallback.onTimeShiftStatusChanged(mInputId, status); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | @Override |
| 1274 | public void onTimeShiftStartPositionChanged(Session session, long timeMs) { |
| 1275 | if (DEBUG) { |
| 1276 | Log.d(TAG, "onTimeShiftStartPositionChanged()"); |
| 1277 | } |
| 1278 | if (this != mSessionCallback) { |
| 1279 | Log.w(TAG, "onTimeShiftStartPositionChanged - session not created"); |
| 1280 | return; |
| 1281 | } |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1282 | if (mTimeShiftPositionCallback != null) { |
| 1283 | mTimeShiftPositionCallback.onTimeShiftStartPositionChanged(mInputId, timeMs); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | @Override |
| 1288 | public void onTimeShiftCurrentPositionChanged(Session session, long timeMs) { |
| 1289 | if (DEBUG) { |
| 1290 | Log.d(TAG, "onTimeShiftCurrentPositionChanged()"); |
| 1291 | } |
| 1292 | if (this != mSessionCallback) { |
| 1293 | Log.w(TAG, "onTimeShiftCurrentPositionChanged - session not created"); |
| 1294 | return; |
| 1295 | } |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 1296 | if (mTimeShiftPositionCallback != null) { |
| 1297 | mTimeShiftPositionCallback.onTimeShiftCurrentPositionChanged(mInputId, timeMs); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 1298 | } |
| 1299 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 1300 | } |
| 1301 | } |