TitleView.java revision 4fdd3589c982860b831c0fad63c0082cb9079f47
1/*
2 * Copyright (C) 2014 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;
22import android.widget.FrameLayout;
23import android.widget.ImageView;
24import android.widget.TextView;
25
26/**
27 * Title view for a leanback fragment.
28 * @hide
29 */
30public class TitleView extends FrameLayout {
31
32    private ImageView mBadgeView;
33    private TextView mTextView;
34    private SearchOrbView mSearchOrbView;
35
36    public TitleView(Context context) {
37        this(context, null);
38    }
39
40    public TitleView(Context context, AttributeSet attrs) {
41        this(context, attrs, R.attr.browseTitleViewStyle);
42    }
43
44    public TitleView(Context context, AttributeSet attrs, int defStyleAttr) {
45        super(context, attrs, defStyleAttr);
46
47        LayoutInflater inflater = LayoutInflater.from(context);
48        View rootView = inflater.inflate(R.layout.lb_title_view, this);
49
50        mBadgeView = (ImageView) rootView.findViewById(R.id.browse_badge);
51        mTextView = (TextView) rootView.findViewById(R.id.browse_title);
52        mSearchOrbView = (SearchOrbView) rootView.findViewById(R.id.browse_orb);
53
54        setClipToPadding(false);
55        setClipChildren(false);
56    }
57
58    /**
59     * Sets the title text.
60     */
61    public void setTitle(String titleText) {
62        mTextView.setText(titleText);
63    }
64
65    /**
66     * Returns the title text.
67     */
68    public CharSequence getTitle() {
69        return mTextView.getText();
70    }
71
72    /**
73     * Sets the badge drawable.
74     * If non-null, the drawable is displayed instead of the title text.
75     */
76    public void setBadgeDrawable(Drawable drawable) {
77        mBadgeView.setImageDrawable(drawable);
78        if (drawable != null) {
79            mBadgeView.setVisibility(View.VISIBLE);
80            mTextView.setVisibility(View.GONE);
81        } else {
82            mBadgeView.setVisibility(View.GONE);
83            mTextView.setVisibility(View.VISIBLE);
84        }
85    }
86
87    /**
88     * Returns the badge drawable.
89     */
90    public Drawable getBadgeDrawable() {
91        return mBadgeView.getDrawable();
92    }
93
94    /**
95     * Sets the listener to be called when the search affordance is clicked.
96     */
97    public void setOnSearchClickedListener(View.OnClickListener listener) {
98        mSearchOrbView.setOnOrbClickedListener(listener);
99    }
100
101    /**
102     *  Returns the view for the search affordance.
103     */
104    public View getSearchAffordanceView() {
105        return mSearchOrbView;
106    }
107
108    /**
109     * Sets the {@link SearchOrbView.Colors} used to draw the search affordance.
110     */
111    public void setSearchAffordanceColors(SearchOrbView.Colors colors) {
112        mSearchOrbView.setOrbColors(colors);
113    }
114
115    /**
116     * Returns the {@link SearchOrbView.Colors} used to draw the search affordance.
117     */
118    public SearchOrbView.Colors getSearchAffordanceColors() {
119        return mSearchOrbView.getOrbColors();
120    }
121}
122