Home | History | Annotate | Download | only in menu
      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 
     42     public ActionCardView(Context context) {
     43         this(context, null);
     44     }
     45 
     46     public ActionCardView(Context context, AttributeSet attrs) {
     47         this(context, attrs, 0);
     48     }
     49 
     50     public ActionCardView(Context context, AttributeSet attrs, int defStyle) {
     51         super(context, attrs, defStyle);
     52     }
     53 
     54     @Override
     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
     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             mIconView.setAlpha(OPACITY_ENABLED);
     73             mLabelView.setAlpha(OPACITY_ENABLED);
     74             mStateView.setAlpha(OPACITY_ENABLED);
     75         } else {
     76             setEnabled(false);
     77             mIconView.setAlpha(OPACITY_DISABLED);
     78             mLabelView.setAlpha(OPACITY_DISABLED);
     79             mStateView.setAlpha(OPACITY_DISABLED);
     80         }
     81     }
     82 
     83     @Override
     84     public void onSelected() {
     85         if (DEBUG) {
     86             Log.d(TAG, "onSelected: action=" + mLabelView.getText());
     87         }
     88     }
     89 
     90     @Override
     91     public void onDeselected() {
     92         if (DEBUG) {
     93             Log.d(TAG, "onDeselected: action=" + mLabelView.getText());
     94         }
     95     }
     96 
     97     @Override
     98     public void onRecycled() { }
     99 }
    100