@@ -260,12 +260,12 @@ public void run() {
260260 };
261261
262262 private Camera .Size getOptimalPictureSize () {
263- final int maxResolution = getMaxResolution ();
263+ final int maxResolution = getMaxPhotoResolution ();
264264 final List <Camera .Size > sizes = mParameters .getSupportedPictureSizes ();
265265 Collections .sort (sizes , new SizesComparator ());
266266 Camera .Size maxSize = sizes .get (0 );
267267 for (Camera .Size size : sizes ) {
268- final boolean isProperRatio = isProperRatio (size );
268+ final boolean isProperRatio = ! mForceAspectRatio || isProperRatio (size );
269269 final boolean isProperResolution = isProperResolution (size , maxResolution );
270270 if (isProperResolution && isProperRatio ) {
271271 maxSize = size ;
@@ -275,8 +275,8 @@ private Camera.Size getOptimalPictureSize() {
275275 return maxSize ;
276276 }
277277
278- private int getMaxResolution () {
279- final int maxRes = Config .newInstance (getContext ()).getMaxResolution ();
278+ private int getMaxPhotoResolution () {
279+ final int maxRes = Config .newInstance (getContext ()).getMaxPhotoResolution ();
280280 switch (maxRes ) {
281281 case 0 :
282282 return 6000000 ;
@@ -291,6 +291,20 @@ private boolean isProperResolution(Camera.Size size, int maxRes) {
291291 return maxRes == 0 || size .width * size .height < maxRes ;
292292 }
293293
294+ private int getMaxVideoResolution () {
295+ final int maxRes = Config .newInstance (getContext ()).getMaxVideoResolution ();
296+ switch (maxRes ) {
297+ case 0 :
298+ return 400000 ;
299+ case 1 :
300+ return 1000000 ;
301+ case 2 :
302+ return 2100000 ;
303+ default :
304+ return 0 ;
305+ }
306+ }
307+
294308 private boolean isProperRatio (Camera .Size size ) {
295309 final float currRatio = (float ) size .height / size .width ;
296310 float wantedRatio = (float ) 3 / 4 ;
@@ -301,15 +315,23 @@ private boolean isProperRatio(Camera.Size size) {
301315 }
302316
303317 private Camera .Size getOptimalVideoSize () {
318+ final int maxResolution = getMaxVideoResolution ();
304319 final List <Camera .Size > sizes = getSupportedVideoSizes ();
305320 Collections .sort (sizes , new SizesComparator ());
306321 Camera .Size maxSize = sizes .get (0 );
307- for (Camera .Size size : sizes ) {
308- final boolean isProperRatio = isProperRatio (size );
309- if (isProperRatio ) {
322+ final int cnt = sizes .size ();
323+ for (int i = 0 ; i < cnt ; i ++) {
324+ Camera .Size size = sizes .get (i );
325+ final boolean isProperRatio = !mForceAspectRatio || isProperRatio (size );
326+ final boolean isProperResolution = isProperResolution (size , maxResolution );
327+ if (isProperResolution && isProperRatio ) {
310328 maxSize = size ;
311329 break ;
312330 }
331+
332+ if (i == cnt - 1 ) {
333+ Utils .showToast (getContext (), R .string .no_valid_resolution_found );
334+ }
313335 }
314336 return maxSize ;
315337 }
@@ -508,7 +530,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
508530
509531 if (mSetupPreviewAfterMeasure ) {
510532 mSetupPreviewAfterMeasure = false ;
511- mCamera .stopPreview ();
533+ if (mCamera != null )
534+ mCamera .stopPreview ();
535+
512536 setupPreview ();
513537 }
514538 }
@@ -559,6 +583,7 @@ public boolean initRecorder() {
559583
560584 mSwitchToVideoAsap = false ;
561585 Camera .Size preferred = mParameters .getPreferredPreviewSizeForVideo ();
586+
562587 if (preferred == null ) {
563588 final List <Camera .Size > previewSizes = mParameters .getSupportedPreviewSizes ();
564589 Collections .sort (previewSizes , new SizesComparator ());
0 commit comments