view_tubi_player_controller_subtitles_btn.xml
Overview
`view_tubi_player_controller_subtitles_btn.xml` is an Android drawable selector XML file used to define the visual states of the subtitles toggle button in the Tubi Player Controller UI. This file manages how the subtitles button's icon changes depending on whether subtitles are enabled or disabled by the user.
Specifically, it switches between two drawable resources:
@drawable/tubi_tv_subtitles_onwhen subtitles are enabled (checked state).@drawable/tubi_tv_subtitles_offwhen subtitles are disabled (unchecked state).
This approach provides visual feedback to users, making it clear whether subtitles are currently active during video playback.
Detailed Explanation
File Type
Android Drawable Selector XML
This type of XML file is used for defining different drawable resources to be used under different states of a UI component, generally for buttons or toggles.
Structure and Elements
<selector>: Root element that defines a list of<item>elements, each representing a drawable associated with a particular state.<item>: Represents a drawable resource and the state(s) under which it applies. Here, the state isstate_checkedwhich indicates the checked/unchecked status of the button.
Items in this selector
XML Element | Description |
|---|---|
Drawable shown when the subtitles button is in the "checked" (enabled) state. | |
Drawable shown when the subtitles button is in the "unchecked" (disabled) state. |
Usage Example
This selector is typically used as the `android:background` or `android:src` attribute of a `ToggleButton`, `CheckBox`, or `ImageButton` in a layout XML that controls subtitles toggling.
Example usage in a layout XML:
<ImageButton
android:id="@+id/subtitles_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/view_tubi_player_controller_subtitles_btn"
android:checkable="true"
android:contentDescription="@string/subtitles_toggle" />
In the Tubi player controller, when the user toggles subtitles:
If subtitles are enabled (
state_checked=true), the button shows thetubi_tv_subtitles_onicon.If subtitles are disabled (
state_checked=false), the button shows thetubi_tv_subtitles_officon.
Important Implementation Details
State-Driven UI: This XML leverages Android's state list drawable mechanism, which simplifies UI state management by declaratively associating visual states to button states without extra code.
Drawables Management: The actual visual icons (
tubi_tv_subtitles_onandtubi_tv_subtitles_off) must be designed to clearly represent the on/off states of subtitles.No Runtime Logic Required: Since this is purely an XML resource, no additional runtime logic is needed to switch icons; Android framework handles it automatically based on the button's checked state.
Interaction with Other Components
UI Layer: This file is part of the UI layer, specifically tied to the video player controller's subtitle toggle button.
Controller Logic: The player controller logic (likely in Kotlin/Java code) handles user input events to toggle subtitles and updates the button's checked state.
Drawable Resources: References two drawable resources (
tubi_tv_subtitles_onandtubi_tv_subtitles_off) which must exist in the project’s drawable folders.Accessibility: The button using this selector should have appropriate content descriptions for accessibility tools.
Visual Diagram
The following Mermaid diagram represents the relationship between the selector and its drawable states:
classDiagram
class view_tubi_player_controller_subtitles_btn {
<<selector>>
+state_checked: true -> tubi_tv_subtitles_on (drawable)
+state_checked: false -> tubi_tv_subtitles_off (drawable)
}
view_tubi_player_controller_subtitles_btn --> tubi_tv_subtitles_on : uses
view_tubi_player_controller_subtitles_btn --> tubi_tv_subtitles_off : uses
Summary
Purpose: Defines the icon for subtitles button based on checked state.
Functionality: Switches drawable between subtitles ON and OFF icons.
Usage: Applied as a background or source drawable of a checkable button in the player UI.
Benefits: Simplifies UI state management without code, enhances user experience by providing clear visual feedback.
This resource is a small but crucial part of the Tubi player UI, ensuring intuitive interaction with subtitle controls.