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