Debian Codegraph @

core/java/android/hardware/input/VirtualMouseScrollEvent.java

raw symbols SCIP
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.FloatRange;
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.internal.util.Preconditions;
26
27 /**
28 * An event describing a mouse scroll interaction originating from a remote device.
29 *
30 * See {@link android.view.MotionEvent}.
31 *
32 * @hide
33 */
34 @SystemApi
35 public final class VirtualMouseScrollEvent implements Parcelable {
36
37 private final float mXAxisMovement;
38 private final float mYAxisMovement;
39
40 private VirtualMouseScrollEvent(float xAxisMovement, float yAxisMovement) {
41 mXAxisMovement = xAxisMovement;
42 mYAxisMovement = yAxisMovement;
43 }
44
45 private VirtualMouseScrollEvent(@NonNull Parcel parcel) {
46 mXAxisMovement = parcel.readFloat();
47 mYAxisMovement = parcel.readFloat();
48 }
49
50 @Override
51 public void writeToParcel(@NonNull Parcel parcel, int parcelableFlags) {
52 parcel.writeFloat(mXAxisMovement);
53 parcel.writeFloat(mYAxisMovement);
54 }
55
56 @Override
57 public int describeContents() {
58 return 0;
59 }
60
61 /**
62 * Returns the x-axis scroll movement, normalized from -1.0 to 1.0, inclusive. Positive values
63 * indicate scrolling upward; negative values, downward.
64 */
65 public float getXAxisMovement() {
66 return mXAxisMovement;
67 }
68
69 /**
70 * Returns the y-axis scroll movement, normalized from -1.0 to 1.0, inclusive. Positive values
71 * indicate scrolling towards the right; negative values, to the left.
72 */
73 public float getYAxisMovement() {
74 return mYAxisMovement;
75 }
76
77 /**
78 * Builder for {@link VirtualMouseScrollEvent}.
79 */
80 public static final class Builder {
81
82 private float mXAxisMovement;
83 private float mYAxisMovement;
84
85 /**
86 * Creates a {@link VirtualMouseScrollEvent} object with the current builder configuration.
87 */
88 public @NonNull VirtualMouseScrollEvent build() {
89 return new VirtualMouseScrollEvent(mXAxisMovement, mYAxisMovement);
90 }
91
92 /**
93 * Sets the x-axis scroll movement, normalized from -1.0 to 1.0, inclusive. Positive values
94 * indicate scrolling upward; negative values, downward.
95 *
96 * @return this builder, to allow for chaining of calls
97 */
98 public @NonNull Builder setXAxisMovement(
99 @FloatRange(from = -1.0f, to = 1.0f) float xAxisMovement) {
100 Preconditions.checkArgumentInRange(xAxisMovement, -1f, 1f, "xAxisMovement");
101 mXAxisMovement = xAxisMovement;
102 return this;
103 }
104
105 /**
106 * Sets the y-axis scroll movement, normalized from -1.0 to 1.0, inclusive. Positive values
107 * indicate scrolling towards the right; negative values, to the left.
108 *
109 * @return this builder, to allow for chaining of calls
110 */
111 public @NonNull Builder setYAxisMovement(
112 @FloatRange(from = -1.0f, to = 1.0f) float yAxisMovement) {
113 Preconditions.checkArgumentInRange(yAxisMovement, -1f, 1f, "yAxisMovement");
114 mYAxisMovement = yAxisMovement;
115 return this;
116 }
117 }
118
119 public static final @NonNull Parcelable.Creator<VirtualMouseScrollEvent> CREATOR =
120 new Parcelable.Creator<VirtualMouseScrollEvent>() {
121 public VirtualMouseScrollEvent createFromParcel(Parcel source) {
122 return new VirtualMouseScrollEvent(source);
123 }
124
125 public VirtualMouseScrollEvent[] newArray(int size) {
126 return new VirtualMouseScrollEvent[size];
127 }
128 };
129 }