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 = (TextView) findViewById(R.id.title);
46        mDescriptionView = (TextView) findViewById(R.id.description);
47    }
48
49    public final CharSequence getTitle() {
50        return mTitleView.getText();
51    }
52
53    public final void setTitle(CharSequence text) {
54        if (!TextUtils.isEmpty(text)) {
55            mTitleView.setText(text);
56            mTitleView.setVisibility(View.VISIBLE);
57        } else {
58            mTitleView.setVisibility(View.GONE);
59        }
60    }
61
62    public final CharSequence getDescription() {
63        return mDescriptionView.getText();
64    }
65
66    public final void setDescription(CharSequence text) {
67        if (!TextUtils.isEmpty(text)) {
68            mDescriptionView.setText(text);
69            mDescriptionView.setVisibility(View.VISIBLE);
70        } else {
71            mDescriptionView.setVisibility(View.GONE);
72        }
73    }
74}
75