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