TvAdView


open class TvAdView : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.media.tv.ad.TvAdView

Displays contents of TV advertisement services.

Summary

Nested classes
abstract

Interface definition for a callback to be invoked when the unhandled input event is received.

abstract

Callback used to receive various status updates on the TvAdView.

Inherited XML attributes
Constants
static String

The error code of an error.

static String

The name of the method where the error happened, if applicable.

Inherited constants
Public constructors
TvAdView(context: Context)

TvAdView(context: Context, attrs: AttributeSet?)

TvAdView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Public methods
open Unit

Clears the callback.

open Unit

Clears the OnUnhandledInputEventListener.

open Boolean

Dispatch a key event to the next view on the focus path.

open Boolean

Dispatches an unhandled input event to the next receiver.

open TvAdView.OnUnhandledInputEventListener?

Gets the OnUnhandledInputEventListener.

open Unit
notifyError(errMsg: String, params: Bundle)

Notifies the corresponding TvAdService when there is an error.

open Unit
notifyTvMessage(type: Int, data: Bundle)

This is called to notify the corresponding TV AD service when a new TV message is received.

open Unit

open Unit

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Boolean

Called when an unhandled input event also has not been handled by the user provided callback.

open Unit
onVisibilityChanged(changedView: View, visibility: Int)

Called when the visibility of the view or an ancestor of the view has changed.

open Unit
prepareAdService(serviceId: String, type: String)

Prepares the AD service of corresponding TvAdService.

open Unit

Resets this TvAdView to release its resources.

open Unit

Resets the AD service.

open Unit
sendCurrentChannelUri(channelUri: Uri?)

Sends current channel URI to related TV AD service.

open Unit

Sends current TV input ID to related TV AD service.

open Unit

Sends current video bounds to related TV AD service.

open Unit
sendSigningResult(signingId: String, result: ByteArray)

Sends signing result to related TV AD service.

open Unit

Sends track info list to related TV AD service.

open Unit

Sets the callback to be invoked when an event is dispatched to this TvAdView.

open Unit

Sets a listener to be invoked when an input event is not handled by the TV AD service.

open Boolean
setTvView(tvView: TvView?)

Sets the TvAdView to receive events from TvInputService.

open Unit
setZOrderMediaOverlay(isMediaOverlay: Boolean)

Controls whether the TvAdView's surface is placed on top of other regular surface views in the window (but still behind the window itself).

open Unit

Controls whether the TvAdView's surface is placed on top of its window.

open Unit

Starts the AD service.

open Unit

Stops the AD service.

Inherited functions
Inherited properties

Constants

ERROR_KEY_ERROR_CODE

static val ERROR_KEY_ERROR_CODE: String

The error code of an error.

It can be TvAdManager.ERROR_WEAK_SIGNAL, TvAdManager.ERROR_RESOURCE_UNAVAILABLE, etc.

Value: "error_code"

ERROR_KEY_METHOD_NAME

static val ERROR_KEY_METHOD_NAME: String

The name of the method where the error happened, if applicable. For example, if there is an error during signing, the request name is "onRequestSigning".

Value: "method_name"

Public constructors

TvAdView

TvAdView(context: Context)
Parameters
context Context: This value cannot be null.

TvAdView

TvAdView(
    context: Context,
    attrs: AttributeSet?)
Parameters
context Context: This value cannot be null.
attrs AttributeSet?: This value may be null.

TvAdView

TvAdView(
    context: Context,
    attrs: AttributeSet?,
    defStyleAttr: Int)
Parameters
context Context: This value cannot be null.
attrs AttributeSet?: This value may be null.

Public methods

clearCallback

open fun clearCallback(): Unit

Clears the callback.

clearOnUnhandledInputEventListener

open fun clearOnUnhandledInputEventListener(): Unit

Clears the OnUnhandledInputEventListener.

dispatchKeyEvent

open fun dispatchKeyEvent(event: KeyEvent?): Boolean

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 KeyEvent?: This value may be null.
Return
Boolean True if the event was handled, false otherwise.

dispatchUnhandledInputEvent

open fun dispatchUnhandledInputEvent(event: InputEvent): Boolean

Dispatches an unhandled input event to the next receiver. It gives the host application a chance to dispatch the unhandled input events.

Parameters
event InputEvent: The input event. This value cannot be null.
Return
Boolean true if the event was handled by the view, false otherwise.

getOnUnhandledInputEventListener

open fun getOnUnhandledInputEventListener(): TvAdView.OnUnhandledInputEventListener?

Gets the OnUnhandledInputEventListener.

Returns null if the listener is not set or is cleared.

notifyError

open fun notifyError(
    errMsg: String,
    params: Bundle
): Unit

Notifies the corresponding TvAdService when there is an error.

Parameters
errMsg String: the message of the error. This value cannot be null.
params Bundle: additional parameters of the error. For example, the signingId of android.media.tv.ad.TvAdView.TvAdCallback#onRequestSigning(java.lang.String,java.lang.String,java.lang.String,java.lang.String,byte[]) can be included to identify the related signing request, and the method name "onRequestSigning" can also be added to the params. This value cannot be null.

notifyTvMessage

open fun notifyTvMessage(
    type: Int,
    data: Bundle
): Unit

This is called to notify the corresponding TV AD service when a new TV message is received.

Parameters
type Int: The type of message received, such as TvInputManager.TV_MESSAGE_TYPE_WATERMARK This value cannot be null. Value is android.media.tv.TvInputManager#TV_MESSAGE_TYPE_WATERMARK, android.media.tv.TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION, or android.media.tv.TvInputManager#TV_MESSAGE_TYPE_OTHER
data Bundle: The raw data of the message. The bundle keys are: TvInputManager.TV_MESSAGE_KEY_STREAM_ID, TvInputManager.TV_MESSAGE_KEY_GROUP_ID, TvInputManager.TV_MESSAGE_KEY_SUBTYPE, TvInputManager.TV_MESSAGE_KEY_RAW_DATA. See TvInputManager.TV_MESSAGE_KEY_SUBTYPE for more information on how to parse this data. This value cannot be null.

