TitleView.java revision 731066a59e10ddc7bb6c95d0b91b3e0e11e10396
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.content.res.TypedArray; 18import android.graphics.drawable.Drawable; 19import android.support.v17.leanback.R; 20import android.util.AttributeSet; 21import android.util.TypedValue; 22import android.view.LayoutInflater; 23import android.view.View; 24import android.view.ViewGroup.MarginLayoutParams; 25import android.widget.FrameLayout; 26import android.widget.ImageView; 27import android.widget.TextView; 28 29/** 30 * Title view for a leanback fragment. 31 * @hide 32 */ 33public class TitleView extends FrameLayout { 34 35 private ImageView mBadgeView; 36 private TextView mTextView; 37 private SearchOrbView mSearchOrbView; 38 39 public TitleView(Context context) { 40 this(context, null); 41 } 42 43 public TitleView(Context context, AttributeSet attrs) { 44 this(context, attrs, R.style.Widget_Leanback_Title); 45 } 46 47 public TitleView(Context context, AttributeSet attrs, int defStyle) { 48 super(context, attrs, defStyle); 49 50 LayoutInflater inflater = LayoutInflater.from(context); 51 View rootView = inflater.inflate(R.layout.lb_title_view, this); 52 53 mBadgeView = (ImageView) rootView.findViewById(R.id.browse_badge); 54 mTextView = (TextView) rootView.findViewById(R.id.browse_title); 55 mSearchOrbView = (SearchOrbView) rootView.findViewById(R.id.browse_orb); 56 57 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.lbTitleView); 58 int color = a.getColor(R.styleable.lbTitleView_searchAffordanceColor, 0); 59 a.recycle(); 60 mSearchOrbView.setOrbColor(color); 61 62 setClipToPadding(false); 63 setClipChildren(false); 64 } 65 66 /** 67 * Sets the title text. 68 */ 69 public void setTitle(String titleText) { 70 mTextView.setText(titleText); 71 } 72 73 /** 74 * Returns the title text. 75 */ 76 public CharSequence getTitle() { 77 return mTextView.getText(); 78 } 79 80 /** 81 * Sets the badge drawable. 82 * If non-null, the drawable is displayed instead of the title text. 83 */ 84 public void setBadgeDrawable(Drawable drawable) { 85 mBadgeView.setImageDrawable(drawable); 86 if (drawable != null) { 87 mBadgeView.setVisibility(View.VISIBLE); 88 mTextView.setVisibility(View.GONE); 89 } else { 90 mBadgeView.setVisibility(View.GONE); 91 mTextView.setVisibility(View.VISIBLE); 92 } 93 } 94 95 /** 96 * Returns the badge drawable. 97 */ 98 public Drawable getBadgeDrawable() { 99 return mBadgeView.getDrawable(); 100 } 101 102 /** 103 * Sets the listener to be called when the search affordance is clicked. 104 */ 105 public void setOnSearchClickedListener(View.OnClickListener listener) { 106 mSearchOrbView.setOnOrbClickedListener(listener); 107 } 108 109 /** 110 * Returns the view for the search affordance. 111 */ 112 public View getSearchAffordanceView() { 113 return mSearchOrbView; 114 } 115 116 /** 117 * Sets the color used to draw the search affordance. 118 */ 119 public void setSearchAffordanceColor(int color) { 120 mSearchOrbView.setOrbColor(color); 121 } 122 123 /** 124 * Returns the color used to draw the search affordance. 125 */ 126 public int getSearchAffordanceColor() { 127 return mSearchOrbView.getOrbColor(); 128 } 129} 130