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