public abstract class

TitleViewAdapter

extends java.lang.Object

 java.lang.Object

↳androidx.leanback.widget.TitleViewAdapter

Gradle dependencies

compile group: 'androidx.leanback', name: 'leanback', version: '1.2.0-alpha02'

  • groupId: androidx.leanback
  • artifactId: leanback
  • version: 1.2.0-alpha02

Artifact androidx.leanback:leanback:1.2.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.leanback:leanback com.android.support:leanback-v17

Androidx class mapping:

androidx.leanback.widget.TitleViewAdapter android.support.v17.leanback.widget.TitleViewAdapter

Overview

This class allows a customized widget class to implement TitleViewAdapter.Provider and expose TitleViewAdapter methods to containing fragment (e.g. BrowseFragment or DetailsFragment). The title view must have a search orb view (TitleViewAdapter.getSearchAffordanceView() aligned to start and can typically have a branding Drawable and or title text aligned to end. The branding part is fully open to customization: not necessary to be a drawable or text.

Summary

Fields
public static final intBRANDING_VIEW_VISIBLE

public static final intFULL_VIEW_VISIBLE

public static final intSEARCH_VIEW_VISIBLE

Constructors
publicTitleViewAdapter()

Methods
public DrawablegetBadgeDrawable()

Returns the badge drawable.

public SearchOrbView.ColorsgetSearchAffordanceColors()

Returns the SearchOrbView.Colors used to draw the search affordance.

public abstract ViewgetSearchAffordanceView()

Returns the view for the search affordance.

public java.lang.CharSequencegetTitle()

Returns the title text.

public voidsetAnimationEnabled(boolean enable)

Enables or disables any view animations.

public voidsetBadgeDrawable(Drawable drawable)

Sets the badge drawable.

public voidsetOnSearchClickedListener(View.OnClickListener listener)

Sets a click listener for the search affordance view.

public voidsetSearchAffordanceColors(SearchOrbView.Colors colors)

Sets the SearchOrbView.Colors used to draw the search affordance.

public voidsetTitle(java.lang.CharSequence titleText)

Sets the title text.

public voidupdateComponentsVisibility(int flags)

Based on the flag, it updates the visibility of the individual components - Branding views (badge drawable and/or title) and search affordance view.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int BRANDING_VIEW_VISIBLE

public static final int SEARCH_VIEW_VISIBLE

public static final int FULL_VIEW_VISIBLE

Constructors

public TitleViewAdapter()

Methods

public void setTitle(java.lang.CharSequence titleText)

Sets the title text.

Parameters:

titleText: The text to set as title.

public java.lang.CharSequence getTitle()

Returns the title text.

Returns:

The title text.

public void setBadgeDrawable(Drawable drawable)

Sets the badge drawable. If non-null, the drawable is displayed instead of the title text.

Parameters:

drawable: The badge drawable to set on title view.

public Drawable getBadgeDrawable()

Returns the badge drawable.

Returns:

The badge drawable.

public abstract View getSearchAffordanceView()

Returns the view for the search affordance.

Returns:

The view for search affordance.

public void setOnSearchClickedListener(View.OnClickListener listener)

Sets a click listener for the search affordance view.

The presence of a listener will change the visibility of the search affordance in the fragment title. When set to non-null, the title will contain an element that a user may click to begin a search.

The listener's method will be invoked when the user clicks on the search element.

Parameters:

listener: The listener to call when the search element is clicked.

public void setSearchAffordanceColors(SearchOrbView.Colors colors)

Sets the SearchOrbView.Colors used to draw the search affordance.

Parameters:

colors: Colors used to draw search affordance.

public SearchOrbView.Colors getSearchAffordanceColors()

Returns the SearchOrbView.Colors used to draw the search affordance.

Returns:

Colors used to draw search affordance.

public void setAnimationEnabled(boolean enable)

Enables or disables any view animations. This method is called to save CPU cycle for example stop search view breathing animation when containing fragment is paused.

Parameters:

enable: True to enable animation, false otherwise.

public void updateComponentsVisibility(int flags)

Based on the flag, it updates the visibility of the individual components - Branding views (badge drawable and/or title) and search affordance view.

Parameters:

flags: integer representing the visibility of TitleView components.

See also: TitleViewAdapter.BRANDING_VIEW_VISIBLE, TitleViewAdapter.SEARCH_VIEW_VISIBLE, TitleViewAdapter.FULL_VIEW_VISIBLE

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package androidx.leanback.widget;

import android.graphics.drawable.Drawable;
import android.view.View;

/**
 * This class allows a customized widget class to implement {@link TitleViewAdapter.Provider}
 * and expose {@link TitleViewAdapter} methods to containing fragment (e.g. BrowseFragment or
 * DetailsFragment).
 * The title view must have a search orb view ({@link #getSearchAffordanceView()} aligned to start
 * and can typically have a branding Drawable and or title text aligned to end.  The branding part
 * is fully open to customization: not necessary to be a drawable or text.
 */
public abstract class TitleViewAdapter {

    /**
     * Interface to be implemented by a customized widget class to implement
     * {@link TitleViewAdapter}.
     */
    public interface Provider {
        /**
         * Returns {@link TitleViewAdapter} to be implemented by the customized widget class.
         * @return {@link TitleViewAdapter} to be implemented by the customized widget class.
         */
        TitleViewAdapter getTitleViewAdapter();
    }

    public static final int BRANDING_VIEW_VISIBLE = 0x02;
    public static final int SEARCH_VIEW_VISIBLE = 0x04;
    public static final int FULL_VIEW_VISIBLE = BRANDING_VIEW_VISIBLE | SEARCH_VIEW_VISIBLE;

    /**
     * Sets the title text.
     * @param titleText The text to set as title.
     */
    public void setTitle(CharSequence titleText) {
    }

    /**
     * Returns the title text.
     * @return The title text.
     */
    public CharSequence getTitle() {
        return null;
    }

    /**
     * Sets the badge drawable.
     * If non-null, the drawable is displayed instead of the title text.
     * @param drawable The badge drawable to set on title view.
     */
    public void setBadgeDrawable(Drawable drawable) {
    }

    /**
     * Returns the badge drawable.
     * @return The badge drawable.
     */
    public Drawable getBadgeDrawable() {
        return null;
    }

    /**
     *  Returns the view for the search affordance.
     *  @return The view for search affordance.
     */
    public abstract View getSearchAffordanceView();

    /**
     * Sets a click listener for the search affordance view.
     *
     * <p>The presence of a listener will change the visibility of the search
     * affordance in the fragment title. When set to non-null, the title will
     * contain an element that a user may click to begin a search.
     *
     * <p>The listener's {@link View.OnClickListener#onClick onClick} method
     * will be invoked when the user clicks on the search element.
     *
     * @param listener The listener to call when the search element is clicked.
     */
    public void setOnSearchClickedListener(View.OnClickListener listener) {
        View view = getSearchAffordanceView();
        if (view != null) {
            view.setOnClickListener(listener);
        }
    }

    /**
     * Sets the {@link androidx.leanback.widget.SearchOrbView.Colors} used to draw the
     * search affordance.
     *
     * @param colors Colors used to draw search affordance.
     */
    public void setSearchAffordanceColors(SearchOrbView.Colors colors) {
    }

    /**
     * Returns the {@link androidx.leanback.widget.SearchOrbView.Colors} used to draw the
     * search affordance.
     *
     * @return Colors used to draw search affordance.
     */
    public SearchOrbView.Colors getSearchAffordanceColors() {
        return null;
    }

    /**
     * Enables or disables any view animations.  This method is called to save CPU cycle for example
     * stop search view breathing animation when containing fragment is paused.
     * @param enable True to enable animation, false otherwise.
     */
    public void setAnimationEnabled(boolean enable) {
    }

    /**
     * Based on the flag, it updates the visibility of the individual components -
     * Branding views (badge drawable and/or title) and search affordance view.
     *
     * @param flags integer representing the visibility of TitleView components.
     * @see #BRANDING_VIEW_VISIBLE
     * @see #SEARCH_VIEW_VISIBLE
     * @see #FULL_VIEW_VISIBLE
     */
    public void updateComponentsVisibility(int flags) {
    }
}