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.support.v17.leanback.R; 18import android.text.TextUtils; 19import android.util.AttributeSet; 20import android.view.LayoutInflater; 21import android.view.View; 22import android.widget.LinearLayout; 23import android.widget.TextView; 24 25/** 26 * ListRowHoverCardView contains a title and description. 27 */ 28public final class ListRowHoverCardView extends LinearLayout { 29 30 private final TextView mTitleView; 31 private final TextView mDescriptionView; 32 33 public ListRowHoverCardView(Context context) { 34 this(context, null); 35 } 36 37 public ListRowHoverCardView(Context context, AttributeSet attrs) { 38 this(context, attrs, 0); 39 } 40 41 public ListRowHoverCardView(Context context, AttributeSet attrs, int defStyle) { 42 super(context, attrs, defStyle); 43 LayoutInflater inflater = LayoutInflater.from(context); 44 inflater.inflate(R.layout.lb_list_row_hovercard, this); 45 mTitleView = findViewById(R.id.title); 46 mDescriptionView = findViewById(R.id.description); 47 } 48 49 /** 50 * Returns the title text. 51 */ 52 public final CharSequence getTitle() { 53 return mTitleView.getText(); 54 } 55 56 /** 57 * Sets the title text. 58 */ 59 public final void setTitle(CharSequence text) { 60 if (!TextUtils.isEmpty(text)) { 61 mTitleView.setText(text); 62 mTitleView.setVisibility(View.VISIBLE); 63 } else { 64 mTitleView.setVisibility(View.GONE); 65 } 66 } 67 68 /** 69 * Returns the description text. 70 */ 71 public final CharSequence getDescription() { 72 return mDescriptionView.getText(); 73 } 74 75 /** 76 * Sets the description text. 77 */ 78 public final void setDescription(CharSequence text) { 79 if (!TextUtils.isEmpty(text)) { 80 mDescriptionView.setText(text); 81 mDescriptionView.setVisibility(View.VISIBLE); 82 } else { 83 mDescriptionView.setVisibility(View.GONE); 84 } 85 } 86} 87