TitleView.java revision fb413100a0ce8c0b68a1c5f6dd9cee5e0f981700
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.attr.browseTitleViewStyle); 45 } 46 47 public TitleView(Context context, AttributeSet attrs, int defStyleAttr) { 48 super(context, attrs, defStyleAttr); 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 defStyleAttr, 0); 59 60 int defColor = context.getResources().getColor(R.color.lb_default_search_color); 61 int color = a.getColor(R.styleable.lbTitleView_searchAffordanceColor, defColor); 62 a.recycle(); 63 mSearchOrbView.setOrbColor(color); 64 65 setClipToPadding(false); 66 setClipChildren(false); 67 } 68 69 /** 70 * Sets the title text. 71 */ 72 public void setTitle(String titleText) { 73 mTextView.setText(titleText); 74 } 75 76 /** 77 * Returns the title text. 78 */ 79 public CharSequence getTitle() { 80 return mTextView.getText(); 81 } 82 83 /** 84 * Sets the badge drawable. 85 * If non-null, the drawable is displayed instead of the title text. 86 */ 87 public void setBadgeDrawable(Drawable drawable) { 88 mBadgeView.setImageDrawable(drawable); 89 if (drawable != null) { 90 mBadgeView.setVisibility(View.VISIBLE); 91 mTextView.setVisibility(View.GONE); 92 } else { 93 mBadgeView.setVisibility(View.GONE); 94 mTextView.setVisibility(View.VISIBLE); 95 } 96 } 97 98 /** 99 * Returns the badge drawable. 100 */ 101 public Drawable getBadgeDrawable() { 102 return mBadgeView.getDrawable(); 103 } 104 105 /** 106 * Sets the listener to be called when the search affordance is clicked. 107 */ 108 public void setOnSearchClickedListener(View.OnClickListener listener) { 109 mSearchOrbView.setOnOrbClickedListener(listener); 110 } 111 112 /** 113 * Returns the view for the search affordance. 114 */ 115 public View getSearchAffordanceView() { 116 return mSearchOrbView; 117 } 118 119 /** 120 * Sets the color used to draw the search affordance. 121 */ 122 public void setSearchAffordanceColor(int color) { 123 mSearchOrbView.setOrbColor(color); 124 } 125 126 /** 127 * Returns the color used to draw the search affordance. 128 */ 129 public int getSearchAffordanceColor() { 130 return mSearchOrbView.getOrbColor(); 131 } 132} 133