|
|
@ -6,7 +6,6 @@ import android.annotation.TargetApi; |
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Activity; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.VisibleForTesting; |
|
|
|
import androidx.annotation.VisibleForTesting; |
|
|
|
import androidx.core.view.ViewCompat; |
|
|
|
|
|
|
|
import androidx.lifecycle.Lifecycle; |
|
|
|
import androidx.lifecycle.Lifecycle; |
|
|
|
import androidx.lifecycle.LifecycleObserver; |
|
|
|
import androidx.lifecycle.LifecycleObserver; |
|
|
|
import androidx.lifecycle.LifecycleOwner; |
|
|
|
import androidx.lifecycle.LifecycleOwner; |
|
|
@ -830,14 +829,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setPreview(@NonNull Preview preview) { |
|
|
|
public void setPreview(@NonNull Preview preview) { |
|
|
|
boolean isNew = preview != mPreview; |
|
|
|
boolean isNew = preview != mPreview; |
|
|
|
if (!isNew) return; |
|
|
|
if (isNew) { |
|
|
|
mPreview = preview; |
|
|
|
mPreview = preview; |
|
|
|
if (!ViewCompat.isAttachedToWindow(this) && mCameraPreview != null) { |
|
|
|
boolean isAttachedToWindow = getWindowToken() != null; |
|
|
|
|
|
|
|
if (!isAttachedToWindow && mCameraPreview != null) { |
|
|
|
// Null the preview: will create another when re-attaching.
|
|
|
|
// Null the preview: will create another when re-attaching.
|
|
|
|
mCameraPreview.onDestroy(); |
|
|
|
mCameraPreview.onDestroy(); |
|
|
|
mCameraPreview = null; |
|
|
|
mCameraPreview = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the current preview control. |
|
|
|
* Returns the current preview control. |
|
|
|