Alan Viverette | 3da604b | 2020-06-10 18:34:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.location; |
| 18 | |
| 19 | import android.annotation.FloatRange; |
| 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.SystemApi; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
| 25 | /** |
| 26 | * Holds the characteristics of the reflecting plane that a satellite signal has bounced from. |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
| 30 | @SystemApi |
| 31 | public final class GnssReflectingPlane implements Parcelable { |
| 32 | |
| 33 | /** Represents latitude in degrees of the reflecting plane */ |
| 34 | @FloatRange(from = -90.0f, to = 90.0f) |
| 35 | private final double mLatitudeDegrees; |
| 36 | /** Represents longitude in degrees of the reflecting plane. */ |
| 37 | @FloatRange(from = -180.0f, to = 180.0f) |
| 38 | private final double mLongitudeDegrees; |
| 39 | /** |
| 40 | * Represents altitude in meters above the WGS 84 reference ellipsoid of the reflection point in |
| 41 | * the plane |
| 42 | */ |
| 43 | @FloatRange(from = -1000.0f, to = 10000.0f) |
| 44 | private final double mAltitudeMeters; |
| 45 | |
| 46 | /** Represents azimuth clockwise from north of the reflecting plane in degrees. */ |
| 47 | @FloatRange(from = 0.0f, to = 360.0f) |
| 48 | private final double mAzimuthDegrees; |
| 49 | |
| 50 | private GnssReflectingPlane(Builder builder) { |
| 51 | mLatitudeDegrees = builder.mLatitudeDegrees; |
| 52 | mLongitudeDegrees = builder.mLongitudeDegrees; |
| 53 | mAltitudeMeters = builder.mAltitudeMeters; |
| 54 | mAzimuthDegrees = builder.mAzimuthDegrees; |
| 55 | } |
| 56 | |
| 57 | /** Gets the latitude in degrees of the reflecting plane. */ |
| 58 | @FloatRange(from = -90.0f, to = 90.0f) |
| 59 | public double getLatitudeDegrees() { |
| 60 | return mLatitudeDegrees; |
| 61 | } |
| 62 | |
| 63 | /** Gets the longitude in degrees of the reflecting plane. */ |
| 64 | @FloatRange(from = -180.0f, to = 180.0f) |
| 65 | public double getLongitudeDegrees() { |
| 66 | return mLongitudeDegrees; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Gets the altitude in meters above the WGS 84 reference ellipsoid of the reflecting point |
| 71 | * within the plane |
| 72 | */ |
| 73 | @FloatRange(from = -1000.0f, to = 10000.0f) |
| 74 | public double getAltitudeMeters() { |
| 75 | return mAltitudeMeters; |
| 76 | } |
| 77 | |
| 78 | /** Gets the azimuth clockwise from north of the reflecting plane in degrees. */ |
| 79 | @FloatRange(from = 0.0f, to = 360.0f) |
| 80 | public double getAzimuthDegrees() { |
| 81 | return mAzimuthDegrees; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int describeContents() { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | public static final Creator<GnssReflectingPlane> CREATOR = |
| 90 | new Creator<GnssReflectingPlane>() { |
| 91 | @Override |
| 92 | @NonNull |
| 93 | public GnssReflectingPlane createFromParcel(@NonNull Parcel parcel) { |
| 94 | GnssReflectingPlane reflectingPlane = |
| 95 | new Builder() |
| 96 | .setLatitudeDegrees(parcel.readDouble()) |
| 97 | .setLongitudeDegrees(parcel.readDouble()) |
| 98 | .setAltitudeMeters(parcel.readDouble()) |
| 99 | .setAzimuthDegrees(parcel.readDouble()) |
| 100 | .build(); |
| 101 | return reflectingPlane; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public GnssReflectingPlane[] newArray(int i) { |
| 106 | return new GnssReflectingPlane[i]; |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | @NonNull |
| 111 | @Override |
| 112 | public String toString() { |
| 113 | final String format = " %-29s = %s\n"; |
| 114 | StringBuilder builder = new StringBuilder("ReflectingPlane:\n"); |
| 115 | builder.append(String.format(format, "LatitudeDegrees = ", mLatitudeDegrees)); |
| 116 | builder.append(String.format(format, "LongitudeDegrees = ", mLongitudeDegrees)); |
| 117 | builder.append(String.format(format, "AltitudeMeters = ", mAltitudeMeters)); |
| 118 | builder.append(String.format(format, "AzimuthDegrees = ", mAzimuthDegrees)); |
| 119 | return builder.toString(); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void writeToParcel(@NonNull Parcel parcel, int flags) { |
| 124 | parcel.writeDouble(mLatitudeDegrees); |
| 125 | parcel.writeDouble(mLongitudeDegrees); |
| 126 | parcel.writeDouble(mAltitudeMeters); |
| 127 | parcel.writeDouble(mAzimuthDegrees); |
| 128 | } |
| 129 | |
| 130 | /** Builder for {@link GnssReflectingPlane} */ |
| 131 | public static final class Builder { |
| 132 | /** For documentation, see corresponding fields in {@link GnssReflectingPlane}. */ |
| 133 | private double mLatitudeDegrees; |
| 134 | private double mLongitudeDegrees; |
| 135 | private double mAltitudeMeters; |
| 136 | private double mAzimuthDegrees; |
| 137 | |
| 138 | /** Sets the latitude in degrees of the reflecting plane. */ |
| 139 | @NonNull public Builder setLatitudeDegrees( |
| 140 | @FloatRange(from = -90.0f, to = 90.0f) double latitudeDegrees) { |
| 141 | mLatitudeDegrees = latitudeDegrees; |
| 142 | return this; |
| 143 | } |
| 144 | |
| 145 | /** Sets the longitude in degrees of the reflecting plane. */ |
| 146 | @NonNull public Builder setLongitudeDegrees( |
| 147 | @FloatRange(from = -180.0f, to = 180.0f) double longitudeDegrees) { |
| 148 | mLongitudeDegrees = longitudeDegrees; |
| 149 | return this; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets the altitude in meters above the WGS 84 reference ellipsoid of the reflecting point |
| 154 | * within the plane |
| 155 | */ |
| 156 | @NonNull public Builder setAltitudeMeters( |
| 157 | @FloatRange(from = -1000.0f, to = 10000.0f) double altitudeMeters) { |
| 158 | mAltitudeMeters = altitudeMeters; |
| 159 | return this; |
| 160 | } |
| 161 | |
| 162 | /** Sets the azimuth clockwise from north of the reflecting plane in degrees. */ |
| 163 | @NonNull public Builder setAzimuthDegrees( |
| 164 | @FloatRange(from = 0.0f, to = 360.0f) double azimuthDegrees) { |
| 165 | mAzimuthDegrees = azimuthDegrees; |
| 166 | return this; |
| 167 | } |
| 168 | |
| 169 | /** Builds a {@link GnssReflectingPlane} object as specified by this builder. */ |
| 170 | @NonNull public GnssReflectingPlane build() { |
| 171 | return new GnssReflectingPlane(this); |
| 172 | } |
| 173 | } |
| 174 | } |