1 /*
2  * Copyright (C) 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.util.Log;
23 import android.widget.TextView;
24 
25 import com.android.tv.MainActivity;
26 import com.android.tv.R;
27 import com.android.tv.data.StreamInfo;
28 import com.android.tv.data.api.Channel;
29 
30 public class InputBannerViewV2 extends InputBannerViewBase
31         implements TvTransitionManager.TransitionLayout {
32     private static final String TAG = "InputBannerViewV2";
33 
34     private TextView mInputLabelTextView;
InputBannerViewV2(Context context)35     public InputBannerViewV2(Context context) {
36         super(context);
37     }
38 
InputBannerViewV2(Context context, AttributeSet attrs)39     public InputBannerViewV2(Context context, AttributeSet attrs) {
40         super(context, attrs);
41     }
42 
InputBannerViewV2(Context context, AttributeSet attrs, int defStyle)43     public InputBannerViewV2(Context context, AttributeSet attrs, int defStyle) {
44         super(context, attrs, defStyle);
45     }
46 
47     @Override
onFinishInflate()48     protected void onFinishInflate() {
49         super.onFinishInflate();
50         mInputLabelTextView = findViewById(R.id.input_label);
51     }
52 
53     @Override
updateLabel()54     public void updateLabel() {
55         MainActivity mainActivity = (MainActivity) getContext();
56         Channel channel = mainActivity.getCurrentChannel();
57         if (channel == null || !channel.isPassthrough()) {
58             return;
59         }
60 
61         TvInputInfo input =
62                 mainActivity.getTvInputManagerHelper().getTvInputInfo(channel.getInputId());
63         if (input == null) {
64             Log.e(TAG, "unable to get TvInputInfo of id " + channel.getInputId());
65             return;
66         }
67 
68         updateInputLabel(input);
69     }
70 
updateInputLabel(TvInputInfo input)71     private void updateInputLabel(TvInputInfo input) {
72         CharSequence customLabel = input.loadCustomLabel(getContext());
73         CharSequence label = input.loadLabel(getContext());
74 
75         if (customLabel == null) {
76             mInputLabelTextView.setText(label);
77         } else {
78             String inputLabel = getResources().getString(
79                     R.string.input_banner_v2_input_label_format, label, customLabel);
80             mInputLabelTextView.setText(inputLabel);
81         }
82 
83     }
84 }
85