1package com.xtremelabs.robolectric.shadows;
2
3import android.hardware.Sensor;
4import android.hardware.SensorEvent;
5import android.hardware.SensorEventListener;
6import android.hardware.SensorManager;
7import android.os.Handler;
8
9import com.xtremelabs.robolectric.Robolectric;
10import com.xtremelabs.robolectric.internal.Implementation;
11import com.xtremelabs.robolectric.internal.Implements;
12
13import java.util.ArrayList;
14import java.util.List;
15
16
17@Implements(SensorManager.class)
18public class ShadowSensorManager {
19
20	private ArrayList<SensorEventListener> listeners = new ArrayList<SensorEventListener>();
21
22	public boolean forceListenersToFail = false;
23
24	@Implementation
25	public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate) {
26
27		if(forceListenersToFail)
28			return false;
29
30		if(!listeners.contains(listener))
31			listeners.add(listener);
32
33		return true;
34	}
35
36	@Implementation
37	public void unregisterListener(SensorEventListener listener, Sensor sensor) {
38		listeners.remove(listener);
39	}
40
41	public boolean hasListener(SensorEventListener listener) {
42		return listeners.contains(listener);
43	}
44
45	public SensorEvent createSensorEvent() {
46		return Robolectric.newInstanceOf(SensorEvent.class);
47	}
48}
49