1 /* 2 * Copyright (C) 2015 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.text.TextUtils; 22 import android.util.AttributeSet; 23 import android.view.View; 24 import android.widget.TextView; 25 26 import com.android.tv.MainActivity; 27 import com.android.tv.R; 28 import com.android.tv.data.api.Channel; 29 30 public class InputBannerView extends InputBannerViewBase 31 implements TvTransitionManager.TransitionLayout { 32 33 private TextView mInputLabelTextView; 34 private TextView mSecondaryInputLabelTextView; 35 InputBannerView(Context context)36 public InputBannerView(Context context) { 37 super(context); 38 } 39 InputBannerView(Context context, AttributeSet attrs)40 public InputBannerView(Context context, AttributeSet attrs) { 41 super(context, attrs); 42 } 43 InputBannerView(Context context, AttributeSet attrs, int defStyle)44 public InputBannerView(Context context, AttributeSet attrs, int defStyle) { 45 super(context, attrs, defStyle); 46 } 47 48 @Override onFinishInflate()49 protected void onFinishInflate() { 50 super.onFinishInflate(); 51 mInputLabelTextView = findViewById(R.id.input_label); 52 mSecondaryInputLabelTextView = findViewById(R.id.secondary_input_label); 53 } 54 55 @Override updateLabel()56 public void updateLabel() { 57 MainActivity mainActivity = (MainActivity) getContext(); 58 Channel channel = mainActivity.getCurrentChannel(); 59 if (channel == null || !channel.isPassthrough()) { 60 return; 61 } 62 TvInputInfo input = 63 mainActivity.getTvInputManagerHelper().getTvInputInfo(channel.getInputId()); 64 CharSequence customLabel = input.loadCustomLabel(getContext()); 65 CharSequence label = input.loadLabel(getContext()); 66 if (TextUtils.isEmpty(customLabel) || customLabel.equals(label)) { 67 mInputLabelTextView.setText(label); 68 mSecondaryInputLabelTextView.setVisibility(View.GONE); 69 } else { 70 mInputLabelTextView.setText(customLabel); 71 mSecondaryInputLabelTextView.setText(label); 72 mSecondaryInputLabelTextView.setVisibility(View.VISIBLE); 73 } 74 } 75 } 76