public final class

CarValueUtils

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.hardware.common.CarValueUtils

Gradle dependencies

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

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

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

Overview

Utility functions to work with AutomotiveCarInfo and AutomotiveCarClimate

Summary

Methods
public static CarValue<java.lang.Object>getCarValue(CarPropertyResponse<java.lang.Object> response)

Builds CarValue from an existing CarPropertyResponse.

public static CarValue<java.lang.Object>getCarValue(CarPropertyResponse<java.lang.Object> response, java.lang.Object value)

Gets a CarValue object from CarPropertyResponse

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

Methods

public static CarValue<java.lang.Object> getCarValue(CarPropertyResponse<java.lang.Object> response, java.lang.Object value)

Gets a CarValue object from CarPropertyResponse

public static CarValue<java.lang.Object> getCarValue(CarPropertyResponse<java.lang.Object> response)

Builds CarValue from an existing CarPropertyResponse.

Source

/*
 * Copyright 2022 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.hardware.common;

import static androidx.annotation.RestrictTo.Scope.LIBRARY;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import androidx.annotation.RestrictTo;
import androidx.car.app.annotations.ExperimentalCarApi;

import java.util.List;

/**
 * Utility functions to work with {@link androidx.car.app.hardware.info.AutomotiveCarInfo} and
 * {@link androidx.car.app.hardware.climate.AutomotiveCarClimate}
 *
 */
@RestrictTo(LIBRARY)
public final class CarValueUtils {
    /**
     * Gets a {@link androidx.car.app.hardware.common.CarValue} object from
     * {@link androidx.car.app.hardware.common.CarPropertyResponse}
     */
    @NonNull
    @OptIn(markerClass = ExperimentalCarApi.class)
    public static <T> CarValue<T> getCarValue(@NonNull CarPropertyResponse<?> response,
            @Nullable T value) {
        long timestampMillis = response.getTimestampMillis();
        int status = response.getStatus();
        List<CarZone> zones =  response.getCarZones();
        return new CarValue<>(value, timestampMillis, status, zones);
    }

    /**
     * Builds {@link CarValue} from an existing {@link CarPropertyResponse}.
     */
    @NonNull
    @OptIn(markerClass = ExperimentalCarApi.class)
    @SuppressWarnings("unchecked")
    public static <T> CarValue<T> getCarValue(@NonNull CarPropertyResponse<?> response) {
        return new CarValue<>((T) response.getValue(), response.getTimestampMillis(),
                response.getStatus());
    }

    private CarValueUtils() {
    }
}