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