Skip to content

Commit

Permalink
It was possible that there is no preview size with the same aspect ra…
Browse files Browse the repository at this point in the history
…tio as picture size. In such cases we fall back to normal preview size selection.
  • Loading branch information
dmitry-zaitsev committed May 24, 2017
1 parent d8fad94 commit 5d23779
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import io.fotoapparat.parameter.FocusMode;
import io.fotoapparat.parameter.Parameters;
import io.fotoapparat.parameter.Size;
import io.fotoapparat.parameter.selector.AspectRatioSelectors;
import io.fotoapparat.parameter.selector.SelectorFunction;
import io.fotoapparat.parameter.selector.Selectors;

import static io.fotoapparat.parameter.selector.AspectRatioSelectors.aspectRatio;

/**
* Provides initial {@link Parameters} for {@link CameraDevice}.
Expand Down Expand Up @@ -59,15 +61,22 @@ private void putPreviewSize(Capabilities capabilities, Parameters parameters) {

parameters.putValue(
Parameters.Type.PREVIEW_SIZE,
AspectRatioSelectors
.aspectRatio(
photoSize.getAspectRatio(),
Selectors
.firstAvailable(
previewWithSameAspectRatio(photoSize),
previewSizeSelector
)
.select(capabilities.supportedPreviewSizes())
);
}

private SelectorFunction<Size> previewWithSameAspectRatio(Size photoSize) {
return aspectRatio(
photoSize.getAspectRatio(),
previewSizeSelector
);
}

private void putPictureSize(Capabilities capabilities, Parameters parameters) {
parameters.putValue(
Parameters.Type.PICTURE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.fotoapparat.parameter.selector.SelectorFunction;

import static io.fotoapparat.test.TestUtils.asSet;
import static java.util.Collections.singleton;
import static junit.framework.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -133,6 +134,36 @@ public void selectPreviewSize_WithValidAspectRatio() throws Exception {
);
}

@Test
public void selectPreviewSize_SameAspectRatioNotAvailable() throws Exception {
// Given
Size photoSize = new Size(10000, 100);
Set<Size> photoSizes = singleton(photoSize);

given(photoSizeSelector.select(photoSizes))
.willReturn(photoSize);

given(cameraDevice.getCapabilities())
.willReturn(new Capabilities(
photoSizes,
ALL_PREVIEW_SIZES,
FOCUS_MODES,
FLASH
));

given(previewSizeSelector.select(ALL_PREVIEW_SIZES))
.willReturn(PREVIEW_SIZE);

// When
Parameters parameters = testee.initialParameters();

// Then
assertEquals(
PREVIEW_SIZE,
parameters.getValue(Parameters.Type.PREVIEW_SIZE)
);
}

@Test
public void parameterValidation() throws Exception {
// Given
Expand Down

0 comments on commit 5d23779

Please sign in to comment.