public final class

SectionedItemList

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.SectionedItemList

Gradle dependencies

compile group: 'androidx.car.app', name: 'app', version: '1.2.0-rc01'

  • groupId: androidx.car.app
  • artifactId: app
  • version: 1.2.0-rc01

Artifact androidx.car.app:app:1.2.0-rc01 it located at Google repository (https://maven.google.com/)

Overview

Represents an ItemList that is contained inside a section, for internal use only.

Summary

Methods
public static SectionedItemListcreate(ItemList itemList, java.lang.CharSequence sectionHeader)

Creates an instance of a SectionedItemList with the given itemList and sectionHeader.

public booleanequals(java.lang.Object other)

public CarTextgetHeader()

Returns the title of the section.

public ItemListgetItemList()

Returns the ItemList for the section.

public inthashCode()

public java.lang.StringtoString()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Methods

public static SectionedItemList create(ItemList itemList, java.lang.CharSequence sectionHeader)

Creates an instance of a SectionedItemList with the given itemList and sectionHeader.

Only DistanceSpans and DurationSpans are supported in the section header.

public ItemList getItemList()

Returns the ItemList for the section.

public CarText getHeader()

Returns the title of the section.

public java.lang.String toString()

public int hashCode()

public boolean equals(java.lang.Object other)

Source

/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.car.app.model;

import static java.util.Objects.requireNonNull;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.annotations.CarProtocol;
import androidx.car.app.model.constraints.CarTextConstraints;

import java.util.Objects;

/**
 * Represents an {@link ItemList} that is contained inside a section, for internal use only.
 */
@CarProtocol
public final class SectionedItemList {
    @Keep
    @Nullable
    private final ItemList mItemList;
    @Keep
    @Nullable
    private final CarText mHeader;

    /**
     * Creates an instance of a {@link SectionedItemList} with the given {@code itemList} and
     * {@code sectionHeader}.
     *
     * <p>Only {@link DistanceSpan}s and {@link DurationSpan}s are supported in the section header.
     *
     * @throws IllegalArgumentException if {@code sectionHeader} contains unsupported spans
     */
    @NonNull
    public static SectionedItemList create(
            @NonNull ItemList itemList, @NonNull CharSequence sectionHeader) {
        CarText sectionHeaderText = CarText.create(requireNonNull(sectionHeader));
        CarTextConstraints.TEXT_ONLY.validateOrThrow(sectionHeaderText);
        return new SectionedItemList(requireNonNull(itemList), sectionHeaderText);
    }

    /** Returns the {@link ItemList} for the section. */
    @NonNull
    public ItemList getItemList() {
        return requireNonNull(mItemList);
    }

    /** Returns the title of the section. */
    @NonNull
    public CarText getHeader() {
        return requireNonNull(mHeader);
    }

    @Override
    @NonNull
    public String toString() {
        return "[ items: " + mItemList + ", has header: " + (mHeader != null) + "]";
    }

    @Override
    public int hashCode() {
        return Objects.hash(mItemList, mHeader);
    }

    @Override
    public boolean equals(@Nullable Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof SectionedItemList)) {
            return false;
        }
        SectionedItemList otherList = (SectionedItemList) other;

        return Objects.equals(mItemList, otherList.mItemList) && Objects.equals(mHeader,
                otherList.mHeader);
    }

    private SectionedItemList(@Nullable ItemList itemList, @Nullable CarText header) {
        mItemList = itemList;
        mHeader = header;
    }

    private SectionedItemList() {
        mItemList = null;
        mHeader = null;
    }
}