onAttachedToWindow

open fun onAttachedToWindow(): Unit

onDetachedFromWindow

open fun onDetachedFromWindow(): Unit

onLayout

open fun onLayout(
    changed: Boolean,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit
Parameters
changed Boolean: This is a new size or position for this view
left Int: Left position, relative to parent
top Int: Top position, relative to parent
right Int: Right position, relative to parent
bottom Int: Bottom position, relative to parent

onMeasure

open fun onMeasure(
    widthMeasureSpec: Int,
    heightMeasureSpec: Int
): Unit
Parameters
widthMeasureSpec Int: horizontal space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.
heightMeasureSpec Int: vertical space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.

onUnhandledInputEvent

open fun onUnhandledInputEvent(event: InputEvent): Boolean

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 TvAdView.

Parameters
event InputEvent: The input event. This value cannot be null.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onVisibilityChanged

open fun onVisibilityChanged(
    changedView: View,
    visibility: Int
): Unit

Called when the visibility of the view or an ancestor of the view has changed.

Parameters
changedView View: This value cannot be null.
visibility Int: The new visibility, one of VISIBLE, INVISIBLE or GONE. Value is android.view.View#VISIBLE, android.view.View#INVISIBLE, or android.view.View#GONE

prepareAdService

open fun prepareAdService(
    serviceId: String,
    type: String
): Unit

Prepares the AD service of corresponding TvAdService.

This should be called before calling startAdService(). Otherwise, startAdService() is a no-op.

Parameters
serviceId String: the AD service ID, which can be found in TvAdServiceInfo#getId(). This value cannot be null.
type String: This value cannot be null.

reset

open fun reset(): Unit

Resets this TvAdView to release its resources.

It can be reused by call prepareAdService(java.lang.String,java.lang.String).

resetAdService

open fun resetAdService(): Unit

Resets the AD service.

This releases the resources of the corresponding TvAdService.Session.

sendCurrentChannelUri

open fun sendCurrentChannelUri(channelUri: Uri?): Unit

Sends current channel URI to related TV AD service.

Parameters
channelUri Uri?: The current channel URI; null if there is no currently tuned channel.

sendCurrentTvInputId

open fun sendCurrentTvInputId(inputId: String?): Unit

Sends current TV input ID to related TV AD service.

Parameters
inputId String?: The current TV input ID whose channel is tuned. null if no channel is tuned.

sendCurrentVideoBounds

open fun sendCurrentVideoBounds(bounds: Rect): Unit

Sends current video bounds to related TV AD service.

Parameters
bounds Rect: the rectangle area for rendering the current video. This value cannot be null.

sendSigningResult

open fun sendSigningResult(
    signingId: String,
    result: ByteArray
): Unit

Sends signing result to related TV AD service.

This is used when the corresponding server of the ADs requires signing during handshaking, and the AD service doesn't have the built-in private key. The private key is provided by the content providers and pre-built in the related app, such as TV app.

Parameters
signingId String: the ID to identify the request. It's the same as the corresponding ID in TvAdService.Session.requestSigning(String, String, String, byte[]) This value cannot be null.
result ByteArray: the signed result. This value cannot be null.

sendTrackInfoList

open fun sendTrackInfoList(tracks: MutableList<TvTrackInfo!>?): Unit

Sends track info list to related TV AD service.

Parameters
tracks MutableList<TvTrackInfo!>?: This value may be null.

setCallback

open fun setCallback(
    executor: Executor,
    callback: TvAdView.TvAdCallback
): Unit

Sets the callback to be invoked when an event is dispatched to this TvAdView.

Parameters
callback TvAdView.TvAdCallback: the callback to receive events. MUST NOT be null.
executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

See Also

setOnUnhandledInputEventListener

open fun setOnUnhandledInputEventListener(listener: TvAdView.OnUnhandledInputEventListener): Unit

Sets a listener to be invoked when an input event is not handled by the TV AD service.

Parameters
listener TvAdView.OnUnhandledInputEventListener: The callback to be invoked when the unhandled input event is received. This value cannot be null.

setTvView

open fun setTvView(tvView: TvView?): Boolean

Sets the TvAdView to receive events from TvInputService. This method links the session of TvAdManager to TvInputManager session, so the TvAdService can get the TvInputService events.

Parameters
tvView TvView?: the TvView to be linked to this TvAdView via linking of Sessions. null to unlink the TvView.
Return
Boolean true if it's linked successfully; false otherwise.

setZOrderMediaOverlay

open fun setZOrderMediaOverlay(isMediaOverlay: Boolean): Unit

Controls whether the TvAdView's surface is placed on top of other regular surface views in the window (but still behind the window itself).

Calling this overrides any previous call to setZOrderOnTop.

Parameters
isMediaOverlay Boolean: true to be on top of another regular surface, false otherwise.

setZOrderOnTop

open fun setZOrderOnTop(onTop: Boolean): Unit

Controls whether the TvAdView's surface is placed on top of its window.

Calling this overrides any previous call to setZOrderMediaOverlay.

Parameters
onTop Boolean: true to be on top of its window, false otherwise.

startAdService

open fun startAdService(): Unit

Starts the AD service.

This should be called after calling prepareAdService(java.lang.String,java.lang.String). Otherwise, it's a no-op.

stopAdService

open fun stopAdService(): Unit

Stops the AD service.

It's a no-op if the service is not started.