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