|
|
@ -75,11 +75,22 @@ public class CameraView extends FrameLayout { |
|
|
|
private Handler mUiHandler; |
|
|
|
private Handler mUiHandler; |
|
|
|
private WorkerHandler mWorkerHandler; |
|
|
|
private WorkerHandler mWorkerHandler; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param context |
|
|
|
|
|
|
|
* @throws CameraUnavailableException if the initialization failed for any (camera-related) reason. |
|
|
|
|
|
|
|
*/ |
|
|
|
public CameraView(@NonNull Context context) { |
|
|
|
public CameraView(@NonNull Context context) { |
|
|
|
super(context, null); |
|
|
|
super(context, null); |
|
|
|
init(context, null); |
|
|
|
init(context, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param context |
|
|
|
|
|
|
|
* @param attrs |
|
|
|
|
|
|
|
* @throws CameraUnavailableException if the initialization failed for any (camera-related) reason. |
|
|
|
|
|
|
|
*/ |
|
|
|
public CameraView(@NonNull Context context, @Nullable AttributeSet attrs) { |
|
|
|
public CameraView(@NonNull Context context, @Nullable AttributeSet attrs) { |
|
|
|
super(context, attrs); |
|
|
|
super(context, attrs); |
|
|
|
init(context, attrs); |
|
|
|
init(context, attrs); |
|
|
@ -87,8 +98,15 @@ public class CameraView extends FrameLayout { |
|
|
|
|
|
|
|
|
|
|
|
//region Init
|
|
|
|
//region Init
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param context |
|
|
|
|
|
|
|
* @param attrs |
|
|
|
|
|
|
|
* @throws CameraUnavailableException if the initialization failed for any (camera-related) reason. |
|
|
|
|
|
|
|
*/ |
|
|
|
@SuppressWarnings("WrongConstant") |
|
|
|
@SuppressWarnings("WrongConstant") |
|
|
|
private void init(@NonNull Context context, @Nullable AttributeSet attrs) { |
|
|
|
private void init(@NonNull Context context, @Nullable AttributeSet attrs) { |
|
|
|
|
|
|
|
try { |
|
|
|
setWillNotDraw(false); |
|
|
|
setWillNotDraw(false); |
|
|
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); |
|
|
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); |
|
|
|
// Self managed
|
|
|
|
// Self managed
|
|
|
@ -157,6 +175,14 @@ public class CameraView extends FrameLayout { |
|
|
|
mOrientationHelper = new OrientationHelper(context, mCameraCallbacks); |
|
|
|
mOrientationHelper = new OrientationHelper(context, mCameraCallbacks); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (CameraException e) { |
|
|
|
|
|
|
|
// Some rare exceptions can occur during the camera initialization.
|
|
|
|
|
|
|
|
// For instance, Camera.getCameraInfo() may fail for inevitable hardware reasons.
|
|
|
|
|
|
|
|
// If the initialization failed for any (camera-related) reason, the camera gets
|
|
|
|
|
|
|
|
// completely unavailable.
|
|
|
|
|
|
|
|
throw new CameraUnavailableException("Failed to initialize the camera.", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected CameraController instantiateCameraController(CameraCallbacks callbacks) { |
|
|
|
protected CameraController instantiateCameraController(CameraCallbacks callbacks) { |
|
|
|
return new Camera1(callbacks); |
|
|
|
return new Camera1(callbacks); |
|
|
|