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