app/src/main/java/cn/lytcom/camera2kit/Camera2Fragment.java
/**
     * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
     * is at least as large as the respective texture view size, and that is at most as large as the
     * respective max size, and whose aspect ratio matches with the specified value. If such size
     * doesn't exist, choose the largest one that is at most as large as the respective max size,
     * and whose aspect ratio matches with the specified value.
     *
     * @param choices           The list of sizes that the camera supports for the intended output
     *                          class
     * @param textureViewWidth  The width of the texture view relative to sensor coordinate
     * @param textureViewHeight The height of the texture view relative to sensor coordinate
     * @param maxWidth          The maximum width that can be chosen
     * @param maxHeight         The maximum height that can be chosen
     * @return The optimal {@code Size}, or an arbitrary one if none were big enough
     */
Given  choices of  Sizes supported by a camera, choose the smallest one that
is at least as large as the respective texture view size, and that is at most as large as the
respective max size, and whose aspect ratio matches with the specified value. If such size
doesn't exist, choose the largest one that is at most as large as the respective max size,
and whose aspect ratio matches with the specified value.


Given choices of Sizes supported by a camera choose the smallest one that is at least as large as the respective texture view size and that is at most as large as the respective max size and whose aspect ratio matches with the specified value . If such size doesn ' t exist choose the largest one that is at most as large as the respective max size and whose aspect ratio matches with the specified value .
Size chooseOptimalSize(Size[] choices, int textureViewWidth,
                           int textureViewHeight, int maxWidth, int maxHeight) {
        mPreviewSizes.clear();
        List<Size> bigEnough = new ArrayList<>();
        List<Size> notBigEnough = new ArrayList<>();
        int w = mAspectRatio.getX();
        int h = mAspectRatio.getY();
        for (Size option : choices) {
            if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight) {
                mPreviewSizes.add(new cn.lytcom.camera2kit.Size(option.getWidth(), option.getHeight()));
                if (option.getHeight() == option.getWidth() * h / w) {
                    if (option.getWidth() >= textureViewWidth &&
                        option.getHeight() >= textureViewHeight) {
                        bigEnough.add(option);
                    } else {
                        notBigEnough.add(option);
                    }
                }
            }
        }
        if (bigEnough.size() > 0) {
            return Collections.min(bigEnough, new CompareSizesByArea());
        } else if (notBigEnough.size() > 0) {
            return Collections.max(notBigEnough, new CompareSizesByArea());
        } else {
            Log.e(TAG, "Couldn't find any suitable preview size");
            mAspectRatio = AspectRatio.of(4, 3);
            SortedSet<cn.lytcom.camera2kit.Size> sortedSet = mPreviewSizes.sizes(mAspectRatio);
            if (sortedSet != null) {
                cn.lytcom.camera2kit.Size lastSize = sortedSet.last();
                return new Size(lastSize.getWidth(), lastSize.getHeight());
            }
            mAspectRatio = AspectRatio.of(choices[0].getWidth(), choices[0].getHeight());
            return choices[0];
        }
    }
Size chooseOptimalSize ( Size [ ] choices , int textureViewWidth , int textureViewHeight , int maxWidth , int maxHeight ) { mPreviewSizes . clear ( ) ; List < Size > bigEnough = new ArrayList < > ( ) ; List < Size > notBigEnough = new ArrayList < > ( ) ; int w = mAspectRatio . getX ( ) ; int h = mAspectRatio . getY ( ) ; for ( Size option : choices ) { if ( option . getWidth ( ) <= maxWidth && option . getHeight ( ) <= maxHeight ) { mPreviewSizes . add ( new cn . lytcom . camera2kit . Size ( option . getWidth ( ) , option . getHeight ( ) ) ) ; if ( option . getHeight ( ) == option . getWidth ( ) * h / w ) { if ( option . getWidth ( ) >= textureViewWidth && option . getHeight ( ) >= textureViewHeight ) { bigEnough . add ( option ) ; } else { notBigEnough . add ( option ) ; } } } } if ( bigEnough . size ( ) > 0 ) { return Collections . min ( bigEnough , new CompareSizesByArea ( ) ) ; } else if ( notBigEnough . size ( ) > 0 ) { return Collections . max ( notBigEnough , new CompareSizesByArea ( ) ) ; } else { Log . e ( TAG , "Couldn't find any suitable preview size" ) ; mAspectRatio = AspectRatio . of ( 4 , 3 ) ; SortedSet < cn . lytcom . camera2kit . Size > sortedSet = mPreviewSizes . sizes ( mAspectRatio ) ; if ( sortedSet != null ) { cn . lytcom . camera2kit . Size lastSize = sortedSet . last ( ) ; return new Size ( lastSize . getWidth ( ) , lastSize . getHeight ( ) ) ; } mAspectRatio = AspectRatio . of ( choices [ 0 ] . getWidth ( ) , choices [ 0 ] . getHeight ( ) ) ; return choices [ 0 ] ; } }
Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 is at least as large as the respective texture view size, and that is at most as large as the
 respective max size, and whose aspect ratio matches with the specified value.
Given { @code choices } of { @code Size } s supported by a camera choose the smallest one that is at least as large as the respective texture view size and that is at most as large as the respective max size and whose aspect ratio matches with the specified value .
// Collect the supported resolutions that are at least as big as the preview Surface // Collect the supported resolutions that are smaller than the preview Surface // Pick the smallest of those big enough. If there is no one big enough, pick the // largest of those not big enough.