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