1 /* 2 * Copyright (C) 2020 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 package android.car.input; 17 18 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 19 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.car.annotation.AddedInOrBefore; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 27 import com.android.car.internal.util.AnnotationValidations; 28 import com.android.car.internal.util.DataClass; 29 30 import java.util.Arrays; 31 32 /** 33 * {@code Parcelable} containing rotary input event. 34 * 35 * <p>A rotary input event can be either clockwise or counterclockwise and can contain more than 1 36 * click. Each click has its own event time. 37 * 38 * @hide 39 */ 40 @SystemApi 41 @DataClass( 42 genEqualsHashCode = true, 43 genAidl = true) 44 public final class RotaryEvent implements Parcelable { 45 /** 46 * Represents the type of rotary event. This indicates which knob was rotated. For example, it 47 * can be {@link CarInputManager#INPUT_TYPE_ROTARY_NAVIGATION}. 48 */ 49 @CarInputManager.InputTypeEnum 50 private final int mInputType; 51 52 /** 53 * Indicates if the event is clockwise (={@code true}) or counterclockwise (={@code false}). 54 */ 55 private final boolean mClockwise; 56 57 /** 58 * Stores the event times of all clicks. Time used is uptime in milliseconds. 59 * See {@link android.os.SystemClock#uptimeMillis()} for the definition of the time. 60 * 61 * <p>Timestamps are guaranteed to be monotonically increasing. If the input device cannot 62 * capture timestamps for each click, all the timestamps will be the same. 63 */ 64 @NonNull 65 private final long[] mUptimeMillisForClicks; 66 67 /** 68 * Returns the number of clicks contained in this event. 69 */ 70 @AddedInOrBefore(majorVersion = 33) getNumberOfClicks()71 public int getNumberOfClicks() { 72 return mUptimeMillisForClicks.length; 73 } 74 75 /** 76 * Returns the event time for the requested {@code clickIndex}. The time is recorded as 77 * {@link android.os.SystemClock#uptimeMillis()}. 78 * 79 * @param clickIndex Index of click to check the time. It should be in the range of 0 to 80 * {@code getNumberOfClicks() - 1}. 81 * 82 * @return Event time 83 */ 84 @AddedInOrBefore(majorVersion = 33) getUptimeMillisForClick(int clickIndex)85 public long getUptimeMillisForClick(int clickIndex) { 86 return mUptimeMillisForClicks[clickIndex]; 87 } 88 89 @Override 90 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 91 @AddedInOrBefore(majorVersion = 33) toString()92 public String toString() { 93 return new StringBuilder(128) 94 .append("RotaryEvent{") 95 .append("mInputType:") 96 .append(mInputType) 97 .append(",mClockwise:") 98 .append(mClockwise) 99 .append(",mUptimeMillisForClicks:") 100 .append(Arrays.toString(mUptimeMillisForClicks)) 101 .append("}") 102 .toString(); 103 } 104 105 106 107 // Code below generated by codegen v1.0.23. 108 // 109 // DO NOT MODIFY! 110 // CHECKSTYLE:OFF Generated code 111 // 112 // To regenerate run: 113 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/input/RotaryEvent.java 114 // 115 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 116 // Settings > Editor > Code Style > Formatter Control 117 //@formatter:off 118 119 120 /** 121 * Creates a new RotaryEvent. 122 * 123 * @param inputType 124 * Represents the type of rotary event. This indicates which knob was rotated. For example, it 125 * can be {@link CarInputManager#INPUT_TYPE_ROTARY_NAVIGATION}. 126 * @param clockwise 127 * Indicates if the event is clockwise (={@code true}) or counterclockwise (={@code false}). 128 * @param uptimeMillisForClicks 129 * Stores the event times of all clicks. Time used is uptime in milliseconds. 130 * See {@link android.os.SystemClock#uptimeMillis()} for the definition of the time. 131 * 132 * <p>Timestamps are guaranteed to be monotonically increasing. If the input device cannot 133 * capture timestamps for each click, all the timestamps will be the same. 134 */ 135 @DataClass.Generated.Member RotaryEvent( @arInputManager.InputTypeEnum int inputType, boolean clockwise, @NonNull long[] uptimeMillisForClicks)136 public RotaryEvent( 137 @CarInputManager.InputTypeEnum int inputType, 138 boolean clockwise, 139 @NonNull long[] uptimeMillisForClicks) { 140 this.mInputType = inputType; 141 AnnotationValidations.validate( 142 CarInputManager.InputTypeEnum.class, null, mInputType); 143 this.mClockwise = clockwise; 144 this.mUptimeMillisForClicks = uptimeMillisForClicks; 145 AnnotationValidations.validate( 146 NonNull.class, null, mUptimeMillisForClicks); 147 148 // onConstructed(); // You can define this method to get a callback 149 } 150 151 /** 152 * Represents the type of rotary event. This indicates which knob was rotated. For example, it 153 * can be {@link CarInputManager#INPUT_TYPE_ROTARY_NAVIGATION}. 154 */ 155 @DataClass.Generated.Member 156 @AddedInOrBefore(majorVersion = 33) getInputType()157 public @CarInputManager.InputTypeEnum int getInputType() { 158 return mInputType; 159 } 160 161 /** 162 * Indicates if the event is clockwise (={@code true}) or counterclockwise (={@code false}). 163 */ 164 @DataClass.Generated.Member 165 @AddedInOrBefore(majorVersion = 33) isClockwise()166 public boolean isClockwise() { 167 return mClockwise; 168 } 169 170 /** 171 * Stores the event times of all clicks. Time used is uptime in milliseconds. 172 * See {@link android.os.SystemClock#uptimeMillis()} for the definition of the time. 173 * 174 * <p>Timestamps are guaranteed to be monotonically increasing. If the input device cannot 175 * capture timestamps for each click, all the timestamps will be the same. 176 */ 177 @DataClass.Generated.Member 178 @AddedInOrBefore(majorVersion = 33) getUptimeMillisForClicks()179 public @NonNull long[] getUptimeMillisForClicks() { 180 return mUptimeMillisForClicks; 181 } 182 183 @Override 184 @DataClass.Generated.Member 185 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 186 @AddedInOrBefore(majorVersion = 33) equals(@ndroid.annotation.Nullable Object o)187 public boolean equals(@android.annotation.Nullable Object o) { 188 // You can override field equality logic by defining either of the methods like: 189 // boolean fieldNameEquals(RotaryEvent other) { ... } 190 // boolean fieldNameEquals(FieldType otherValue) { ... } 191 192 if (this == o) return true; 193 if (o == null || getClass() != o.getClass()) return false; 194 @SuppressWarnings("unchecked") 195 RotaryEvent that = (RotaryEvent) o; 196 //noinspection PointlessBooleanExpression 197 return true 198 && mInputType == that.mInputType 199 && mClockwise == that.mClockwise 200 && Arrays.equals(mUptimeMillisForClicks, that.mUptimeMillisForClicks); 201 } 202 203 @Override 204 @DataClass.Generated.Member 205 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 206 @AddedInOrBefore(majorVersion = 33) hashCode()207 public int hashCode() { 208 // You can override field hashCode logic by defining methods like: 209 // int fieldNameHashCode() { ... } 210 211 int _hash = 1; 212 _hash = 31 * _hash + mInputType; 213 _hash = 31 * _hash + Boolean.hashCode(mClockwise); 214 _hash = 31 * _hash + Arrays.hashCode(mUptimeMillisForClicks); 215 return _hash; 216 } 217 218 @Override 219 @DataClass.Generated.Member 220 @AddedInOrBefore(majorVersion = 33) writeToParcel(@onNull Parcel dest, int flags)221 public void writeToParcel(@NonNull Parcel dest, int flags) { 222 // You can override field parcelling by defining methods like: 223 // void parcelFieldName(Parcel dest, int flags) { ... } 224 225 byte flg = 0; 226 if (mClockwise) flg |= 0x2; 227 dest.writeByte(flg); 228 dest.writeInt(mInputType); 229 dest.writeLongArray(mUptimeMillisForClicks); 230 } 231 232 @Override 233 @DataClass.Generated.Member 234 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 235 @AddedInOrBefore(majorVersion = 33) describeContents()236 public int describeContents() { return 0; } 237 238 /** @hide */ 239 @SuppressWarnings({"unchecked", "RedundantCast"}) 240 @DataClass.Generated.Member RotaryEvent(@onNull Parcel in)241 /* package-private */ RotaryEvent(@NonNull Parcel in) { 242 // You can override field unparcelling by defining methods like: 243 // static FieldType unparcelFieldName(Parcel in) { ... } 244 245 byte flg = in.readByte(); 246 boolean clockwise = (flg & 0x2) != 0; 247 int inputType = in.readInt(); 248 long[] uptimeMillisForClicks = in.createLongArray(); 249 250 this.mInputType = inputType; 251 AnnotationValidations.validate( 252 CarInputManager.InputTypeEnum.class, null, mInputType); 253 this.mClockwise = clockwise; 254 this.mUptimeMillisForClicks = uptimeMillisForClicks; 255 AnnotationValidations.validate( 256 NonNull.class, null, mUptimeMillisForClicks); 257 258 // onConstructed(); // You can define this method to get a callback 259 } 260 261 @DataClass.Generated.Member 262 @AddedInOrBefore(majorVersion = 33) 263 public static final @NonNull Parcelable.Creator<RotaryEvent> CREATOR 264 = new Parcelable.Creator<RotaryEvent>() { 265 @Override 266 public RotaryEvent[] newArray(int size) { 267 return new RotaryEvent[size]; 268 } 269 270 @Override 271 public RotaryEvent createFromParcel(@NonNull Parcel in) { 272 return new RotaryEvent(in); 273 } 274 }; 275 276 @DataClass.Generated( 277 time = 1628099164166L, 278 codegenVersion = "1.0.23", 279 sourceFile = "packages/services/Car/car-lib/src/android/car/input/RotaryEvent.java", 280 inputSignatures = "private final @android.car.input.CarInputManager.InputTypeEnum int mInputType\nprivate final boolean mClockwise\nprivate final @android.annotation.NonNull long[] mUptimeMillisForClicks\npublic int getNumberOfClicks()\npublic long getUptimeMillisForClick(int)\npublic @java.lang.Override @com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport java.lang.String toString()\nclass RotaryEvent extends java.lang.Object implements [android.os.Parcelable]\n@com.android.car.internal.util.DataClass(genEqualsHashCode=true, genAidl=true)") 281 @Deprecated 282 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) __metadata()283 private void __metadata() {} 284 285 286 //@formatter:on 287 // End of generated code 288 289 } 290