• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import android.view.InputDevice;
4 import android.view.KeyCharacterMap;
5 
6 /**
7  * Builder for {@link android.view.InputDevice}.
8  *
9  * <p>This exposes the setters for public InputDevice attributes. Its implemented by wrapping the
10  * hidden android.view.InputDevice.Builder. Tests building against the android platform source
11  * should just use that API instead.
12  *
13  * <p>Only supported when running on SDKs >= 34
14  */
15 public class InputDeviceBuilder {
16 
InputDeviceBuilder()17   private InputDeviceBuilder() {}
18 
newBuilder()19   public static InputDeviceBuilder newBuilder() {
20     return new InputDeviceBuilder();
21   }
22 
23   private final InputDevice.Builder delegate = new InputDevice.Builder();
24 
25   /**
26    * @see InputDevice#getId()
27    */
setId(int id)28   public InputDeviceBuilder setId(int id) {
29     delegate.setId(id);
30     return this;
31   }
32 
33   /**
34    * @see InputDevice#getControllerNumber()
35    */
setControllerNumber(int controllerNumber)36   public InputDeviceBuilder setControllerNumber(int controllerNumber) {
37     delegate.setControllerNumber(controllerNumber);
38     return this;
39   }
40 
41   /**
42    * @see InputDevice#getName()
43    */
setName(String name)44   public InputDeviceBuilder setName(String name) {
45     delegate.setName(name);
46     return this;
47   }
48 
49   /**
50    * @see InputDevice#getVendorId()
51    */
setVendorId(int vendorId)52   public InputDeviceBuilder setVendorId(int vendorId) {
53     delegate.setVendorId(vendorId);
54     return this;
55   }
56 
57   /**
58    * @see InputDevice#getProductId()
59    */
setProductId(int productId)60   public InputDeviceBuilder setProductId(int productId) {
61     delegate.setProductId(productId);
62     return this;
63   }
64 
65   /**
66    * @see InputDevice#getDescriptor()
67    */
setDescriptor(String descriptor)68   public InputDeviceBuilder setDescriptor(String descriptor) {
69     delegate.setDescriptor(descriptor);
70     return this;
71   }
72 
73   /**
74    * @see InputDevice#isExternal()
75    */
setExternal(boolean external)76   public InputDeviceBuilder setExternal(boolean external) {
77     delegate.setExternal(external);
78     return this;
79   }
80 
81   /**
82    * @see InputDevice#getSources()
83    */
setSources(int sources)84   public InputDeviceBuilder setSources(int sources) {
85     delegate.setSources(sources);
86     return this;
87   }
88 
89   /**
90    * @see InputDevice#getKeyboardType()
91    */
setKeyboardType(int keyboardType)92   public InputDeviceBuilder setKeyboardType(int keyboardType) {
93     delegate.setKeyboardType(keyboardType);
94     return this;
95   }
96 
97   /**
98    * @see InputDevice#getKeyCharacterMap()
99    */
setKeyCharacterMap(KeyCharacterMap keyCharacterMap)100   public InputDeviceBuilder setKeyCharacterMap(KeyCharacterMap keyCharacterMap) {
101     delegate.setKeyCharacterMap(keyCharacterMap);
102     return this;
103   }
104 
105   /**
106    * @see InputDevice#getVibrator()
107    */
setHasVibrator(boolean hasVibrator)108   public InputDeviceBuilder setHasVibrator(boolean hasVibrator) {
109     delegate.setHasVibrator(hasVibrator);
110     return this;
111   }
112 
113   /**
114    * @see InputDevice#hasMicrophone()
115    */
setHasMicrophone(boolean hasMicrophone)116   public InputDeviceBuilder setHasMicrophone(boolean hasMicrophone) {
117     delegate.setHasMicrophone(hasMicrophone);
118     return this;
119   }
120 
121   /**
122    * @see InputDevice#getMotionRanges()
123    */
addMotionRange( int axis, int source, float min, float max, float flat, float fuzz, float resolution)124   public InputDeviceBuilder addMotionRange(
125       int axis, int source, float min, float max, float flat, float fuzz, float resolution) {
126     delegate.addMotionRange(axis, source, min, max, flat, fuzz, resolution);
127     return this;
128   }
129 
build()130   public InputDevice build() {
131     return delegate.build();
132   }
133 }
134