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 */
14package android.support.v17.leanback.widget;
15
16import android.content.Context;
17import android.graphics.drawable.Drawable;
18import android.support.v17.leanback.R;
19import android.util.AttributeSet;
20import android.view.LayoutInflater;
21import android.view.View;
22
23/**
24 * This class allows a customized widget class to implement {@link TitleViewAdapter.Provider}
25 * and expose {@link TitleViewAdapter} methods to containing fragment (e.g. BrowseFragment or
26 * DetailsFragment).
27 * The title view must have a search orb view ({@link #getSearchAffordanceView()} aligned to start
28 * and can typically have a branding Drawable and or title text aligned to end.  The branding part
29 * is fully open to customization: not necessary to be a drawable or text.
30 */
31public abstract class TitleViewAdapter {
32
33    /**
34     * Interface to be implemented by a customized widget class to implement
35     * {@link TitleViewAdapter}.
36     */
37    public interface Provider {
38        /**
39         * Returns {@link TitleViewAdapter} to be implemented by the customized widget class.
40         * @return {@link TitleViewAdapter} to be implemented by the customized widget class.
41         */
42        TitleViewAdapter getTitleViewAdapter();
43    }
44
45    public static final int BRANDING_VIEW_VISIBLE = 0x02;
46    public static final int SEARCH_VIEW_VISIBLE = 0x04;
47    public static final int FULL_VIEW_VISIBLE = BRANDING_VIEW_VISIBLE | SEARCH_VIEW_VISIBLE;
48
49    /**
50     * Sets the title text.
51     * @param titleText The text to set as title.
52     */
53    public void setTitle(CharSequence titleText) {
54    }
55
56    /**
57     * Returns the title text.
58     * @return The title text.
59     */
60    public CharSequence getTitle() {
61        return null;
62    }
63
64    /**
65     * Sets the badge drawable.
66     * If non-null, the drawable is displayed instead of the title text.
67     * @param drawable The badge drawable to set on title view.
68     */
69    public void setBadgeDrawable(Drawable drawable) {
70    }
71
72    /**
73     * Returns the badge drawable.
74     * @return The badge drawable.
75     */
76    public Drawable getBadgeDrawable() {
77        return null;
78    }
79
80    /**
81     *  Returns the view for the search affordance.
82     *  @return The view for search affordance.
83     */
84    public abstract View getSearchAffordanceView();
85
86    /**
87     * Sets a click listener for the search affordance view.
88     *
89     * <p>The presence of a listener will change the visibility of the search
90     * affordance in the fragment title. When set to non-null, the title will
91     * contain an element that a user may click to begin a search.
92     *
93     * <p>The listener's {@link View.OnClickListener#onClick onClick} method
94     * will be invoked when the user clicks on the search element.
95     *
96     * @param listener The listener to call when the search element is clicked.
97     */
98    public void setOnSearchClickedListener(View.OnClickListener listener) {
99    }
100
101    /**
102     * Sets the {@link android.support.v17.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 android.support.v17.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