public class

MediaPlaybackTemplate

extends java.lang.Object

implements Template

 java.lang.Object

↳androidx.car.app.media.model.MediaPlaybackTemplate

Gradle dependencies

compile group: 'androidx.car.app', name: 'app', version: '1.7.0-beta01'

  • groupId: androidx.car.app
  • artifactId: app
  • version: 1.7.0-beta01

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

Overview

A template representing content to display for media playback.

Template Requirement

A pre requisite for using this template is the usage of MediaPlaybackManager.registerMediaPlaybackToken(MediaSessionCompat.Token).

Summary

Methods
public booleanequals(java.lang.Object other)

public HeadergetHeader()

Returns the Header to display in this template or not to display one if it is null.

public inthashCode()

public java.lang.StringtoString()

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

Methods

public Header getHeader()

Returns the Header to display in this template or not to display one if it is null.

public java.lang.String toString()

public int hashCode()

public boolean equals(java.lang.Object other)

Source

/*
 * Copyright 2024 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.media.model;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.annotations.CarProtocol;
import androidx.car.app.annotations.ExperimentalCarApi;
import androidx.car.app.annotations.KeepFields;
import androidx.car.app.annotations.RequiresCarApi;
import androidx.car.app.media.MediaPlaybackManager;
import androidx.car.app.model.Header;
import androidx.car.app.model.Template;

import java.util.Objects;

/**
 * A template representing content to display for media playback.
 *
 * <h4>Template Requirement</h4>
 *
 * A pre requisite for using this template is the usage of {@link
 * MediaPlaybackManager#registerMediaPlaybackToken}.
 */
@ExperimentalCarApi
@RequiresCarApi(8)
@CarProtocol
@KeepFields
public class MediaPlaybackTemplate implements Template {
    @Nullable
    private final Header mHeader;

    /**
     * Returns the {@link Header} to display in this template or not to display one if it is {@code
     * null}.
     */
    @Nullable
    public Header getHeader() {
        return mHeader;
    }

    @NonNull
    @Override
    public String toString() {
        return "MediaPlaybackTemplate";
    }

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

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

        return Objects.equals(mHeader, otherTemplate.mHeader);
    }

    /** Constructs an empty instance, used by serialization code. */
    private MediaPlaybackTemplate() {
        mHeader = null;
    }

    MediaPlaybackTemplate(Builder builder) {
        mHeader = builder.mHeader;
    }

    /** Builder for the {@link MediaPlaybackTemplate} */
    @ExperimentalCarApi
    public static final class Builder {
        @Nullable
        Header mHeader;

        /**
         * Sets the {@link Header} for this template or {code null} to not display a {@link
         * Header}.
         *
         * <p>Defaults to {@code null}, which means header is not displayed.
         */
        @NonNull
        public MediaPlaybackTemplate.Builder setHeader(@Nullable Header header) {
            this.mHeader = header;
            return this;
        }

        /** Constructs the template defined by this builder. */
        @NonNull
        public MediaPlaybackTemplate build() {
            return new MediaPlaybackTemplate(this);
        }

        /** Creates a default {@link Builder}. */
        public Builder() {};

        /** Creates a new {@link Builder}, populated from the input {@link MediaPlaybackTemplate} */
        public Builder(@NonNull MediaPlaybackTemplate template) {
            mHeader = template.getHeader();
        }
    }
}