• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.hardware.input;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * An event describing a mouse movement interaction originating from a remote device.
26  *
27  * See {@link android.view.MotionEvent}.
28  *
29  * @hide
30  */
31 @SystemApi
32 public final class VirtualMouseRelativeEvent implements Parcelable {
33 
34     private final float mRelativeX;
35     private final float mRelativeY;
36 
VirtualMouseRelativeEvent(float relativeX, float relativeY)37     private VirtualMouseRelativeEvent(float relativeX, float relativeY) {
38         mRelativeX = relativeX;
39         mRelativeY = relativeY;
40     }
41 
VirtualMouseRelativeEvent(@onNull Parcel parcel)42     private VirtualMouseRelativeEvent(@NonNull Parcel parcel) {
43         mRelativeX = parcel.readFloat();
44         mRelativeY = parcel.readFloat();
45     }
46 
47     @Override
writeToParcel(@onNull Parcel parcel, int parcelableFlags)48     public void writeToParcel(@NonNull Parcel parcel, int parcelableFlags) {
49         parcel.writeFloat(mRelativeX);
50         parcel.writeFloat(mRelativeY);
51     }
52 
53     @Override
describeContents()54     public int describeContents() {
55         return 0;
56     }
57 
58     /**
59      * Returns the relative x-axis movement, in pixels.
60      */
getRelativeX()61     public float getRelativeX() {
62         return mRelativeX;
63     }
64 
65     /**
66      * Returns the relative x-axis movement, in pixels.
67      */
getRelativeY()68     public float getRelativeY() {
69         return mRelativeY;
70     }
71 
72     /**
73      * Builder for {@link VirtualMouseRelativeEvent}.
74      */
75     public static final class Builder {
76 
77         private float mRelativeX;
78         private float mRelativeY;
79 
80         /**
81          * Creates a {@link VirtualMouseRelativeEvent} object with the current builder
82          * configuration.
83          */
build()84         public @NonNull VirtualMouseRelativeEvent build() {
85             return new VirtualMouseRelativeEvent(mRelativeX, mRelativeY);
86         }
87 
88         /**
89          * Sets the relative x-axis movement, in pixels.
90          *
91          * @return this builder, to allow for chaining of calls
92          */
setRelativeX(float relativeX)93         public @NonNull Builder setRelativeX(float relativeX) {
94             mRelativeX = relativeX;
95             return this;
96         }
97 
98         /**
99          * Sets the relative y-axis movement, in pixels.
100          *
101          * @return this builder, to allow for chaining of calls
102          */
setRelativeY(float relativeY)103         public @NonNull Builder setRelativeY(float relativeY) {
104             mRelativeY = relativeY;
105             return this;
106         }
107     }
108 
109     public static final @NonNull Parcelable.Creator<VirtualMouseRelativeEvent> CREATOR =
110             new Parcelable.Creator<VirtualMouseRelativeEvent>() {
111                 public VirtualMouseRelativeEvent createFromParcel(Parcel source) {
112                     return new VirtualMouseRelativeEvent(source);
113                 }
114 
115                 public VirtualMouseRelativeEvent[] newArray(int size) {
116                     return new VirtualMouseRelativeEvent[size];
117                 }
118             };
119 }
120