1 /* 2 * Copyright (C) 2014 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.settings; 18 19 import android.support.v17.leanback.widget.ArrayObjectAdapter; 20 import android.support.v17.leanback.widget.HeaderItem; 21 import android.support.v17.leanback.widget.ListRow; 22 import android.support.v17.leanback.widget.ClassPresenterSelector; 23 import android.util.SparseArray; 24 25 import java.util.ArrayList; 26 27 public abstract class BrowseInfoBase implements BrowseInfoFactory { 28 protected final SparseArray<ArrayObjectAdapter> mRows = new SparseArray<ArrayObjectAdapter>(); 29 protected final ArrayList<HeaderItem> mHeaderItems = new ArrayList<HeaderItem>(); 30 private final ClassPresenterSelector mPresenterSelector = new ClassPresenterSelector(); 31 BrowseInfoBase()32 public BrowseInfoBase() { 33 mPresenterSelector.addClassPresenter(MenuItem.class, new MenuItemPresenter()); 34 } 35 36 @Override getRows()37 public ArrayObjectAdapter getRows() { 38 ArrayObjectAdapter rows = new ArrayObjectAdapter(); 39 40 for (int i = 0, size = mHeaderItems.size(); i < size; i++) { 41 HeaderItem headerItem = mHeaderItems.get(i); 42 ArrayObjectAdapter adapter = mRows.get((int) headerItem.getId()); 43 adapter.setPresenterSelector(mPresenterSelector); 44 rows.add(new ListRow(headerItem, adapter)); 45 } 46 return rows; 47 } 48 49 } 50