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) toString()91 public String toString() { 92 return new StringBuilder(128) 93 .append("RotaryEvent{") 94 .append("mInputType:") 95 .append(mInputType) 96 .append(",mClockwise:") 97 .append(mClockwise) 98 .append(",mUptimeMillisForClicks:") 99 .append(Arrays.toString(mUptimeMillisForClicks)) 100 .append("}") 101 .toString(); 102 } 103 104 105 106 // Code below generated by codegen v1.0.23. 107 // 108 // DO NOT MODIFY! 109 // CHECKSTYLE:OFF Generated code 110 // 111 // To regenerate run: 112 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/input/RotaryEvent.java 113 // Added AddedInOrBefore or ApiRequirement Annotation manually 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) equals(@ndroid.annotation.Nullable Object o)186 public boolean equals(@android.annotation.Nullable Object o) { 187 // You can override field equality logic by defining either of the methods like: 188 // boolean fieldNameEquals(RotaryEvent other) { ... } 189 // boolean fieldNameEquals(FieldType otherValue) { ... } 190 191 if (this == o) return true; 192 if (o == null || getClass() != o.getClass()) return false; 193 @SuppressWarnings("unchecked") 194 RotaryEvent that = (RotaryEvent) o; 195 //noinspection PointlessBooleanExpression 196 return true 197 && mInputType == that.mInputType 198 && mClockwise == that.mClockwise 199 && Arrays.equals(mUptimeMillisForClicks, that.mUptimeMillisForClicks); 200 } 201 202 @Override 203 @DataClass.Generated.Member 204 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) hashCode()205 public int hashCode() { 206 // You can override field hashCode logic by defining methods like: 207 // int fieldNameHashCode() { ... } 208 209 int _hash = 1; 210 _hash = 31 * _hash + mInputType; 211 _hash = 31 * _hash + Boolean.hashCode(mClockwise); 212 _hash = 31 * _hash + Arrays.hashCode(mUptimeMillisForClicks); 213 return _hash; 214 } 215 216 @Override 217 @DataClass.Generated.Member 218 @AddedInOrBefore(majorVersion = 33) writeToParcel(@onNull Parcel dest, int flags)219 public void writeToParcel(@NonNull Parcel dest, int flags) { 220 // You can override field parcelling by defining methods like: 221 // void parcelFieldName(Parcel dest, int flags) { ... } 222 223 byte flg = 0; 224 if (mClockwise) flg |= 0x2; 225 dest.writeByte(flg); 226 dest.writeInt(mInputType); 227 dest.writeLongArray(mUptimeMillisForClicks); 228 } 229 230 @Override 231 @DataClass.Generated.Member 232 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 233 @AddedInOrBefore(majorVersion = 33) describeContents()234 public int describeContents() { return 0; } 235 236 /** @hide */ 237 @SuppressWarnings({"unchecked", "RedundantCast"}) 238 @DataClass.Generated.Member RotaryEvent(@onNull Parcel in)239 /* package-private */ RotaryEvent(@NonNull Parcel in) { 240 // You can override field unparcelling by defining methods like: 241 // static FieldType unparcelFieldName(Parcel in) { ... } 242 243 byte flg = in.readByte(); 244 boolean clockwise = (flg & 0x2) != 0; 245 int inputType = in.readInt(); 246 long[] uptimeMillisForClicks = in.createLongArray(); 247 248 this.mInputType = inputType; 249 AnnotationValidations.validate( 250 CarInputManager.InputTypeEnum.class, null, mInputType); 251 this.mClockwise = clockwise; 252 this.mUptimeMillisForClicks = uptimeMillisForClicks; 253 AnnotationValidations.validate( 254 NonNull.class, null, mUptimeMillisForClicks); 255 256 // onConstructed(); // You can define this method to get a callback 257 } 258 259 @DataClass.Generated.Member 260 @AddedInOrBefore(majorVersion = 33) 261 public static final @NonNull Parcelable.Creator<RotaryEvent> CREATOR 262 = new Parcelable.Creator<RotaryEvent>() { 263 @Override 264 public RotaryEvent[] newArray(int size) { 265 return new RotaryEvent[size]; 266 } 267 268 @Override 269 public RotaryEvent createFromParcel(@NonNull Parcel in) { 270 return new RotaryEvent(in); 271 } 272 }; 273 274 @DataClass.Generated( 275 time = 1628099164166L, 276 codegenVersion = "1.0.23", 277 sourceFile = "packages/services/Car/car-lib/src/android/car/input/RotaryEvent.java", 278 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)") 279 @Deprecated 280 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) __metadata()281 private void __metadata() {} 282 283 284 //@formatter:on 285 // End of generated code 286 287 } 288