• 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.menu;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.util.Log;
22 import android.widget.FrameLayout;
23 import android.widget.ImageView;
24 import android.widget.TextView;
25 
26 import com.android.tv.R;
27 
28 /**
29  * A view to render an item of TV options.
30  */
31 public class ActionCardView extends FrameLayout implements ItemListRowView.CardView<MenuAction> {
32     private static final String TAG = MenuView.TAG;
33     private static final boolean DEBUG = MenuView.DEBUG;
34 
35     private static final float OPACITY_DISABLED = 0.3f;
36     private static final float OPACITY_ENABLED = 1.0f;
37 
38     private ImageView mIconView;
39     private TextView mLabelView;
40     private TextView mStateView;
41 
ActionCardView(Context context)42     public ActionCardView(Context context) {
43         this(context, null);
44     }
45 
ActionCardView(Context context, AttributeSet attrs)46     public ActionCardView(Context context, AttributeSet attrs) {
47         this(context, attrs, 0);
48     }
49 
ActionCardView(Context context, AttributeSet attrs, int defStyle)50     public ActionCardView(Context context, AttributeSet attrs, int defStyle) {
51         super(context, attrs, defStyle);
52     }
53 
54     @Override
onFinishInflate()55     protected void onFinishInflate() {
56         super.onFinishInflate();
57         mIconView = (ImageView) findViewById(R.id.action_card_icon);
58         mLabelView = (TextView) findViewById(R.id.action_card_label);
59         mStateView = (TextView) findViewById(R.id.action_card_state);
60     }
61 
62     @Override
onBind(MenuAction action, boolean selected)63     public void onBind(MenuAction action, boolean selected) {
64         if (DEBUG) {
65             Log.d(TAG, "onBind: action=" + action.getActionName(getContext()));
66         }
67         mIconView.setImageDrawable(action.getDrawable(getContext()));
68         mLabelView.setText(action.getActionName(getContext()));
69         mStateView.setText(action.getActionDescription(getContext()));
70         if (action.isEnabled()) {
71             setEnabled(true);
72             setFocusable(true);
73             mIconView.setAlpha(OPACITY_ENABLED);
74             mLabelView.setAlpha(OPACITY_ENABLED);
75             mStateView.setAlpha(OPACITY_ENABLED);
76         } else {
77             setEnabled(false);
78             setFocusable(false);
79             mIconView.setAlpha(OPACITY_DISABLED);
80             mLabelView.setAlpha(OPACITY_DISABLED);
81             mStateView.setAlpha(OPACITY_DISABLED);
82         }
83     }
84 
85     @Override
onSelected()86     public void onSelected() {
87         if (DEBUG) {
88             Log.d(TAG, "onSelected: action=" + mLabelView.getText());
89         }
90     }
91 
92     @Override
onDeselected()93     public void onDeselected() {
94         if (DEBUG) {
95             Log.d(TAG, "onDeselected: action=" + mLabelView.getText());
96         }
97     }
98 
99     @Override
onRecycled()100     public void onRecycled() { }
101 }
102