UIControllerView.java


Overview

`UIControllerView` is a custom Android UI component extending `FrameLayout` that provides an interactive playback control panel for media content. It serves as the visual container for user controls such as play/pause buttons, seek bars, and other playback-related UI elements, which are data-bound to a `UserController` instance representing the current playback state and user interaction logic.

The primary responsibilities of `UIControllerView` include:

This class encapsulates UI visibility logic and binds the playback state model to the control panel, making it an essential component for user interaction within the media playback interface.


Class: UIControllerView

Package

`com.tubitv.media.views`

Inheritance

Properties

Name

Type

Description

`TAG`

`String` (static final)

Log tag identifying this class.

`TIME_TO_HIDE_CONTROL`

`int` (static final)

Duration in milliseconds (3000 ms) after which the control panel auto-hides.

`userController`

`UserController`

The data-binding controller instance linked to this view providing playback state and logic.

`binding`

`UiControllerViewBinding`

Binding object generated from `ui_controller_view.xml` layout, connecting UI to data model.

`countdownHandler`

`Handler`

Handler to schedule delayed UI hide actions.

`hideUIAction`

`Runnable`

Runnable task that hides the control panel by setting visibility to GONE.

Constructors

  1. UIControllerView(Context context)

    • Calls the two-parameter constructor with null attributes.

    • Initializes the view.

  2. UIControllerView(Context context, @Nullable AttributeSet attrs)

    • Calls the three-parameter constructor with a default style attribute of 0.

    • Initializes the view.

  3. UIControllerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)

    • Main constructor.

    • Calls initLayout(context) to inflate and bind the layout, initialize handler.

Methods


setUserController(UserController userController) : UIControllerView

UIControllerView controllerView = new UIControllerView(context);
controllerView.setUserController(myUserController);

onDetachedFromWindow() : void


onTouchEvent(MotionEvent event) : boolean

@Override
public boolean onTouchEvent(MotionEvent event) {
    countdownHandler.removeCallbacks(hideUIAction);

    if (binding.controllerPanel.getVisibility() == VISIBLE) {
        binding.controllerPanel.setVisibility(GONE);
    } else {
        if (userController.playerPlaybackState.get() != Player.STATE_IDLE) {
            binding.controllerPanel.setVisibility(VISIBLE);
            hideUiTimeout();
        }
    }

    return super.onTouchEvent(event);
}

initLayout(Context context) : void


hideUiTimeout() : void


Important Implementation Details


Interaction With Other Components


Usage Example

// In Activity or custom Player View initialization:

UIControllerView controlView = new UIControllerView(context);

// Assuming userController is already instantiated and configured
controlView.setUserController(userController);

// Add to your player layout hierarchy
playerContainer.addView(controlView);

// The controls will auto-hide after 3 seconds of inactivity
// and toggle visibility upon user touch.

Mermaid Class Diagram

classDiagram
    class UIControllerView {
        - static final String TAG
        - static final int TIME_TO_HIDE_CONTROL = 3000
        - UserController userController
        - UiControllerViewBinding binding
        - Handler countdownHandler
        - Runnable hideUIAction
        + UIControllerView(Context)
        + UIControllerView(Context, AttributeSet)
        + UIControllerView(Context, AttributeSet, int)
        + UIControllerView setUserController(UserController)
        + void onDetachedFromWindow()
        + boolean onTouchEvent(MotionEvent)
        - void initLayout(Context)
        - void hideUiTimeout()
    }

Summary

`UIControllerView` acts as the user-facing playback control interface within the media player UI. By seamlessly integrating Android Data Binding with `UserController`, it allows the UI to reflect playback state changes in real-time. Its touch handling and auto-hide logic ensure an unobtrusive and user-friendly control experience. This component is typically embedded into the playback view hierarchy and interacts closely with playback state models and UI layouts to provide a responsive media control panel.


Appendix: Layout Binding Assumption

The `UiControllerViewBinding` class is generated from a layout XML named `ui_controller_view.xml` which contains a root view with an ID `controllerPanel`. This panel is the container whose visibility is toggled to show or hide the controls.


End of Documentation for UIControllerView.java