WebviewActivity.java


Overview

`WebviewActivity.java` defines an Android `Activity` that serves as a container for rendering VPAID (Video Player Ad-Serving Interface Definition) ads using a `WebView`. This activity initializes the WebView environment, integrates it with a native VPAID client (`TubiVPAID`), and manages user interactions such as back navigation. It acts as the UI host for VPAID ads, bridging the gap between native Android components and the interactive JavaScript ad content loaded in the WebView.


Class: WebviewActivity

Purpose

`WebviewActivity` manages the lifecycle and setup of the WebView component that displays VPAID ads. It initializes the `TubiVPAID` client with the WebView and a UI thread handler, configures the WebView for JavaScript interface communication, and loads the VPAID ad content URL.

Class Structure

Property

Type

Description

`VPAID_URL`

`String`

URL of the web page hosting the VPAID ads (`http://tubitv.com/`)

`tubiVPAID`

`TubiVPAID`

Native client managing VPAID ad playback via WebView interface

`myHandler`

`Handler`

Android Handler for posting UI thread tasks

`webView`

`WebView`

Android WebView component for rendering ads


Methods

protected void onCreate(@Nullable Bundle savedInstanceState)


private void initVpaidWebview(WebView view, Handler handler)


public void onBackPressed()


Important Implementation Details


Interaction with Other Components


Usage Example

A typical usage scenario is an Android app that plays video content and occasionally needs to display interactive VPAID ads. When a VPAID ad is triggered, the app launches `WebviewActivity`, which sets up the WebView and loads the ad. The activity manages the ad playback lifecycle and user interactions until the ad completes or errors out.


Visual Diagram

classDiagram
    class WebviewActivity {
        -static final String VPAID_URL
        -TubiVPAID tubiVPAID
        -Handler myHandler
        -WebView webView
        +void onCreate(Bundle savedInstanceState)
        -void initVpaidWebview(WebView view, Handler handler)
        +void onBackPressed()
    }
    WebviewActivity --> WebView : uses
    WebviewActivity --> Handler : uses
    WebviewActivity --> TubiVPAID : creates & manages

Summary

`WebviewActivity.java` is a focused Android activity designed to host and manage VPAID ad playback via a WebView component. By initializing the `TubiVPAID` client and binding it as a JavaScript interface, it enables seamless communication between native Android code and the interactive VPAID ads running in JavaScript. The activity handles lifecycle events such as creation and back navigation to provide a smooth user experience during ad playback. This file forms the UI layer of the VPAID ad integration subsystem, complementing the underlying ad logic and state management handled by other components like `TubiVPAID` and the media player's FSM.