public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Open an instance of the first camera and retrieve its info. camera = GetCameraInstance(CAMERA_ID); Camera.CameraInfo cameraInfo = null; if (camera != null) { // Get camera info only if the camera is available cameraInfo = new Camera.CameraInfo(); Camera.GetCameraInfo(CAMERA_ID, cameraInfo); } if (camera == null || cameraInfo == null) { Toast.MakeText(Activity, "Camera is not available.", ToastLength.Short).Show(); return(inflater.Inflate(Resource.Layout.fragment_camera_unavailable, null)); } View root = inflater.Inflate(Resource.Layout.fragment_camera, null); // Get the rotation of the screen to adjust the preview image accordingly. SurfaceOrientation displayRotation = Activity.WindowManager.DefaultDisplay.Rotation; // Create the Preview view and set it as the content of this Activity. cameraPreview = new CameraPreview(Activity, camera, cameraInfo, displayRotation); var preview = root.FindViewById <FrameLayout> (Resource.Id.camera_preview); preview.AddView(cameraPreview); return(root); }
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Open an instance of the first camera and retrieve its info. camera = GetCameraInstance (CAMERA_ID); Camera.CameraInfo cameraInfo = null; if (camera != null) { // Get camera info only if the camera is available cameraInfo = new Camera.CameraInfo (); Camera.GetCameraInfo (CAMERA_ID, cameraInfo); } if (camera == null || cameraInfo == null) { Toast.MakeText (Activity, "Camera is not available.", ToastLength.Short).Show (); return inflater.Inflate (Resource.Layout.fragment_camera_unavailable, null); } View root = inflater.Inflate (Resource.Layout.fragment_camera, null); // Get the rotation of the screen to adjust the preview image accordingly. SurfaceOrientation displayRotation = Activity.WindowManager.DefaultDisplay.Rotation; // Create the Preview view and set it as the content of this Activity. cameraPreview = new CameraPreview (Activity, camera, cameraInfo, displayRotation); var preview = root.FindViewById <FrameLayout> (Resource.Id.camera_preview); preview.AddView (cameraPreview); return root; }