1 /*
2  * Copyright (C) 2022 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.IntRange;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 /**
26  * Configurations to create virtual navigation touchpad.
27  *
28  * @hide
29  */
30 @SystemApi
31 public final class VirtualNavigationTouchpadConfig extends VirtualInputDeviceConfig
32         implements Parcelable {
33 
34     /** The touchpad height. */
35     private final int mHeight;
36     /** The touchpad width. */
37     private final int mWidth;
38 
VirtualNavigationTouchpadConfig(@onNull Builder builder)39     private VirtualNavigationTouchpadConfig(@NonNull Builder builder) {
40         super(builder);
41         mHeight = builder.mHeight;
42         mWidth = builder.mWidth;
43     }
44 
VirtualNavigationTouchpadConfig(@onNull Parcel in)45     private VirtualNavigationTouchpadConfig(@NonNull Parcel in) {
46         super(in);
47         mHeight = in.readInt();
48         mWidth = in.readInt();
49     }
50 
51     /** Returns the touchpad height. */
getHeight()52     @IntRange(from = 1) public int getHeight() {
53         return mHeight;
54     }
55 
56     /** Returns the touchpad width. */
getWidth()57     @IntRange(from = 1) public int getWidth() {
58         return mWidth;
59     }
60 
61     @Override
describeContents()62     public int describeContents() {
63         return 0;
64     }
65 
66     @Override
writeToParcel(@onNull Parcel dest, int flags)67     public void writeToParcel(@NonNull Parcel dest, int flags) {
68         super.writeToParcel(dest, flags);
69         dest.writeInt(mHeight);
70         dest.writeInt(mWidth);
71     }
72 
73     @NonNull
74     public static final Creator<VirtualNavigationTouchpadConfig> CREATOR =
75             new Creator<VirtualNavigationTouchpadConfig>() {
76                 @Override
77                 public VirtualNavigationTouchpadConfig createFromParcel(Parcel in) {
78                     return new VirtualNavigationTouchpadConfig(in);
79                 }
80 
81                 @Override
82                 public VirtualNavigationTouchpadConfig[] newArray(int size) {
83                     return new VirtualNavigationTouchpadConfig[size];
84                 }
85             };
86 
87     /**
88      * Builder for creating a {@link VirtualNavigationTouchpadConfig}.
89      */
90     public static final class Builder extends VirtualInputDeviceConfig.Builder<Builder> {
91         private final int mHeight;
92         private final int mWidth;
93 
94         /**
95          * Creates a new instance for the given dimensions of the {@link VirtualNavigationTouchpad}.
96          *
97          * @param touchpadWidth The width of the touchpad.
98          * @param touchpadHeight The height of the touchpad.
99          */
Builder(@ntRangefrom = 1) int touchpadWidth, @IntRange(from = 1) int touchpadHeight)100         public Builder(@IntRange(from = 1) int touchpadWidth,
101                 @IntRange(from = 1) int touchpadHeight) {
102             if (touchpadHeight <= 0 || touchpadWidth <= 0) {
103                 throw new IllegalArgumentException(
104                         "Cannot create a virtual navigation touchpad, touchpad dimensions must be "
105                                 + "positive. Got: (" + touchpadHeight + ", "
106                                 + touchpadWidth + ")");
107             }
108             mHeight = touchpadHeight;
109             mWidth = touchpadWidth;
110         }
111 
112         /**
113          * Builds the {@link VirtualNavigationTouchpadConfig} instance.
114          */
115         @NonNull
build()116         public VirtualNavigationTouchpadConfig build() {
117             return new VirtualNavigationTouchpadConfig(this);
118         }
119     }
120 }
121