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