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