1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package android.support.v17.leanback.widget; 15 16/** 17 * A {@link Row} composed of a optional {@link HeaderItem}, and an {@link ObjectAdapter} 18 * describing the items in the list. 19 */ 20public class ListRow extends Row { 21 private final ObjectAdapter mAdapter; 22 private CharSequence mContentDescription; 23 24 /** 25 * Returns the {@link ObjectAdapter} that represents a list of objects. 26 */ 27 public final ObjectAdapter getAdapter() { 28 return mAdapter; 29 } 30 31 public ListRow(HeaderItem header, ObjectAdapter adapter) { 32 super(header); 33 mAdapter = adapter; 34 verify(); 35 } 36 37 public ListRow(long id, HeaderItem header, ObjectAdapter adapter) { 38 super(id, header); 39 mAdapter = adapter; 40 verify(); 41 } 42 43 public ListRow(ObjectAdapter adapter) { 44 super(); 45 mAdapter = adapter; 46 verify(); 47 } 48 49 private void verify() { 50 if (mAdapter == null) { 51 throw new IllegalArgumentException("ObjectAdapter cannot be null"); 52 } 53 } 54 55 /** 56 * Returns content description for the ListRow. By default it returns 57 * {@link HeaderItem#getContentDescription()} or {@link HeaderItem#getName()}, 58 * unless {@link #setContentDescription(CharSequence)} was explicitly called. 59 * 60 * @return Content description for the ListRow. 61 */ 62 public CharSequence getContentDescription() { 63 if (mContentDescription != null) { 64 return mContentDescription; 65 } 66 final HeaderItem headerItem = getHeaderItem(); 67 if (headerItem != null) { 68 CharSequence contentDescription = headerItem.getContentDescription(); 69 if (contentDescription != null) { 70 return contentDescription; 71 } 72 return headerItem.getName(); 73 } 74 return null; 75 } 76 77 /** 78 * Explicitly set content description for the ListRow, {@link #getContentDescription()} will 79 * ignore values from HeaderItem. 80 * 81 * @param contentDescription Content description sets on the ListRow. 82 */ 83 public void setContentDescription(CharSequence contentDescription) { 84 mContentDescription = contentDescription; 85 } 86} 87