CameraResolutionRequirement implements Requirement { @NonNull @Override public RequirementReport check() { boolean result = true; String details = ""; try { final Camera.Parameters parameters = mCameraHolder.getCameraParameters(); if (parameters != null) { final Size pictureSize = SizeSelectionHelper.getLargestAllowedSize( parameters.getSupportedPictureSizes(), MAX_PICTURE_AREA); if (pictureSize == null) { result = false; details = "Camera has no picture resolutions"; return new RequirementReport(getId(), result, details); } else if (!isAround8MPOrHigher(pictureSize)) { result = false; details = "Largest camera picture resolution is lower than 8MP"; return new RequirementReport(getId(), result, details); } final Size previewSize = SizeSelectionHelper.getLargestAllowedSizeWithSimilarAspectRatio( parameters.getSupportedPreviewSizes(), pictureSize, MAX_PICTURE_AREA); if (previewSize == null) { result = false; details = String.format(Locale.US, "Camera has no preview resolutions matching the picture resolution " + "%dx%d", pictureSize.width, pictureSize.height); return new RequirementReport(getId(), result, details); } } else { result = false; details = "Camera not open"; } } catch (final RuntimeException e) { result = false; details = "Camera exception: " + e.getMessage(); } return new RequirementReport(getId(), result, details); } CameraResolutionRequirement(final CameraHolder cameraHolder); @NonNull @Override RequirementId getId(); @NonNull @Override RequirementReport check(); static final int MAX_PICTURE_AREA; }
@Test public void should_reportUnfulfilled_ifNoPreviewSize_withSameAspectRatio_asLargestPictureSize() { CameraHolder cameraHolder = getCameraHolder(Collections.singletonList(createSize(300, 200)), null); CameraResolutionRequirement requirement = new CameraResolutionRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); assertThat(requirement.check().getDetails()).isEqualTo( "Camera has no preview resolutions matching the picture resolution 3840x2160"); }
@Test public void should_reportUnfulfilled_ifPictureSize_isSmallerThan8MP() { CameraHolder cameraHolder = getCameraHolder(null, Arrays.asList( createSize(400, 300), createSize(3200, 2048)) ); CameraResolutionRequirement requirement = new CameraResolutionRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); assertThat(requirement.check().getDetails()).isEqualTo( "Largest camera picture resolution is lower than 8MP"); }
@Test public void should_reportFulfilled_ifPreviewSize_andPictureSize_isLargerThan8MP() { CameraHolder cameraHolder = getCameraHolder(null, null); CameraResolutionRequirement requirement = new CameraResolutionRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isTrue(); assertThat(requirement.check().getDetails()).isEqualTo(""); }
@Test public void should_reportUnfulfilled_ifCamera_isNotOpen() { CameraHolder cameraHolder = mock(CameraHolder.class); CameraResolutionRequirement requirement = new CameraResolutionRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); assertThat(requirement.check().getDetails()).isEqualTo("Camera not open"); }