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.LinearLayout; 25 import android.widget.TextView; 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 LinearLayout implements TvTransitionManager.TransitionLayout { 31 private final long mShowDurationMillis; 32 33 private final Runnable mHideRunnable = 34 () -> 35 ((MainActivity) getContext()) 36 .getOverlayManager() 37 .hideOverlays( 38 TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_DIALOG 39 | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_SIDE_PANELS 40 | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_PROGRAM_GUIDE 41 | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_MENU 42 | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_FRAGMENT); 43 private TextView mInputLabelTextView; 44 private TextView mSecondaryInputLabelTextView; 45 InputBannerView(Context context)46 public InputBannerView(Context context) { 47 this(context, null, 0); 48 } 49 InputBannerView(Context context, AttributeSet attrs)50 public InputBannerView(Context context, AttributeSet attrs) { 51 this(context, attrs, 0); 52 } 53 InputBannerView(Context context, AttributeSet attrs, int defStyle)54 public InputBannerView(Context context, AttributeSet attrs, int defStyle) { 55 super(context, attrs, defStyle); 56 mShowDurationMillis = 57 context.getResources().getInteger(R.integer.select_input_show_duration); 58 } 59 60 @Override onFinishInflate()61 protected void onFinishInflate() { 62 super.onFinishInflate(); 63 mInputLabelTextView = (TextView) findViewById(R.id.input_label); 64 mSecondaryInputLabelTextView = (TextView) findViewById(R.id.secondary_input_label); 65 } 66 updateLabel()67 public void updateLabel() { 68 MainActivity mainActivity = (MainActivity) getContext(); 69 Channel channel = mainActivity.getCurrentChannel(); 70 if (channel == null || !channel.isPassthrough()) { 71 return; 72 } 73 TvInputInfo input = 74 mainActivity.getTvInputManagerHelper().getTvInputInfo(channel.getInputId()); 75 CharSequence customLabel = input.loadCustomLabel(getContext()); 76 CharSequence label = input.loadLabel(getContext()); 77 if (TextUtils.isEmpty(customLabel) || customLabel.equals(label)) { 78 mInputLabelTextView.setText(label); 79 mSecondaryInputLabelTextView.setVisibility(View.GONE); 80 } else { 81 mInputLabelTextView.setText(customLabel); 82 mSecondaryInputLabelTextView.setText(label); 83 mSecondaryInputLabelTextView.setVisibility(View.VISIBLE); 84 } 85 } 86 87 @Override onEnterAction(boolean fromEmptyScene)88 public void onEnterAction(boolean fromEmptyScene) { 89 removeCallbacks(mHideRunnable); 90 postDelayed(mHideRunnable, mShowDurationMillis); 91 } 92 93 @Override onExitAction()94 public void onExitAction() { 95 removeCallbacks(mHideRunnable); 96 } 97 } 98