• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.graphics.ImageFormat;
4 import android.hardware.Camera;
5 import com.xtremelabs.robolectric.Robolectric;
6 import com.xtremelabs.robolectric.internal.Implementation;
7 import com.xtremelabs.robolectric.internal.Implements;
8 
9 import java.util.ArrayList;
10 import java.util.List;
11 
12 /**
13  * Shadows the Android {@code Camera.Parameters} class.
14  */
15 @Implements(Camera.Parameters.class)
16 public 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
getPictureSize()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
getPreviewFormat()36     public int getPreviewFormat() {
37         return previewFormat;
38     }
39 
40     @Implementation
getPreviewFpsRange(int[] range)41     public void getPreviewFpsRange(int[] range) {
42         range[0] = previewFpsMin;
43         range[1] = previewFpsMax;
44     }
45 
46     @Implementation
getPreviewFrameRate()47     public int getPreviewFrameRate() {
48         return previewFps;
49     }
50 
51     @Implementation
getPreviewSize()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
getSupportedPictureSizes()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
getSupportedPictureFormats()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
getSupportedPreviewFormats()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
getSupportedPreviewFpsRange()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
getSupportedPreviewFrameRates()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
getSupportedPreviewSizes()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
setPictureSize(int width, int height)110     public void setPictureSize(int width, int height) {
111         pictureWidth = width;
112         pictureHeight = height;
113     }
114 
115     @Implementation
setPreviewFormat(int pixel_format)116     public void setPreviewFormat(int pixel_format) {
117         previewFormat = pixel_format;
118     }
119 
120     @Implementation
setPreviewFpsRange(int min, int max)121     public void setPreviewFpsRange(int min, int max) {
122         previewFpsMin = min;
123         previewFpsMax = max;
124     }
125 
126     @Implementation
setPreviewFrameRate(int fps)127     public void setPreviewFrameRate(int fps) {
128         previewFps = fps;
129     }
130 
131     @Implementation
setPreviewSize(int width, int height)132     public void setPreviewSize(int width, int height) {
133         previewWidth = width;
134         previewHeight = height;
135     }
136 
getPreviewWidth()137     public int getPreviewWidth() {
138         return previewWidth;
139     }
140 
getPreviewHeight()141     public int getPreviewHeight() {
142         return previewHeight;
143     }
144 
getPictureWidth()145     public int getPictureWidth() {
146         return pictureWidth;
147     }
148 
getPictureHeight()149     public int getPictureHeight() {
150         return pictureHeight;
151     }
152 
addSize(List<Camera.Size> sizes, int width, int height)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 
addRange(List<int[]> ranges, int min, int max)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