Methods Summary |
---|
private void | createSessionOverlayView()
if (mSession == null || !isAttachedToWindow()
|| mOverlayViewCreated || mWindowZOrder != ZORDER_MEDIA) {
return;
}
mOverlayViewFrame = getViewFrameOnScreen();
mSession.createOverlayView(this, mOverlayViewFrame);
mOverlayViewCreated = true;
|
protected void | dispatchDraw(android.graphics.Canvas canvas)
if (mWindowZOrder != ZORDER_ON_TOP) {
// Punch a hole so that the underlying overlay view and surface can be shown.
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
}
super.dispatchDraw(canvas);
|
public boolean | dispatchGenericMotionEvent(android.view.MotionEvent event)
if (super.dispatchGenericMotionEvent(event)) {
return true;
}
if (DEBUG) Log.d(TAG, "dispatchGenericMotionEvent(" + event + ")");
if (mSession == null) {
return false;
}
InputEvent copiedEvent = event.copy();
int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback,
mHandler);
return ret != Session.DISPATCH_NOT_HANDLED;
|
public boolean | dispatchKeyEvent(android.view.KeyEvent event)
if (super.dispatchKeyEvent(event)) {
return true;
}
if (DEBUG) Log.d(TAG, "dispatchKeyEvent(" + event + ")");
if (mSession == null) {
return false;
}
InputEvent copiedEvent = event.copy();
int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback,
mHandler);
return ret != Session.DISPATCH_NOT_HANDLED;
|
private void | dispatchSurfaceChanged(int format, int width, int height)
if (mSession == null) {
return;
}
mSession.dispatchSurfaceChanged(format, width, height);
|
public boolean | dispatchTouchEvent(android.view.MotionEvent event)
if (super.dispatchTouchEvent(event)) {
return true;
}
if (DEBUG) Log.d(TAG, "dispatchTouchEvent(" + event + ")");
if (mSession == null) {
return false;
}
InputEvent copiedEvent = event.copy();
int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback,
mHandler);
return ret != Session.DISPATCH_NOT_HANDLED;
|
public boolean | dispatchTrackballEvent(android.view.MotionEvent event)
if (super.dispatchTrackballEvent(event)) {
return true;
}
if (DEBUG) Log.d(TAG, "dispatchTrackballEvent(" + event + ")");
if (mSession == null) {
return false;
}
InputEvent copiedEvent = event.copy();
int ret = mSession.dispatchInputEvent(copiedEvent, copiedEvent, mFinishedInputEventCallback,
mHandler);
return ret != Session.DISPATCH_NOT_HANDLED;
|
public boolean | dispatchUnhandledInputEvent(android.view.InputEvent event)Dispatches an unhandled input event to the next receiver.
Except system keys, TvView always consumes input events in the normal flow. This is called
asynchronously from where the event is dispatched. It gives the host application a chance to
dispatch the unhandled input events.
if (mOnUnhandledInputEventListener != null) {
if (mOnUnhandledInputEventListener.onUnhandledInputEvent(event)) {
return true;
}
}
return onUnhandledInputEvent(event);
|
public void | dispatchWindowFocusChanged(boolean hasFocus)
super.dispatchWindowFocusChanged(hasFocus);
// Other app may have shown its own main TvView.
// Set main again to regain main session.
synchronized (sMainTvViewLock) {
if (hasFocus && this == sMainTvView.get() && mSession != null) {
mSession.setMain();
}
}
|
public void | draw(android.graphics.Canvas canvas)
if (mWindowZOrder != ZORDER_ON_TOP) {
// Punch a hole so that the underlying overlay view and surface can be shown.
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
}
super.draw(canvas);
|
public boolean | gatherTransparentRegion(android.graphics.Region region)
if (mWindowZOrder != ZORDER_ON_TOP) {
if (region != null) {
int width = getWidth();
int height = getHeight();
if (width > 0 && height > 0) {
int location[] = new int[2];
getLocationInWindow(location);
int left = location[0];
int top = location[1];
region.op(left, top, left + width, top + height, Region.Op.UNION);
}
}
}
return super.gatherTransparentRegion(region);
|
public java.lang.String | getSelectedTrack(int type)Returns the ID of the selected track for a given type. Returns {@code null} if the
information is not available or the track is not selected.
if (mSession == null) {
return null;
}
return mSession.getSelectedTrack(type);
|
public java.util.List | getTracks(int type)Returns the list of tracks. Returns {@code null} if the information is not available.
if (mSession == null) {
return null;
}
return mSession.getTracks(type);
|
private android.graphics.Rect | getViewFrameOnScreen()
int[] location = new int[2];
getLocationOnScreen(location);
return new Rect(location[0], location[1],
location[0] + getWidth(), location[1] + getHeight());
|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
createSessionOverlayView();
|
protected void | onDetachedFromWindow()
removeSessionOverlayView();
super.onDetachedFromWindow();
|
protected void | onLayout(boolean changed, int left, int top, int right, int bottom)
if (DEBUG) {
Log.d(TAG, "onLayout (left=" + left + ", top=" + top + ", right=" + right
+ ", bottom=" + bottom + ",)");
}
if (mUseRequestedSurfaceLayout) {
mSurfaceView.layout(mSurfaceViewLeft, mSurfaceViewTop, mSurfaceViewRight,
mSurfaceViewBottom);
} else {
mSurfaceView.layout(0, 0, right - left, bottom - top);
}
|
protected void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
mSurfaceView.measure(widthMeasureSpec, heightMeasureSpec);
int width = mSurfaceView.getMeasuredWidth();
int height = mSurfaceView.getMeasuredHeight();
int childState = mSurfaceView.getMeasuredState();
setMeasuredDimension(resolveSizeAndState(width, widthMeasureSpec, childState),
resolveSizeAndState(height, heightMeasureSpec,
childState << MEASURED_HEIGHT_STATE_SHIFT));
|
public boolean | onUnhandledInputEvent(android.view.InputEvent event)Called when an unhandled input event also has not been handled by the user provided
callback. This is the last chance to handle the unhandled input event in the TvView.
return false;
|
protected void | onVisibilityChanged(android.view.View changedView, int visibility)
super.onVisibilityChanged(changedView, visibility);
mSurfaceView.setVisibility(visibility);
if (visibility == View.VISIBLE) {
createSessionOverlayView();
} else {
removeSessionOverlayView();
}
|
private void | relayoutSessionOverlayView()
if (mSession == null || !isAttachedToWindow() || !mOverlayViewCreated
|| mWindowZOrder != ZORDER_MEDIA) {
return;
}
Rect viewFrame = getViewFrameOnScreen();
if (viewFrame.equals(mOverlayViewFrame)) {
return;
}
mSession.relayoutOverlayView(viewFrame);
mOverlayViewFrame = viewFrame;
|
private void | release()
mAppPrivateCommandAction = null;
mAppPrivateCommandData = null;
setSessionSurface(null);
removeSessionOverlayView();
mUseRequestedSurfaceLayout = false;
mSession.release();
mSession = null;
mSessionCallback = null;
|
private void | removeSessionOverlayView()
if (mSession == null || !mOverlayViewCreated) {
return;
}
mSession.removeOverlayView();
mOverlayViewCreated = false;
mOverlayViewFrame = null;
|
public void | requestUnblockContent(TvContentRating unblockedRating)Requests to unblock TV content according to the given rating.
This notifies TV input that blocked content is now OK to play.
if (mSession != null) {
mSession.requestUnblockContent(unblockedRating);
}
|
public void | reset()Resets this TvView.
This method is primarily used to un-tune the current TvView.
if (DEBUG) Log.d(TAG, "reset()");
synchronized (sMainTvViewLock) {
if (this == sMainTvView.get()) {
sMainTvView = NULL_TV_VIEW;
}
}
resetInternal();
|
private void | resetInternal()
if (mSession != null) {
release();
resetSurfaceView();
}
|
private void | resetSurfaceView()
if (mSurfaceView != null) {
mSurfaceView.getHolder().removeCallback(mSurfaceHolderCallback);
removeView(mSurfaceView);
}
mSurface = null;
mSurfaceView = new SurfaceView(getContext(), mAttrs, mDefStyleAttr) {
@Override
protected void updateWindow(boolean force, boolean redrawNeeded) {
super.updateWindow(force, redrawNeeded);
relayoutSessionOverlayView();
}};
mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
if (mWindowZOrder == ZORDER_MEDIA_OVERLAY) {
mSurfaceView.setZOrderMediaOverlay(true);
} else if (mWindowZOrder == ZORDER_ON_TOP) {
mSurfaceView.setZOrderOnTop(true);
}
addView(mSurfaceView);
|
public void | selectTrack(int type, java.lang.String trackId)Selects a track.
if (mSession != null) {
mSession.selectTrack(type, trackId);
}
|
public void | sendAppPrivateCommand(java.lang.String action, android.os.Bundle data)Calls {@link TvInputService.Session#appPrivateCommand(String, Bundle)
TvInputService.Session.appPrivateCommand()} on the current TvView.
if (TextUtils.isEmpty(action)) {
throw new IllegalArgumentException("action cannot be null or an empty string");
}
if (mSession != null) {
mSession.sendAppPrivateCommand(action, data);
} else {
Log.w(TAG, "sendAppPrivateCommand - session not created (action " + action + " cached)");
if (mAppPrivateCommandAction != null) {
Log.w(TAG, "previous cached action " + action + " removed");
}
mAppPrivateCommandAction = action;
mAppPrivateCommandData = data;
}
|
public void | setCallback(android.media.tv.TvView$TvInputCallback callback)Sets the callback to be invoked when an event is dispatched to this TvView.
mCallback = callback;
|
public void | setCaptionEnabled(boolean enabled)Enables or disables the caption in this TvView.
Note that this method does not take any effect unless the current TvView is tuned.
mCaptionEnabled = enabled ? CAPTION_ENABLED : CAPTION_DISABLED;
if (mSession != null) {
mSession.setCaptionEnabled(enabled);
}
|
public void | setMain()Sets this as the main {@link TvView}.
The main {@link TvView} is a {@link TvView} whose corresponding TV input determines the
HDMI-CEC active source device. For an HDMI port input, one of source devices that is
connected to that HDMI port becomes the active source. For an HDMI-CEC logical device input,
the corresponding HDMI-CEC logical device becomes the active source. For any non-HDMI input
(including the tuner, composite, S-Video, etc.), the internal device (= TV itself) becomes
the active source.
First tuned {@link TvView} becomes main automatically, and keeps to be main until either
{@link #reset} is called for the main {@link TvView} or {@link #setMain} is called for other
{@link TvView}.
synchronized (sMainTvViewLock) {
sMainTvView = new WeakReference<>(this);
if (hasWindowFocus() && mSession != null) {
mSession.setMain();
}
}
|
public void | setOnUnhandledInputEventListener(android.media.tv.TvView$OnUnhandledInputEventListener listener)Registers a callback to be invoked when an input event is not handled by the bound TV input.
mOnUnhandledInputEventListener = listener;
|
private void | setSessionSurface(android.view.Surface surface)
if (mSession == null) {
return;
}
mSession.setSurface(surface);
|
public void | setStreamVolume(float volume)Sets the relative stream volume of this session to handle a change of audio focus.
if (DEBUG) Log.d(TAG, "setStreamVolume(" + volume + ")");
mHasStreamVolume = true;
mStreamVolume = volume;
if (mSession == null) {
// Volume will be set once the connection has been made.
return;
}
mSession.setStreamVolume(volume);
|
public void | setZOrderMediaOverlay(boolean isMediaOverlay)Sets the Z order of a window owning the surface of this TvView above the normal TvView
but below an application.
if (isMediaOverlay) {
mWindowZOrder = ZORDER_MEDIA_OVERLAY;
removeSessionOverlayView();
} else {
mWindowZOrder = ZORDER_MEDIA;
createSessionOverlayView();
}
if (mSurfaceView != null) {
// ZOrderOnTop(false) removes WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
// from WindowLayoutParam as well as changes window type.
mSurfaceView.setZOrderOnTop(false);
mSurfaceView.setZOrderMediaOverlay(isMediaOverlay);
}
|
public void | setZOrderOnTop(boolean onTop)Sets the Z order of a window owning the surface of this TvView on top of an application.
if (onTop) {
mWindowZOrder = ZORDER_ON_TOP;
removeSessionOverlayView();
} else {
mWindowZOrder = ZORDER_MEDIA;
createSessionOverlayView();
}
if (mSurfaceView != null) {
mSurfaceView.setZOrderMediaOverlay(false);
mSurfaceView.setZOrderOnTop(onTop);
}
|
public void | tune(java.lang.String inputId, android.net.Uri channelUri, android.os.Bundle params)Tunes to a given channel.
if (DEBUG) Log.d(TAG, "tune(" + channelUri + ")");
if (TextUtils.isEmpty(inputId)) {
throw new IllegalArgumentException("inputId cannot be null or an empty string");
}
synchronized (sMainTvViewLock) {
if (sMainTvView.get() == null) {
sMainTvView = new WeakReference<>(this);
}
}
if (mSessionCallback != null && mSessionCallback.mInputId.equals(inputId)) {
if (mSession != null) {
mSession.tune(channelUri, params);
} else {
// Session is not created yet. Replace the channel which will be set once the
// session is made.
mSessionCallback.mChannelUri = channelUri;
mSessionCallback.mTuneParams = params;
}
} else {
resetInternal();
// When createSession() is called multiple times before the callback is called,
// only the callback of the last createSession() call will be actually called back.
// The previous callbacks will be ignored. For the logic, mSessionCallback
// is newly assigned for every createSession request and compared with
// MySessionCreateCallback.this.
mSessionCallback = new MySessionCallback(inputId, channelUri, params);
if (mTvInputManager != null) {
mTvInputManager.createSession(inputId, mSessionCallback, mHandler);
}
}
|
public void | tune(java.lang.String inputId, android.net.Uri channelUri)Tunes to a given channel.
tune(inputId, channelUri, null);
|