public class

RequestReaders

extends java.lang.Object

 java.lang.Object

↳androidx.wear.tiles.readers.RequestReaders

Gradle dependencies

compile group: 'androidx.wear', name: 'wear-tiles', version: '1.0.0-alpha01'

  • groupId: androidx.wear
  • artifactId: wear-tiles
  • version: 1.0.0-alpha01

Artifact androidx.wear:wear-tiles:1.0.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Request readers for androidx.wear.tiles' Parcelable classes.

Summary

Methods
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

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.wear.tiles.readers;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;
import androidx.wear.tiles.ResourcesRequestData;
import androidx.wear.tiles.TileRequestData;
import androidx.wear.tiles.builders.StateBuilders.State;
import androidx.wear.tiles.proto.RequestProto;
import androidx.wear.tiles.protobuf.ExtensionRegistryLite;
import androidx.wear.tiles.protobuf.InvalidProtocolBufferException;
import androidx.wear.tiles.readers.DeviceParametersReaders.DeviceParameters;

import java.util.List;

/** Request readers for androidx.wear.tiles' Parcelable classes. */
public class RequestReaders {
    private RequestReaders() {}

    /** Reader for a {@link TileRequestData} instance. */
    public static class TileRequest {
        private final RequestProto.TileRequest mProto;
        private final int mTileId;

        private TileRequest(RequestProto.TileRequest proto, int tileId) {
            this.mProto = proto;
            this.mTileId = tileId;
        }

        /** Get the {@link State} that the tile should be built with. */
        @NonNull
        public State getState() {
            return State.fromProto(mProto.getState());
        }

        /** Get parameters describing the device requesting this tile. */
        @NonNull
        public DeviceParameters getDeviceParameters() {
            return new DeviceParameters(mProto.getDeviceParameters());
        }

        public int getTileId() {
            return mTileId;
        }

        /** @hide */
        @RestrictTo(Scope.LIBRARY)
        @NonNull
        public static TileRequest fromParcelable(@NonNull TileRequestData parcelable, int tileId) {
            try {
                return new TileRequest(
                        RequestProto.TileRequest.parseFrom(
                                parcelable.getContents(), ExtensionRegistryLite.getEmptyRegistry()),
                        tileId);
            } catch (InvalidProtocolBufferException ex) {
                throw new IllegalArgumentException(
                        "Passed TileRequestData did not contain a valid proto payload", ex);
            }
        }
    }

    /** Reader for a {@link ResourcesRequestData} instance. */
    public static class ResourcesRequest {
        private final RequestProto.ResourcesRequest mProto;
        private final int mTileId;

        private ResourcesRequest(@NonNull RequestProto.ResourcesRequest proto, int tileId) {
            this.mProto = proto;
            this.mTileId = tileId;
        }

        /** @hide */
        @RestrictTo(Scope.LIBRARY)
        @NonNull
        public static ResourcesRequest fromParcelable(
                @NonNull ResourcesRequestData parcelable, int tileId) {
            try {
                return new ResourcesRequest(
                        RequestProto.ResourcesRequest.parseFrom(
                                parcelable.getContents(), ExtensionRegistryLite.getEmptyRegistry()),
                        tileId);
            } catch (InvalidProtocolBufferException ex) {
                throw new IllegalArgumentException(
                        "Passed ResourcesRequestData did not contain a valid proto payload", ex);
            }
        }

        public int getTileId() {
            return mTileId;
        }

        /** Get the resource version requested by this {@link ResourcesRequestData}. */
        @NonNull
        public String getVersion() {
            return mProto.getVersion();
        }

        /**
         * Get the resource IDs requested by this {@link ResourcesRequestData}. May be empty, in
         * which case all resources should be returned.
         */
        @NonNull
        public List<String> getResourceIds() {
            return mProto.getResourceIdsList();
        }

        /** Get parameters describing the device requesting these resources. */
        @NonNull
        public DeviceParameters getDeviceParameters() {
            return new DeviceParameters(mProto.getDeviceParameters());
        }
    }
}