diff --git a/library/src/main/api14/com/google/android/cameraview/Camera1.java b/library/src/main/api14/com/google/android/cameraview/Camera1.java index 1830c185..8dc6f9f0 100644 --- a/library/src/main/api14/com/google/android/cameraview/Camera1.java +++ b/library/src/main/api14/com/google/android/cameraview/Camera1.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.atomic.AtomicBoolean; @@ -151,7 +152,9 @@ int getFacing() { @Override Set getSupportedAspectRatios() { SizeMap idealAspectRatios = mPreviewSizes; - for (AspectRatio aspectRatio : idealAspectRatios.ratios()) { + + Set ratios = new TreeSet<>(idealAspectRatios.ratios()); + for (AspectRatio aspectRatio : ratios) { if (mPictureSizes.sizes(aspectRatio) == null) { idealAspectRatios.remove(aspectRatio); } diff --git a/library/src/main/java/com/google/android/cameraview/CameraView.java b/library/src/main/java/com/google/android/cameraview/CameraView.java index 04826d84..fe4d550f 100644 --- a/library/src/main/java/com/google/android/cameraview/CameraView.java +++ b/library/src/main/java/com/google/android/cameraview/CameraView.java @@ -244,6 +244,9 @@ protected void onRestoreInstanceState(Parcelable state) { */ public void start() { if (!mImpl.start()) { + if (mImpl.getView() != null) { + this.removeView(mImpl.getView()); + } //store the state ,and restore this state after fall back o Camera1 Parcelable state=onSaveInstanceState(); // Camera2 uses legacy hardware layer; fall back to Camera1