147520b68e50572a9775a662410c5aff8300c8784Craig Stout/*
247520b68e50572a9775a662410c5aff8300c8784Craig Stout * Copyright (C) 2014 The Android Open Source Project
347520b68e50572a9775a662410c5aff8300c8784Craig Stout *
447520b68e50572a9775a662410c5aff8300c8784Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
547520b68e50572a9775a662410c5aff8300c8784Craig Stout * in compliance with the License. You may obtain a copy of the License at
647520b68e50572a9775a662410c5aff8300c8784Craig Stout *
747520b68e50572a9775a662410c5aff8300c8784Craig Stout * http://www.apache.org/licenses/LICENSE-2.0
847520b68e50572a9775a662410c5aff8300c8784Craig Stout *
947520b68e50572a9775a662410c5aff8300c8784Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License
1047520b68e50572a9775a662410c5aff8300c8784Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1147520b68e50572a9775a662410c5aff8300c8784Craig Stout * or implied. See the License for the specific language governing permissions and limitations under
1247520b68e50572a9775a662410c5aff8300c8784Craig Stout * the License.
1347520b68e50572a9775a662410c5aff8300c8784Craig Stout */
1447520b68e50572a9775a662410c5aff8300c8784Craig Stoutpackage android.support.v17.leanback.widget;
1547520b68e50572a9775a662410c5aff8300c8784Craig Stout
1647520b68e50572a9775a662410c5aff8300c8784Craig Stout/**
17a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * A {@link Row} composed of a optional {@link HeaderItem}, and an {@link ObjectAdapter}
18a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout * describing the items in the list.
1947520b68e50572a9775a662410c5aff8300c8784Craig Stout */
2047520b68e50572a9775a662410c5aff8300c8784Craig Stoutpublic class ListRow extends Row {
2147520b68e50572a9775a662410c5aff8300c8784Craig Stout    private final ObjectAdapter mAdapter;
22ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    private CharSequence mContentDescription;
2347520b68e50572a9775a662410c5aff8300c8784Craig Stout
2447520b68e50572a9775a662410c5aff8300c8784Craig Stout    /**
25a00bada00bff4a58436a39472ab14ccb7a8f619dCraig Stout     * Returns the {@link ObjectAdapter} that represents a list of objects.
2647520b68e50572a9775a662410c5aff8300c8784Craig Stout     */
2747520b68e50572a9775a662410c5aff8300c8784Craig Stout    public final ObjectAdapter getAdapter() {
2847520b68e50572a9775a662410c5aff8300c8784Craig Stout        return mAdapter;
2947520b68e50572a9775a662410c5aff8300c8784Craig Stout    }
3047520b68e50572a9775a662410c5aff8300c8784Craig Stout
3147520b68e50572a9775a662410c5aff8300c8784Craig Stout    public ListRow(HeaderItem header, ObjectAdapter adapter) {
3247520b68e50572a9775a662410c5aff8300c8784Craig Stout        super(header);
3347520b68e50572a9775a662410c5aff8300c8784Craig Stout        mAdapter = adapter;
3447520b68e50572a9775a662410c5aff8300c8784Craig Stout        verify();
3547520b68e50572a9775a662410c5aff8300c8784Craig Stout    }
3647520b68e50572a9775a662410c5aff8300c8784Craig Stout
3747520b68e50572a9775a662410c5aff8300c8784Craig Stout    public ListRow(long id, HeaderItem header, ObjectAdapter adapter) {
3847520b68e50572a9775a662410c5aff8300c8784Craig Stout        super(id, header);
3947520b68e50572a9775a662410c5aff8300c8784Craig Stout        mAdapter = adapter;
4047520b68e50572a9775a662410c5aff8300c8784Craig Stout        verify();
4147520b68e50572a9775a662410c5aff8300c8784Craig Stout    }
4247520b68e50572a9775a662410c5aff8300c8784Craig Stout
4347520b68e50572a9775a662410c5aff8300c8784Craig Stout    public ListRow(ObjectAdapter adapter) {
4447520b68e50572a9775a662410c5aff8300c8784Craig Stout        super();
4547520b68e50572a9775a662410c5aff8300c8784Craig Stout        mAdapter = adapter;
4647520b68e50572a9775a662410c5aff8300c8784Craig Stout        verify();
4747520b68e50572a9775a662410c5aff8300c8784Craig Stout    }
4847520b68e50572a9775a662410c5aff8300c8784Craig Stout
4947520b68e50572a9775a662410c5aff8300c8784Craig Stout    private void verify() {
5047520b68e50572a9775a662410c5aff8300c8784Craig Stout        if (mAdapter == null) {
5147520b68e50572a9775a662410c5aff8300c8784Craig Stout            throw new IllegalArgumentException("ObjectAdapter cannot be null");
5247520b68e50572a9775a662410c5aff8300c8784Craig Stout        }
5347520b68e50572a9775a662410c5aff8300c8784Craig Stout    }
54ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu
55ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    /**
56ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * Returns content description for the ListRow.  By default it returns
57ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * {@link HeaderItem#getContentDescription()} or {@link HeaderItem#getName()},
58ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * unless {@link #setContentDescription(CharSequence)} was explicitly called.
59ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     *
60ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * @return Content description for the ListRow.
61ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     */
62ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    public CharSequence getContentDescription() {
63ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        if (mContentDescription != null) {
64ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu            return mContentDescription;
65ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        }
66ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        final HeaderItem headerItem = getHeaderItem();
67ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        if (headerItem != null) {
68ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu            CharSequence contentDescription = headerItem.getContentDescription();
69ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu            if (contentDescription != null) {
70ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu                return contentDescription;
71ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu            }
72ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu            return headerItem.getName();
73ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        }
74ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        return null;
75ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    }
76ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu
77ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    /**
78ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * Explicitly set content description for the ListRow, {@link #getContentDescription()} will
79ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * ignore values from HeaderItem.
80ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     *
81ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     * @param contentDescription Content description sets on the ListRow.
82ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu     */
83ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    public void setContentDescription(CharSequence contentDescription) {
84ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu        mContentDescription = contentDescription;
85ac30644710e427c77b9d1f20ae385590bdac6c60Dake Gu    }
8647520b68e50572a9775a662410c5aff8300c8784Craig Stout}
87