• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 com.android.settings.testutils.shadow;
18 
19 import android.view.InputDevice;
20 
21 import org.robolectric.annotation.Implementation;
22 import org.robolectric.annotation.Implements;
23 import org.robolectric.annotation.Resetter;
24 import org.robolectric.shadow.api.Shadow;
25 
26 import java.util.HashMap;
27 import java.util.Map;
28 
29 @Implements(InputDevice.class)
30 public class ShadowInputDevice extends org.robolectric.shadows.ShadowInputDevice {
31 
32     public static int[] sDeviceIds;
33 
34     private static Map<Integer, InputDevice> sDeviceMap = new HashMap<>();
35 
36     private int mDeviceId;
37 
38     @Implementation
getDeviceIds()39     protected static int[] getDeviceIds() {
40         return sDeviceIds;
41     }
42 
43     @Implementation
getDevice(int id)44     protected static InputDevice getDevice(int id) {
45         return sDeviceMap.get(id);
46     }
47 
addDevice(int id, InputDevice device)48     public static void addDevice(int id, InputDevice device) {
49         sDeviceMap.put(id, device);
50     }
51 
52     @Resetter
reset()53     public static void reset() {
54         sDeviceIds = null;
55         sDeviceMap.clear();
56     }
57 
58     @Implementation
getId()59     protected int getId() {
60         return mDeviceId;
61     }
62 
makeInputDevicebyId(int id)63     public static InputDevice makeInputDevicebyId(int id) {
64         final InputDevice inputDevice = Shadow.newInstanceOf(InputDevice.class);
65         final ShadowInputDevice shadowInputDevice = Shadow.extract(inputDevice);
66         shadowInputDevice.setId(id);
67         return inputDevice;
68     }
69 
setId(int id)70     public void setId(int id) {
71         mDeviceId = id;
72     }
73 }
74