public final class

Accelerometer

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.hardware.info.Accelerometer

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

Information about car specific accelerometers available from the car hardware.

Summary

Constructors
publicAccelerometer(CarValue<java.util.List> forces)

Creates an Accelerometer with the given raw data.

Methods
public booleanequals(java.lang.Object other)

public CarValue<java.util.List>getForces()

Returns the raw accelerometer force data from the car sensor.

public inthashCode()

public java.lang.StringtoString()

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

Constructors

public Accelerometer(CarValue<java.util.List> forces)

Creates an Accelerometer with the given raw data.

Methods

public CarValue<java.util.List> getForces()

Returns the raw accelerometer force data from the car sensor.

Individual values can be Float.Nan if not reported. The array values consist of:

  • [0]: Acceleration including gravity on the x-axis
  • [1]: Acceleration including gravity on the y-axis
  • [2]: Acceleration including gravity on the z-axis

public java.lang.String toString()

public int hashCode()

public boolean equals(java.lang.Object other)

Source

/*
 * Copyright 2021 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.info;

import static java.util.Objects.requireNonNull;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.annotations.CarProtocol;
import androidx.car.app.annotations.RequiresCarApi;
import androidx.car.app.hardware.common.CarValue;
import androidx.car.app.annotations.KeepFields;

import java.util.List;
import java.util.Objects;

/** Information about car specific accelerometers available from the car hardware. */
@CarProtocol
@RequiresCarApi(3)
@KeepFields
public final class Accelerometer {
    @NonNull
    private final CarValue<List<Float>> mForces;

    /**
     * Returns the raw accelerometer force data from the car sensor.
     *
     * <p>Individual values can be {@code Float.Nan} if not reported. The array values consist of:
     * <ul>
     *     <li>[0]: Acceleration including gravity on the x-axis
     *     <li>[1]: Acceleration including gravity on the y-axis
     *     <li>[2]: Acceleration including gravity on the z-axis
     * </ul>
     */
    @NonNull
    public CarValue<List<Float>> getForces() {
        return mForces;
    }

    @Override
    @NonNull
    public String toString() {
        return "[ forces: " + mForces + " ]";
    }

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

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

        return Objects.equals(mForces, otherAccelerometer.mForces);
    }

    /**
     * Creates an {@link Accelerometer} with the given raw data.
     *
     * @throws NullPointerException if {@code forces} is {@code null}
     */
    public Accelerometer(@NonNull CarValue<List<Float>> forces) {
        mForces = requireNonNull(forces);
    }

    /** Constructs an empty instance, used by serialization code. */
    private Accelerometer() {
        mForces = CarValue.UNKNOWN_FLOAT_LIST;
    }
}