Here are the examples of the java api class android.util.Size taken from open source projects.
1. Camera2Fragment#chooseVideoSize()
Project: material-camera
File: Camera2Fragment.java
File: Camera2Fragment.java
private static Size chooseVideoSize(BaseCaptureInterface ci, Size[] choices) { Size backupSize = null; for (Size size : choices) { if (size.getHeight() <= ci.videoPreferredHeight()) { if (size.getWidth() == size.getHeight() * ci.videoPreferredAspect()) return size; if (ci.videoPreferredHeight() >= size.getHeight()) backupSize = size; } } if (backupSize != null) return backupSize; LOG(Camera2Fragment.class, "Couldn't find any suitable video size"); return choices[choices.length - 1]; }
2. CameraFragment#chooseOptimalSize()
Project: io2015-codelabs
File: CameraFragment.java
File: CameraFragment.java
/** * 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 respective requested values, 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 width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { Log.d(TAG, "chooseOptimalSize: "); // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<Size>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
3. Camera2Fragment#chooseOptimalSize()
Project: material-camera
File: Camera2Fragment.java
File: Camera2Fragment.java
private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { LOG(Camera2Fragment.class, "Couldn't find any suitable preview size"); return aspectRatio; } }
4. CameraFragment#chooseOptimalSize()
Project: io2015-codelabs
File: CameraFragment.java
File: CameraFragment.java
/** * 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 respective requested values, 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 width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { Log.d(TAG, "chooseOptimalSize: "); // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<Size>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }