attr.xml
Overview
The `attr.xml` file is an Android resource definition file that declares custom XML attributes used by various UI components within the application. Specifically, it defines several `` groups, each grouping a set of custom attributes that can be applied to custom views or components in the Android layout XML files.
This file facilitates configuring the appearance and behavior of custom UI elements such as video player views and control views by allowing developers to specify parameters like artwork usage, controller behavior, timeout durations, and state-dependent drawable resources.
By centralizing these attribute definitions, the file enables flexible, reusable, and customizable UI components that can be easily styled and modified via XML without changing the underlying Java/Kotlin code.
Detailed Explanation of Elements
1. <declare-styleable name="TubiExoPlayerView">
Defines custom attributes for the `TubiExoPlayerView` component, which appears to be a customized video player view, likely based on ExoPlayer.
Attribute Name | Format | Description |
|---|---|---|
`use_artwork` | boolean | Indicates whether to display artwork (e.g., album art or placeholder image) when no video is playing. |
`default_artwork` | reference | A drawable resource reference used as the default artwork when no media artwork is available. |
`use_controller` | boolean | Specifies whether the playback controller UI (play/pause, seek controls) should be enabled. |
`surface_type` | (unspecified) | Defines the type of surface used for video rendering (e.g., TextureView or SurfaceView). |
`show_timeout` | (unspecified) | The duration for which the controller UI remains visible before auto-hiding. |
`rewind_increment` | (unspecified) | The rewind increment duration in milliseconds or seconds. |
`fastforward_increment` | (unspecified) | The fast-forward increment duration in milliseconds or seconds. |
`resize_mode` | (unspecified) | Defines how the video content should be resized/scaled within the view bounds. |
`player_layout_id` | (unspecified) | A layout resource reference for specifying a custom player UI layout. |
`controller_layout_id` | (unspecified) | A layout resource reference for specifying a custom controller UI layout. |
**Usage Example:**
<com.example.TubiExoPlayerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:use_artwork="true"
app:default_artwork="@drawable/default_album_art"
app:use_controller="true"
app:surface_type="texture_view"
app:show_timeout="3000"
app:rewind_increment="10000"
app:fastforward_increment="10000"
app:resize_mode="fit"
app:player_layout_id="@layout/custom_player_layout"
app:controller_layout_id="@layout/custom_controller_layout" />
2. <declare-styleable name="TubiPlayerControlViewOld">
Defines a legacy or older version of player control view attributes.
Attribute Name | Format | Description |
|---|---|---|
`show_timeout_ms` | integer | The duration in milliseconds before the control view hides itself automatically. |
**Usage Example:**
<com.example.TubiPlayerControlViewOld
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:show_timeout_ms="4000" />
3. <declare-styleable name="TubiPlayerControlView">
Defines attributes for a newer or current player control view component.
Attribute Name | Format | Description |
|---|---|---|
`tubi_hide_timeout_ms` | integer | Duration in milliseconds after which the control view auto-hides. |
**Usage Example:**
<com.example.TubiPlayerControlView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tubi_hide_timeout_ms="3500" />
4. <declare-styleable name="StateImageButton">
Defines attributes for a custom button that changes its image resource depending on its checked state.
Attribute Name | Format | Description |
|---|---|---|
`state_checked` | reference | Drawable resource shown when the button is in the checked state. |
`state_not_checked` | reference | Drawable resource shown when the button is not checked. |
**Usage Example:**
<com.example.StateImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:state_checked="@drawable/ic_checked"
app:state_not_checked="@drawable/ic_unchecked" />
Important Implementation Details
Formats and Data Types: The
formatattribute specifies the expected data type for each attribute, such as boolean, integer, or reference to a drawable resource. Android's resource system validates these types during compilation.Custom View Integration: These attributes are typically referenced in custom view classes via the
TypedArrayAPI inside the view's constructor or initialization block. For example, the view reads these attributes usingcontext.obtainStyledAttributes()to configure internal state and UI accordingly.Backward Compatibility: The presence of both
TubiPlayerControlViewOldandTubiPlayerControlViewsuggests a migration or versioning strategy, allowing gradual adoption of new control views without breaking existing code.Surface Type and Resize Mode: While the formats are unspecified in this file, these attributes likely expect enumerated values or specific string constants defined elsewhere in the codebase or Android framework. They control how the video is rendered and scaled, impacting performance and user experience.
Interaction with Other Parts of the System
Custom Views / Components: The attributes declared here are consumed by the corresponding custom views:
TubiExoPlayerView,TubiPlayerControlViewOld,TubiPlayerControlView, andStateImageButton. These views parse the attributes to adjust their functionality and appearance.Layouts and XML: Developers use these attributes in layout XML files to customize UI behavior declaratively, without modifying code.
Drawable Resources: Attributes like
default_artwork,state_checked, andstate_not_checkedreference drawable resources, linking UI state to visual assets.Player Logic: Attributes like rewind and fast-forward increments, controller visibility timeout, and resize modes influence the media playback experience governed by the player component logic.
Mermaid Diagram: Structure of attr.xml
classDiagram
class TubiExoPlayerView {
+use_artwork: boolean
+default_artwork: reference
+use_controller: boolean
+surface_type
+show_timeout
+rewind_increment
+fastforward_increment
+resize_mode
+player_layout_id
+controller_layout_id
}
class TubiPlayerControlViewOld {
+show_timeout_ms: integer
}
class TubiPlayerControlView {
+tubi_hide_timeout_ms: integer
}
class StateImageButton {
+state_checked: reference
+state_not_checked: reference
}
Summary
The `attr.xml` file defines a collection of custom XML attributes that support flexible configuration of video player components and UI buttons. These attributes empower developers to tailor playback controls, artwork display, UI timeouts, and button states easily via XML declarations. The file plays a crucial role in the UI layer of the application by bridging resource definitions with custom view implementations, ultimately enhancing the media playback experience and visual consistency across the app.