1package com.xtremelabs.robolectric.shadows; 2 3import android.graphics.ImageFormat; 4import android.hardware.Camera; 5import com.xtremelabs.robolectric.Robolectric; 6import com.xtremelabs.robolectric.internal.Implementation; 7import com.xtremelabs.robolectric.internal.Implements; 8 9import java.util.ArrayList; 10import java.util.List; 11 12/** 13 * Shadows the Android {@code Camera.Parameters} class. 14 */ 15@Implements(Camera.Parameters.class) 16public class ShadowCameraParameters { 17 18 private int pictureWidth = 1280; 19 private int pictureHeight = 960; 20 private int previewWidth = 640; 21 private int previewHeight = 480; 22 private int previewFormat = ImageFormat.NV21; 23 private int previewFpsMin = 10; 24 private int previewFpsMax = 30; 25 private int previewFps = 30; 26 27 @Implementation 28 public Camera.Size getPictureSize() { 29 Camera.Size pictureSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0); 30 pictureSize.width = pictureWidth; 31 pictureSize.height = pictureHeight; 32 return pictureSize; 33 } 34 35 @Implementation 36 public int getPreviewFormat() { 37 return previewFormat; 38 } 39 40 @Implementation 41 public void getPreviewFpsRange(int[] range) { 42 range[0] = previewFpsMin; 43 range[1] = previewFpsMax; 44 } 45 46 @Implementation 47 public int getPreviewFrameRate() { 48 return previewFps; 49 } 50 51 @Implementation 52 public Camera.Size getPreviewSize() { 53 Camera.Size previewSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0); 54 previewSize.width = previewWidth; 55 previewSize.height = previewHeight; 56 return previewSize; 57 } 58 59 @Implementation 60 public List<Camera.Size> getSupportedPictureSizes() { 61 List<Camera.Size> supportedSizes = new ArrayList<Camera.Size>(); 62 addSize(supportedSizes, 320, 240); 63 addSize(supportedSizes, 640, 480); 64 addSize(supportedSizes, 800, 600); 65 return supportedSizes; 66 } 67 68 @Implementation 69 public List<Integer> getSupportedPictureFormats() { 70 List<Integer> formats = new ArrayList<Integer>(); 71 formats.add(ImageFormat.NV21); 72 formats.add(ImageFormat.JPEG); 73 return formats; 74 } 75 76 @Implementation 77 public List<Integer> getSupportedPreviewFormats() { 78 List<Integer> formats = new ArrayList<Integer>(); 79 formats.add(ImageFormat.NV21); 80 formats.add(ImageFormat.JPEG); 81 return formats; 82 } 83 84 @Implementation 85 public List<int[]> getSupportedPreviewFpsRange() { 86 List<int[]> supportedRanges = new ArrayList<int[]>(); 87 addRange(supportedRanges, 15000, 15000); 88 addRange(supportedRanges, 10000, 30000); 89 return supportedRanges; 90 } 91 92 @Implementation 93 public List<Integer> getSupportedPreviewFrameRates() { 94 List<Integer> supportedRates = new ArrayList<Integer>(); 95 supportedRates.add(10); 96 supportedRates.add(15); 97 supportedRates.add(30); 98 return supportedRates; 99 } 100 101 @Implementation 102 public List<Camera.Size> getSupportedPreviewSizes() { 103 List<Camera.Size> supportedSizes = new ArrayList<Camera.Size>(); 104 addSize(supportedSizes, 320, 240); 105 addSize(supportedSizes, 640, 480); 106 return supportedSizes; 107 } 108 109 @Implementation 110 public void setPictureSize(int width, int height) { 111 pictureWidth = width; 112 pictureHeight = height; 113 } 114 115 @Implementation 116 public void setPreviewFormat(int pixel_format) { 117 previewFormat = pixel_format; 118 } 119 120 @Implementation 121 public void setPreviewFpsRange(int min, int max) { 122 previewFpsMin = min; 123 previewFpsMax = max; 124 } 125 126 @Implementation 127 public void setPreviewFrameRate(int fps) { 128 previewFps = fps; 129 } 130 131 @Implementation 132 public void setPreviewSize(int width, int height) { 133 previewWidth = width; 134 previewHeight = height; 135 } 136 137 public int getPreviewWidth() { 138 return previewWidth; 139 } 140 141 public int getPreviewHeight() { 142 return previewHeight; 143 } 144 145 public int getPictureWidth() { 146 return pictureWidth; 147 } 148 149 public int getPictureHeight() { 150 return pictureHeight; 151 } 152 153 private void addSize(List<Camera.Size> sizes, int width, int height) { 154 Camera.Size newSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0); 155 newSize.width = width; 156 newSize.height = height; 157 sizes.add(newSize); 158 } 159 160 private void addRange(List<int[]> ranges, int min, int max) { 161 int[] range = new int[2]; 162 range[0] = min; 163 range[1] = max; 164 ranges.add(range); 165 } 166 167} 168