1/* 2 * Copyright (C) 2015 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 15package android.support.v17.leanback.supportleanbackshowcase.app.page; 16 17import android.content.Context; 18import android.graphics.drawable.Drawable; 19import android.support.v17.leanback.supportleanbackshowcase.R; 20import android.support.v17.leanback.widget.TitleViewAdapter; 21import android.util.AttributeSet; 22import android.view.LayoutInflater; 23import android.view.View; 24import android.widget.ImageView; 25import android.widget.RelativeLayout; 26import android.widget.TextView; 27 28/** 29 * Custom title view to be used in {@link android.support.v17.leanback.app.BrowseFragment}. 30 */ 31public class CustomTitleView extends RelativeLayout implements TitleViewAdapter.Provider { 32 private final TextView mTitleView; 33 private final ImageView mBadgeView; 34 35 private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() { 36 @Override 37 public View getSearchAffordanceView() { 38 return null; 39 } 40 41 @Override 42 public void setTitle(CharSequence titleText) { 43 CustomTitleView.this.setTitle(titleText); 44 } 45 46 @Override 47 public void setBadgeDrawable(Drawable drawable) { 48 CustomTitleView.this.setBadgeDrawable(drawable); 49 } 50 }; 51 52 public CustomTitleView(Context context) { 53 this(context, null); 54 } 55 56 public CustomTitleView(Context context, AttributeSet attrs) { 57 this(context, attrs, 0); 58 } 59 60 public CustomTitleView(Context context, AttributeSet attrs, int defStyle) { 61 super(context, attrs, defStyle); 62 View root = LayoutInflater.from(context).inflate(R.layout.custom_titleview, this); 63 mTitleView = (TextView) root.findViewById(R.id.title_tv); 64 mBadgeView = (ImageView)root.findViewById(R.id.title_badge_iv); 65 } 66 67 public void setTitle(CharSequence title) { 68 if (title != null) { 69 mTitleView.setText(title); 70 mTitleView.setVisibility(View.VISIBLE); 71 mBadgeView.setVisibility(View.GONE); 72 } 73 } 74 75 76 public void setBadgeDrawable(Drawable drawable) { 77 if (drawable != null) { 78 mTitleView.setVisibility(View.GONE); 79 mBadgeView.setImageDrawable(drawable); 80 mBadgeView.setVisibility(View.VISIBLE); 81 } 82 } 83 84 @Override 85 public TitleViewAdapter getTitleViewAdapter() { 86 return mTitleViewAdapter; 87 } 88} 89