Android APIs
public class

TvView

extends ViewGroup
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.media.tv.TvView

Class Overview

View playing TV

Summary

Nested Classes
interface TvView.OnUnhandledInputEventListener Interface definition for a callback to be invoked when the unhandled input event is received. 
class TvView.TvInputListener Interface used to receive various status updates on the TvView
[Expand]
Inherited XML Attributes
From class android.view.ViewGroup
From class android.view.View
Constants
int ERROR_BUSY Passed with onError(String, int).
int ERROR_TV_INPUT_DISCONNECTED Passed with onError(String, int).
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
TvView(Context context)
TvView(Context context, AttributeSet attrs)
TvView(Context context, AttributeSet attrs, int defStyleAttr)
Public Methods
boolean dispatchGenericMotionEvent(MotionEvent event)
Dispatch a generic motion event.
boolean dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
boolean dispatchTouchEvent(MotionEvent event)
Pass the touch screen motion event down to the target view, or this view if it is the target.
boolean dispatchTrackballEvent(MotionEvent event)
Pass a trackball motion event down to the focused view.
boolean dispatchUnhandledInputEvent(InputEvent event)
Dispatches an unhandled input event to the next receiver.
boolean onUnhandledInputEvent(InputEvent event)
Called when an unhandled input event was also not handled by the user provided callback.
void reset()
Resets this TvView.
void setOnUnhandledInputEventListener(TvView.OnUnhandledInputEventListener listener)
Registers a callback to be invoked when an input event was not handled by the bound TV input.
void setStreamVolume(float volume)
Sets the relative stream volume of this session to handle a change of audio focus.
void setTvInputListener(TvView.TvInputListener listener)
Sets a listener for events in this TvView.
void setVisibility(int visibility)
Set the enabled state of this view.
void tune(String inputId, Uri channelUri)
Tunes to a given channel.
Protected Methods
void onAttachedToWindow()
This is called when the view is attached to a window.
void onDetachedFromWindow()
This is called when the view is detached from a window.
void onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int ERROR_BUSY

Passed with onError(String, int). Indicates that the requested TV input is busy and unable to handle the request.

Constant Value: 0 (0x00000000)

public static final int ERROR_TV_INPUT_DISCONNECTED

Passed with onError(String, int). Indicates that the underlying TV input has been disconnected.

Constant Value: 1 (0x00000001)

Public Constructors

public TvView (Context context)

public TvView (Context context, AttributeSet attrs)

public TvView (Context context, AttributeSet attrs, int defStyleAttr)

Public Methods

public boolean dispatchGenericMotionEvent (MotionEvent event)

Dispatch a generic motion event.

Generic motion events with source class SOURCE_CLASS_POINTER are delivered to the view under the pointer. All other generic motion events are delivered to the focused view. Hover events are handled specially and are delivered to onHoverEvent(MotionEvent).

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchKeyEvent (KeyEvent event)

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled, false otherwise.

public boolean dispatchTouchEvent (MotionEvent event)

Pass the touch screen motion event down to the target view, or this view if it is the target.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchTrackballEvent (MotionEvent event)

Pass a trackball motion event down to the focused view.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchUnhandledInputEvent (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.

Parameters
event The input event.
Returns
  • true if the event was handled by the view, false otherwise.

public boolean onUnhandledInputEvent (InputEvent event)

Called when an unhandled input event was also not handled by the user provided callback. This is the last chance to handle the unhandled input event in the TvView.

Parameters
event The input event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public void reset ()

Resets this TvView.

This method is primarily used to un-tune the current TvView.

public void setOnUnhandledInputEventListener (TvView.OnUnhandledInputEventListener listener)

Registers a callback to be invoked when an input event was not handled by the bound TV input.

Parameters
listener The callback to invoke when the unhandled input event was received.

public void setStreamVolume (float volume)

Sets the relative stream volume of this session to handle a change of audio focus.

Parameters
volume A volume value between 0.0f to 1.0f.

public void setTvInputListener (TvView.TvInputListener listener)

Sets a listener for events in this TvView.

Parameters
listener The listener to be called with events. A value of null removes any existing listener.

public void setVisibility (int visibility)

Set the enabled state of this view.

Parameters
visibility One of VISIBLE, INVISIBLE, or GONE.

public void tune (String inputId, Uri channelUri)

Tunes to a given channel.

Parameters
inputId the id of TV input which will play the given channel.
channelUri The URI of a channel.

Protected Methods

protected void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

protected void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.