Cwac Camera - Multiple Camera Views In One Layout (and Switching Between Them)
Solution 1:
I just realized that I could pass the image data from fragment to fragment (or pass a URI since the images are way over the 1 MB intent limit), but it seems like there should be an easier way to do this.
Have the hosting activity hold onto the images.
Or, have a retained fragment hold onto the images, if you are supporting configuration changes.
Solution 2:
Not sure if you still looking for a single-fragment solution. But I manage to switch the front/back camera using following code without creating another fragment. So, you may modifying a bit and it should fit yours.
My solution is as simple as removing the current CameraView instance and add a new one. If you prefer add it to another frame, be my guest.
The CameraView is added dynamically into a Framelayout:
publicclassMyCameraFragmentextendsCameraFragment {
CameraView cameraView;
@OverridepublicvoidonViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
addCameraView(view);
}
privatevoidaddCameraView(View view) {
FrameLayout frame = (FrameLayout)v.findViewById(R.id.cameraFrame);
frame.removeAllViews();
cameraView = newCameraView(getActivity());
cameraView.setHost(cameraHost = newMyCameraHost(getActivity()));
setCameraView(cameraView);
frame.addView(cameraView);
}
privatevoiddoSwitchCamera() {
// do some change to the settings.
useFrontFacingCamera = !useFrontFacingCamera;
if (null != cameraView) {
cameraView.onPause();
}
addCameraView(getView());
cameraView.onResume();
}
}
I'm not sure if super.onPause() and super.onResume() is necessary but they do call the onPause() and onResume() of CameraView, which I believe it is necessary.
Edited: after some code investigation and testing, I found that calling super.onPause/onResume is not necessary. Just call onPause and onResume on the cameraView is enough.
Post a Comment for "Cwac Camera - Multiple Camera Views In One Layout (and Switching Between Them)"