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 
     21 import com.android.tv.R;
     22 import com.android.tv.menu.ItemListRowView.ItemListAdapter;
     23 
     24 /**
     25  * A menu item which is used to represents the list of the items.
     26  * A list will be displayed by a HorizontalGridView with cards, so an adapter
     27  * for the GridView is necessary.
     28  */
     29 @SuppressWarnings("rawtypes")
     30 public class ItemListRow extends MenuRow {
     31     private ItemListAdapter mAdapter;
     32 
     33     public ItemListRow(Context context, Menu menu, int titleResId, int itemHeightResId,
     34             ItemListAdapter adapter) {
     35         this(context, menu, context.getString(titleResId), itemHeightResId, adapter);
     36     }
     37 
     38     public ItemListRow(Context context, Menu menu, String title, int itemHeightResId,
     39             ItemListAdapter adapter) {
     40         super(context, menu, title, itemHeightResId);
     41         mAdapter = adapter;
     42     }
     43 
     44     /**
     45      * Returns the adapter.
     46      */
     47     public ItemListAdapter<?> getAdapter() {
     48         return mAdapter;
     49     }
     50 
     51     public void setAdapter(ItemListAdapter<?> adapter) {
     52         mAdapter = adapter;
     53     }
     54 
     55     @Override
     56     public void update() {
     57         mAdapter.update();
     58     }
     59 
     60     @Override
     61     public boolean isVisible() {
     62         return mAdapter.getItemCount() > 0;
     63     }
     64 
     65     @Override
     66     public int getLayoutResId() {
     67         return R.layout.item_list;
     68     }
     69 
     70     @Override
     71     public String getId() {
     72         return this.getClass().getName();
     73     }
     74 }
     75