Example #1
0
        // Gets the configurations of all cameras in the device
        private async Task <List <CameraConfig> > GetCameraConfigurations()
        {
            // Try load the camera configurations from preferences
            List <CameraConfig> cameraConfigList =
                (PreferencesManager.Instance.Contains(KEY_CAMERA_CONFIG)) ?
                PreferencesManager.Instance.Get <List <CameraConfig> >(KEY_CAMERA_CONFIG) :
                new List <CameraConfig>();

            if (cameraConfigList.Count != 2)
            {
                // Front camera config. Read configuration if not available.
                CameraConfig frontCameraConfig =
                    cameraConfigList.Where(config => config.Type.Equals(CameraType.FrontFacing)).
                    FirstOrDefault();
                if (frontCameraConfig == null)
                {
                    frontCameraConfig = await GetCameraConfiguration(
                        CameraType.FrontFacing, CameraSensorLocation.Front);

                    if (frontCameraConfig != null)
                    {
                        cameraConfigList.Add(frontCameraConfig);
                    }
                }

                // Back camera config. Read configuration if not available.
                CameraConfig backCameraConfig =
                    cameraConfigList.Where(config => config.Type.Equals(CameraType.Primary)).
                    FirstOrDefault();
                if (backCameraConfig == null)
                {
                    backCameraConfig = await GetCameraConfiguration(
                        CameraType.Primary, CameraSensorLocation.Back);

                    if (backCameraConfig != null)
                    {
                        cameraConfigList.Add(backCameraConfig);
                    }
                }

                // Update preferences
                if (cameraConfigList.Count > 0)
                {
                    PreferencesManager.Instance.Put <List <CameraConfig> >(
                        KEY_CAMERA_CONFIG, cameraConfigList);
                }
            }
            return(cameraConfigList);
        }