131af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesipackage com.xtremelabs.robolectric.shadows; 231af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi 3f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultzimport android.graphics.ImageFormat; 4f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultzimport android.hardware.Camera; 55564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesiimport com.xtremelabs.robolectric.Robolectric; 622c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implementation; 722c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implements; 831af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi 9f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultzimport java.util.ArrayList; 10f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultzimport java.util.List; 1131af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi 1231af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi/** 1331af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi * Shadows the Android {@code Camera.Parameters} class. 1431af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi */ 15f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz@Implements(Camera.Parameters.class) 1631af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesipublic class ShadowCameraParameters { 17f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 1840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int pictureWidth = 1280; 1940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int pictureHeight = 960; 2040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int previewWidth = 640; 2140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int previewHeight = 480; 2240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int previewFormat = ImageFormat.NV21; 2340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int previewFpsMin = 10; 2440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int previewFpsMax = 30; 2540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private int previewFps = 30; 26f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 27f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz @Implementation 28ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public Camera.Size getPictureSize() { 2940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams Camera.Size pictureSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0); 3040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams pictureSize.width = pictureWidth; 3140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams pictureSize.height = pictureHeight; 3240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return pictureSize; 33f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz } 34f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 35f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz @Implementation 365564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi public int getPreviewFormat() { 375564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi return previewFormat; 385564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 3940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 405564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 41ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public void getPreviewFpsRange(int[] range) { 4240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams range[0] = previewFpsMin; 4340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams range[1] = previewFpsMax; 44f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz } 45f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 46f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz @Implementation 47ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public int getPreviewFrameRate() { 4840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return previewFps; 495564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 5040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 515564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 52ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public Camera.Size getPreviewSize() { 5340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams Camera.Size previewSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0); 5440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams previewSize.width = previewWidth; 5540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams previewSize.height = previewHeight; 5640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return previewSize; 57f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz } 58f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 59f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz @Implementation 60ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public List<Camera.Size> getSupportedPictureSizes() { 6140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams List<Camera.Size> supportedSizes = new ArrayList<Camera.Size>(); 6240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams addSize(supportedSizes, 320, 240); 6340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams addSize(supportedSizes, 640, 480); 6440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams addSize(supportedSizes, 800, 600); 6540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return supportedSizes; 665564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 6740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 685564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 69ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public List<Integer> getSupportedPictureFormats() { 705564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi List<Integer> formats = new ArrayList<Integer>(); 715564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi formats.add(ImageFormat.NV21); 725564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi formats.add(ImageFormat.JPEG); 7340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return formats; 745564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 7540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 765564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 77f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz public List<Integer> getSupportedPreviewFormats() { 78f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz List<Integer> formats = new ArrayList<Integer>(); 79f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz formats.add(ImageFormat.NV21); 80f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz formats.add(ImageFormat.JPEG); 81f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz return formats; 82f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz } 8340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 845564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 85ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public List<int[]> getSupportedPreviewFpsRange() { 8640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams List<int[]> supportedRanges = new ArrayList<int[]>(); 87930923f56f3146324b96a760d66319f9914ad331Michael Portuesi addRange(supportedRanges, 15000, 15000); 88930923f56f3146324b96a760d66319f9914ad331Michael Portuesi addRange(supportedRanges, 10000, 30000); 8940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return supportedRanges; 905564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 9140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 925564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 93ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public List<Integer> getSupportedPreviewFrameRates() { 9440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams List<Integer> supportedRates = new ArrayList<Integer>(); 9540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams supportedRates.add(10); 9640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams supportedRates.add(15); 9740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams supportedRates.add(30); 9840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return supportedRates; 995564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 1005564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi 1015564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 102ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public List<Camera.Size> getSupportedPreviewSizes() { 10340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams List<Camera.Size> supportedSizes = new ArrayList<Camera.Size>(); 10440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams addSize(supportedSizes, 320, 240); 10540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams addSize(supportedSizes, 640, 480); 10640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return supportedSizes; 1075564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 10840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 1095564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 110ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public void setPictureSize(int width, int height) { 1115564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi pictureWidth = width; 1125564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi pictureHeight = height; 1135564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 1145564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi 1155564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 1165564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi public void setPreviewFormat(int pixel_format) { 1175564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi previewFormat = pixel_format; 1185564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 11940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 1205564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 121ba56578d4e5b38670a42a30fc9d45e0004ec2f94Michael Portuesi public void setPreviewFpsRange(int min, int max) { 12240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams previewFpsMin = min; 12340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams previewFpsMax = max; 1245564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 125f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 1265564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 1275564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi public void setPreviewFrameRate(int fps) { 12840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams previewFps = fps; 1295564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 13040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 1315564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi @Implementation 1325564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi public void setPreviewSize(int width, int height) { 1335564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi previewWidth = width; 1345564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi previewHeight = height; 1355564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 13640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 137f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz public int getPreviewWidth() { 138f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz return previewWidth; 139f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz } 140f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz 141f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz public int getPreviewHeight() { 142f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz return previewHeight; 143f96b9a1f17d47e48d1f5f8e29b4ed7ffccc739abPhil Goodwin & Tyler Schultz } 1445564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi 14540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams public int getPictureWidth() { 14640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return pictureWidth; 14740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams } 14840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 14940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams public int getPictureHeight() { 15040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams return pictureHeight; 15140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams } 1525564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi 15340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams private void addSize(List<Camera.Size> sizes, int width, int height) { 15440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams Camera.Size newSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0); 15540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams newSize.width = width; 15640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams newSize.height = height; 15740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams sizes.add(newSize); 1585564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 15940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 1605564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi private void addRange(List<int[]> ranges, int min, int max) { 16140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams int[] range = new int[2]; 16240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams range[0] = min; 16340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams range[1] = max; 16440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams ranges.add(range); 1655564bdcd09063feb7639eb7f40baeae43820c705Michael Portuesi } 16640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams 16731af8607e2c7da6ba8708f57c4b67b6b4aaad921Michael Portuesi} 168