Java Code Examples for android.util.Size#equals()
The following examples show how to use
android.util.Size#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraConnectionFragment.java From android-yolo-v2 with Do What The F*ck You Want To Public License | 6 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(final Size[] choices) { final int minSize = Math.max(Math.min(DESIRED_PREVIEW_SIZE.getWidth(), DESIRED_PREVIEW_SIZE.getHeight()), MINIMUM_PREVIEW_SIZE); // Collect the supported resolutions that are at least as big as the preview Surface final List<Size> bigEnough = new ArrayList(); for (final Size option : choices) { if (option.equals(DESIRED_PREVIEW_SIZE)) { return DESIRED_PREVIEW_SIZE; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any return (bigEnough.size() > 0) ? Collections.min(bigEnough, new CompareSizesByArea()) : choices[0]; }
Example 2
Source File: LegacyCameraDevice.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
static Size findClosestSize(Size size, Size[] supportedSizes) { if (size == null || supportedSizes == null) { return null; } Size bestSize = null; for (Size s : supportedSizes) { if (s.equals(size)) { return size; } else if (s.getWidth() <= MAX_DIMEN_FOR_ROUNDING && (bestSize == null || LegacyCameraDevice.findEuclidDistSquare(size, s) < LegacyCameraDevice.findEuclidDistSquare(bestSize, s))) { bestSize = s; } } return bestSize; }
Example 3
Source File: SizeAreaComparator.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public int compare(Size size, Size size2) { checkNotNull(size, "size must not be null"); checkNotNull(size2, "size2 must not be null"); if (size.equals(size2)) { return 0; } long width = size.getWidth(); long width2 = size2.getWidth(); long area = width * size.getHeight(); long area2 = width2 * size2.getHeight(); if (area == area2) { return (width > width2) ? 1 : -1; } return (area > area2) ? 1 : -1; }
Example 4
Source File: OutputConfiguration.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Add a surface to this OutputConfiguration. * * <p> This function can be called before or after {@link * CameraDevice#createCaptureSessionByOutputConfigurations}. If it's called after, * the application must finalize the capture session with * {@link CameraCaptureSession#finalizeOutputConfigurations}. It is possible to call this method * after the output configurations have been finalized only in cases of enabled surface sharing * see {@link #enableSurfaceSharing}. The modified output configuration must be updated with * {@link CameraCaptureSession#updateOutputConfiguration}.</p> * * <p> If the OutputConfiguration was constructed with a deferred surface by {@link * OutputConfiguration#OutputConfiguration(Size, Class)}, the added surface must be obtained * from {@link android.view.SurfaceView} by calling {@link android.view.SurfaceHolder#getSurface}, * or from {@link android.graphics.SurfaceTexture} via * {@link android.view.Surface#Surface(android.graphics.SurfaceTexture)}).</p> * * <p> If the OutputConfiguration was constructed by other constructors, the added * surface must be compatible with the existing surface. See {@link #enableSurfaceSharing} for * details of compatible surfaces.</p> * * <p> If the OutputConfiguration already contains a Surface, {@link #enableSurfaceSharing} must * be called before calling this function to add a new Surface.</p> * * @param surface The surface to be added. * @throws IllegalArgumentException if the Surface is invalid, the Surface's * dataspace/format doesn't match, or adding the Surface would exceed number of * shared surfaces supported. * @throws IllegalStateException if the Surface was already added to this OutputConfiguration, * or if the OutputConfiguration is not shared and it already has a surface associated * with it. */ public void addSurface(@NonNull Surface surface) { checkNotNull(surface, "Surface must not be null"); if (mSurfaces.contains(surface)) { throw new IllegalStateException("Surface is already added!"); } if (mSurfaces.size() == 1 && !mIsShared) { throw new IllegalStateException("Cannot have 2 surfaces for a non-sharing configuration"); } if (mSurfaces.size() + 1 > MAX_SURFACES_COUNT) { throw new IllegalArgumentException("Exceeds maximum number of surfaces"); } // This will throw IAE is the surface was abandoned. Size surfaceSize = SurfaceUtils.getSurfaceSize(surface); if (!surfaceSize.equals(mConfiguredSize)) { Log.w(TAG, "Added surface size " + surfaceSize + " is different than pre-configured size " + mConfiguredSize + ", the pre-configured size will be used."); } if (mConfiguredFormat != SurfaceUtils.getSurfaceFormat(surface)) { throw new IllegalArgumentException("The format of added surface format doesn't match"); } // If the surface format is PRIVATE, do not enforce dataSpace because camera device may // override it. if (mConfiguredFormat != ImageFormat.PRIVATE && mConfiguredDataspace != SurfaceUtils.getSurfaceDataspace(surface)) { throw new IllegalArgumentException("The dataspace of added surface doesn't match"); } mSurfaces.add(surface); }
Example 5
Source File: CameraConnectionFragment.java From dbclf with Apache License 2.0 | 5 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } } if (exactSizeFound) { return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); return chosenSize; } else { return choices[0]; } }
Example 6
Source File: CameraConnectionFragment.java From next18-ai-in-motion with Apache License 2.0 | 5 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } if (exactSizeFound) { return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); return chosenSize; } else { return choices[0]; } }
Example 7
Source File: ImageTransferFormatSelectorPageFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Context context = getContext(); if (context == null) return; Size[] resolutions = mIsEInkMode ? kEInkResolutions : kStandardResolutions; // add a radio button list int checkedItem = -1; final ArrayAdapter<String> resolutionsAdapter = new ArrayAdapter<>(context, android.R.layout.select_dialog_singlechoice); for (int i = 0; i < resolutions.length; i++) { Size size = resolutions[i]; resolutionsAdapter.add(String.format(Locale.US, "%d x %d", size.getWidth(), size.getHeight())); if (size.equals(mResolution)) { checkedItem = i; } } ListView listView = view.findViewById(R.id.listView); listView.setAdapter(resolutionsAdapter); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); if (checkedItem >= 0) { listView.setItemChecked(checkedItem, true); } listView.setOnItemClickListener((parent, view1, position, id) -> { if (mListener != null) { Size[] currentResolutions = mIsEInkMode ? kEInkResolutions : kStandardResolutions; mListener.onResolutionSelected(currentResolutions[position], mIsEInkMode); } }); }
Example 8
Source File: CameraXUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@RequiresApi(21) private static boolean shouldCropImage(@NonNull ImageProxy image) { Size sourceSize = new Size(image.getWidth(), image.getHeight()); Size targetSize = new Size(image.getCropRect().width(), image.getCropRect().height()); return !targetSize.equals(sourceSize); }
Example 9
Source File: StreamConfigurationMap.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Get the frame per second ranges (fpsMin, fpsMax) for input high speed video size. * <p> * See {@link #getHighSpeedVideoFpsRanges} for how to enable high speed recording. * </p> * <p> * The {@link CaptureRequest#CONTROL_AE_TARGET_FPS_RANGE FPS ranges} reported in this method * must not be used to setup capture requests that are submitted to unconstrained capture * sessions, or it will result in {@link IllegalArgumentException IllegalArgumentExceptions}. * </p> * <p> * See {@link #getHighSpeedVideoFpsRanges} for the characteristics of the returned FPS ranges. * </p> * * @param size one of the sizes returned by {@link #getHighSpeedVideoSizes()} * @return an array of supported high speed video recording FPS ranges The upper bound of * returned ranges is guaranteed to be greater than or equal to 120. * @throws IllegalArgumentException if input size does not exist in the return value of * getHighSpeedVideoSizes * @see #getHighSpeedVideoSizes() * @see #getHighSpeedVideoFpsRanges() */ public Range<Integer>[] getHighSpeedVideoFpsRangesFor(Size size) { Integer fpsRangeCount = mHighSpeedVideoSizeMap.get(size); if (fpsRangeCount == null || fpsRangeCount == 0) { throw new IllegalArgumentException(String.format( "Size %s does not support high speed video recording", size)); } @SuppressWarnings("unchecked") Range<Integer>[] fpsRanges = new Range[fpsRangeCount]; int i = 0; for (HighSpeedVideoConfiguration config : mHighSpeedVideoConfigurations) { if (size.equals(config.getSize())) { fpsRanges[i++] = config.getFpsRange(); } } return fpsRanges; }
Example 10
Source File: CameraConnectionFragment.java From tensorflow-classifier-android with Apache License 2.0 | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } LOGGER.i("Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); LOGGER.i("Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); LOGGER.i("Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { LOGGER.i("Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); LOGGER.i("Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { LOGGER.e("Couldn't find any suitable preview size"); return choices[0]; } }
Example 11
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 12
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 13
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 14
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 15
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 16
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 17
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 18
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 19
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 20
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }