1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tv.ui;
18 
19 import android.content.Context;
20 import android.media.tv.TvInputInfo;
21 import android.util.AttributeSet;
22 import android.widget.FrameLayout;
23 import android.widget.ImageView;
24 import android.widget.TextView;
25 
26 import com.android.tv.R;
27 
28 public class EmptyInputStatusBlockView extends FrameLayout {
29     private ImageView mEmptyInputStatusIcon;
30     private TextView mEmptyInputTitleTextView;
31 
EmptyInputStatusBlockView(Context context)32     public EmptyInputStatusBlockView(Context context) {
33         this(context, null, 0);
34     }
35 
EmptyInputStatusBlockView(Context context, AttributeSet attrs)36     public EmptyInputStatusBlockView(Context context, AttributeSet attrs) {
37         this(context, attrs, 0);
38     }
39 
EmptyInputStatusBlockView(Context context, AttributeSet attrs, int defStyle)40     public EmptyInputStatusBlockView(Context context, AttributeSet attrs, int defStyle) {
41         super(context, attrs, defStyle);
42         inflate(context, R.layout.empty_input_status_block, this);
43     }
44 
45     @Override
onFinishInflate()46     protected void onFinishInflate() {
47         super.onFinishInflate();
48 
49         mEmptyInputStatusIcon = findViewById(R.id.empty_input_status_icon);
50         mEmptyInputTitleTextView = findViewById(R.id.empty_input_status_title_text);
51     }
52 
setIconAndLabelByInputInfo(TvInputInfo inputInfo)53     public void setIconAndLabelByInputInfo(TvInputInfo inputInfo) {
54         CharSequence label = inputInfo.loadLabel(getContext());
55         String title = getResources().getString(R.string.empty_input_status_title_format, label);
56         mEmptyInputTitleTextView.setText(title);
57 
58         if (inputInfo.isPassthroughInput()) {
59             mEmptyInputStatusIcon.setImageDrawable(
60                     getResources().getDrawable(R.drawable.ic_empty_input_hdmi, null)
61             );
62         } else {
63             mEmptyInputStatusIcon.setImageDrawable(
64                     getResources().getDrawable(R.drawable.ic_empty_input_tuner, null)
65             );
66         }
67     }
68 }
69