I\'ve got my CWAC Camera fragment setup, and everything is working nicely. There\'s a few customizations I\'d like to do.
To be notified when the camera is loaded and preview started, use this code:
public class MyCameraFragment extends CameraFragment {
CameraView cameraView;
Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
// camera is "loaded" and first preview is sent to the screen
// do whatever you want to do
}
};
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
cameraView = // code to find your CameraView
}
@Override
public void onResume() {
super.onResume();
Camera camera = cameraView.getCamera();
if (null != camera) {
camera.setOneShotPreviewCallback(previewCallback);
}
}
private void somehowRestartedCameraViewForWhateverReason() {
if (null != cameraView) {
cameraView.onResume(); // force it to restart
Camera camera = cameraView.getCamera();
if (null != camera) {
camera.setOneShotPreviewCallback(previewCallback);
}
}
}
}
I used this code to update the UI, so that flash button only appears when camera supported:
camera.getParameters().getSupportedFlashModes()
return non-null List and size > 0. Usually Front Facing Camera has no flash but who knows?
If you want to switch camera, please also see my other answer here: CWAC Camera - Multiple camera views in one layout (and switching between them)
I'd like to show a ProgressBar as the camera is loading into the Activity/Fragment
I have no idea what "loading into the Activity/Fragment" means.
After a user has taken a picture, I want to show a ProgressBar again overlay on the picture taking button, so they understand they can't immediately take a picture until the camera is ready again
You know when you are calling takePicture()
. You can know when saveImage()
is called on your CameraHost
by creating your own implementation of CameraHost
or own subclass of SimpleCameraHost
. You can do your ProgressBar
work at those times. You can see this in the demo app, where I disable and re-enable the action bar item for the same purpose.