1 package org.robolectric.shadows; 2 3 import android.graphics.Canvas; 4 import android.graphics.Rect; 5 import android.view.Surface; 6 import android.view.SurfaceHolder; 7 import android.view.SurfaceView; 8 import java.util.HashSet; 9 import java.util.Set; 10 import org.robolectric.annotation.Implementation; 11 import org.robolectric.annotation.Implements; 12 13 @Implements(SurfaceView.class) 14 @SuppressWarnings({"UnusedDeclaration"}) 15 public class ShadowSurfaceView extends ShadowView { 16 private final FakeSurfaceHolder fakeSurfaceHolder = new FakeSurfaceHolder(); 17 18 @Implementation onAttachedToWindow()19 protected void onAttachedToWindow() {} 20 21 @Implementation getHolder()22 protected SurfaceHolder getHolder() { 23 return fakeSurfaceHolder; 24 } 25 getFakeSurfaceHolder()26 public FakeSurfaceHolder getFakeSurfaceHolder() { 27 return fakeSurfaceHolder; 28 } 29 30 /** 31 * Robolectric implementation of {@link android.view.SurfaceHolder}. 32 */ 33 public static class FakeSurfaceHolder implements SurfaceHolder { 34 private final Set<Callback> callbacks = new HashSet<>(); 35 36 @Override addCallback(Callback callback)37 public void addCallback(Callback callback) { 38 callbacks.add(callback); 39 } 40 getCallbacks()41 public Set<Callback> getCallbacks() { 42 return callbacks; 43 } 44 45 @Override removeCallback(Callback callback)46 public void removeCallback(Callback callback) { 47 callbacks.remove(callback); 48 } 49 50 @Override isCreating()51 public boolean isCreating() { 52 return false; 53 } 54 55 @Override setType(int i)56 public void setType(int i) { 57 } 58 59 @Override setFixedSize(int i, int i1)60 public void setFixedSize(int i, int i1) { 61 } 62 63 @Override setSizeFromLayout()64 public void setSizeFromLayout() { 65 } 66 67 @Override setFormat(int i)68 public void setFormat(int i) { 69 } 70 71 @Override setKeepScreenOn(boolean b)72 public void setKeepScreenOn(boolean b) { 73 } 74 75 @Override lockCanvas()76 public Canvas lockCanvas() { 77 return null; 78 } 79 80 @Override lockCanvas(Rect rect)81 public Canvas lockCanvas(Rect rect) { 82 return null; 83 } 84 85 @Override unlockCanvasAndPost(Canvas canvas)86 public void unlockCanvasAndPost(Canvas canvas) { 87 } 88 89 @Override getSurfaceFrame()90 public Rect getSurfaceFrame() { 91 return null; 92 } 93 94 @Override getSurface()95 public Surface getSurface() { 96 return null; 97 } 98 } 99 } 100