Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
      5  * in compliance with the License. You may obtain a copy of the License at
      6  *
      7  * http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the License
     10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
     11  * or implied. See the License for the specific language governing permissions and limitations under
     12  * the License.
     13  */
     14 package androidx.leanback.widget;
     15 
     16 import android.graphics.drawable.Drawable;
     17 import android.view.View;
     18 
     19 /**
     20  * This class allows a customized widget class to implement {@link TitleViewAdapter.Provider}
     21  * and expose {@link TitleViewAdapter} methods to containing fragment (e.g. BrowseFragment or
     22  * DetailsFragment).
     23  * The title view must have a search orb view ({@link #getSearchAffordanceView()} aligned to start
     24  * and can typically have a branding Drawable and or title text aligned to end.  The branding part
     25  * is fully open to customization: not necessary to be a drawable or text.
     26  */
     27 public abstract class TitleViewAdapter {
     28 
     29     /**
     30      * Interface to be implemented by a customized widget class to implement
     31      * {@link TitleViewAdapter}.
     32      */
     33     public interface Provider {
     34         /**
     35          * Returns {@link TitleViewAdapter} to be implemented by the customized widget class.
     36          * @return {@link TitleViewAdapter} to be implemented by the customized widget class.
     37          */
     38         TitleViewAdapter getTitleViewAdapter();
     39     }
     40 
     41     public static final int BRANDING_VIEW_VISIBLE = 0x02;
     42     public static final int SEARCH_VIEW_VISIBLE = 0x04;
     43     public static final int FULL_VIEW_VISIBLE = BRANDING_VIEW_VISIBLE | SEARCH_VIEW_VISIBLE;
     44 
     45     /**
     46      * Sets the title text.
     47      * @param titleText The text to set as title.
     48      */
     49     public void setTitle(CharSequence titleText) {
     50     }
     51 
     52     /**
     53      * Returns the title text.
     54      * @return The title text.
     55      */
     56     public CharSequence getTitle() {
     57         return null;
     58     }
     59 
     60     /**
     61      * Sets the badge drawable.
     62      * If non-null, the drawable is displayed instead of the title text.
     63      * @param drawable The badge drawable to set on title view.
     64      */
     65     public void setBadgeDrawable(Drawable drawable) {
     66     }
     67 
     68     /**
     69      * Returns the badge drawable.
     70      * @return The badge drawable.
     71      */
     72     public Drawable getBadgeDrawable() {
     73         return null;
     74     }
     75 
     76     /**
     77      *  Returns the view for the search affordance.
     78      *  @return The view for search affordance.
     79      */
     80     public abstract View getSearchAffordanceView();
     81 
     82     /**
     83      * Sets a click listener for the search affordance view.
     84      *
     85      * <p>The presence of a listener will change the visibility of the search
     86      * affordance in the fragment title. When set to non-null, the title will
     87      * contain an element that a user may click to begin a search.
     88      *
     89      * <p>The listener's {@link View.OnClickListener#onClick onClick} method
     90      * will be invoked when the user clicks on the search element.
     91      *
     92      * @param listener The listener to call when the search element is clicked.
     93      */
     94     public void setOnSearchClickedListener(View.OnClickListener listener) {
     95         View view = getSearchAffordanceView();
     96         if (view != null) {
     97             view.setOnClickListener(listener);
     98         }
     99     }
    100 
    101     /**
    102      * Sets the {@link androidx.leanback.widget.SearchOrbView.Colors} used to draw the
    103      * search affordance.
    104      *
    105      * @param colors Colors used to draw search affordance.
    106      */
    107     public void setSearchAffordanceColors(SearchOrbView.Colors colors) {
    108     }
    109 
    110     /**
    111      * Returns the {@link androidx.leanback.widget.SearchOrbView.Colors} used to draw the
    112      * search affordance.
    113      *
    114      * @return Colors used to draw search affordance.
    115      */
    116     public SearchOrbView.Colors getSearchAffordanceColors() {
    117         return null;
    118     }
    119 
    120     /**
    121      * Enables or disables any view animations.  This method is called to save CPU cycle for example
    122      * stop search view breathing animation when containing fragment is paused.
    123      * @param enable True to enable animation, false otherwise.
    124      */
    125     public void setAnimationEnabled(boolean enable) {
    126     }
    127 
    128     /**
    129      * Based on the flag, it updates the visibility of the individual components -
    130      * Branding views (badge drawable and/or title) and search affordance view.
    131      *
    132      * @param flags integer representing the visibility of TitleView components.
    133      * @see #BRANDING_VIEW_VISIBLE
    134      * @see #SEARCH_VIEW_VISIBLE
    135      * @see #FULL_VIEW_VISIBLE
    136      */
    137     public void updateComponentsVisibility(int flags) {
    138     }
    139 }
    140