private void Process(CaptureResult result)
        {
            switch (Owner.mState)
            {
                case Camera2BasicFragment.STATE_WAITING_LOCK:
                    {
                        Integer afState = (Integer)result.Get(CaptureResult.ControlAfState);
                        if (afState == null)
                        {
                            Owner.CaptureStillPicture();
                        }

                        else if ((((int)ControlAFState.FocusedLocked) == afState.IntValue()) ||
                                   (((int)ControlAFState.NotFocusedLocked) == afState.IntValue()))
                        {
                            // ControlAeState can be null on some devices
                            Integer aeState = (Integer)result.Get(CaptureResult.ControlAeState);
                            if (aeState == null ||
                                    aeState.IntValue() == ((int)ControlAEState.Converged))
                            {
                                Owner.mState = Camera2BasicFragment.STATE_PICTURE_TAKEN;
                                Owner.CaptureStillPicture();
                            }
                            else
                            {
                                Owner.RunPrecaptureSequence();
                            }
                        }
                        break;
                    }
                case Camera2BasicFragment.STATE_WAITING_PRECAPTURE:
                    {
                        // ControlAeState can be null on some devices
                        Integer aeState = (Integer)result.Get(CaptureResult.ControlAeState);
                        if (aeState == null ||
                                aeState.IntValue() == ((int)ControlAEState.Precapture) ||
                                aeState.IntValue() == ((int)ControlAEState.FlashRequired))
                        {
                            Owner.mState = Camera2BasicFragment.STATE_WAITING_NON_PRECAPTURE;
                        }
                        break;
                    }
                case Camera2BasicFragment.STATE_WAITING_NON_PRECAPTURE:
                    {
                        // ControlAeState can be null on some devices
                        Integer aeState = (Integer)result.Get(CaptureResult.ControlAeState);
                        if (aeState == null || aeState.IntValue() != ((int)ControlAEState.Precapture))
                        {
                            Owner.mState = Camera2BasicFragment.STATE_PICTURE_TAKEN;
                            Owner.CaptureStillPicture();
                        }
                        break;
                    }
            }
        }
        private void Process(CaptureResult result)
        {
            switch (_controller.State)
            {
                case CameraState.WaitingLock:

                    var afState = result.Get(CaptureResult.ControlAfState) as Integer;
                    if (afState == null)
                    {
                        _controller.CaptureStillPicture();
                    }
                    else if ((int)ControlAFState.FocusedLocked == (int)afState || (int)ControlAFState.NotFocusedLocked == (int)afState)
                    {
                        // CONTROL_AE_STATE can be null on some devices
                        var ae = result.Get(CaptureResult.ControlAeState) as Integer;
                        if (ae == null || ae.IntValue() == (int)ControlAEState.Converged)
                        {
                            _controller.State = CameraState.PictureTaken;
                            _controller.CaptureStillPicture();
                        }
                        else
                        {
                            _controller.RunPrecaptureSequence();
                        }
                    }
                    break;
                case CameraState.WaitingPrecapture:
                    // CONTROL_AE_STATE can be null on some devices
                    var state = result.Get(CaptureResult.ControlAeState) as Integer;
                    if (state == null || state.IntValue() == (int)ControlAEState.Precapture || state.IntValue() == (int)ControlAEState.FlashRequired)
                    {
                        _controller.State = CameraState.WaitingNonPrecapture;
                    }
                    break;
                case CameraState.WaitingNonPrecapture:
                    // CONTROL_AE_STATE can be null on some devices
                    var aeState = result.Get(CaptureResult.ControlAeState) as Integer;
                    if (aeState == null || aeState.IntValue() == (int)ControlAEState.Precapture)
                    {
                        _controller.State = CameraState.PictureTaken;
                        _controller.CaptureStillPicture();
                    }
                    break;
            }
        }
 public override void OnCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)
 {
     Process(partialResult);
 }