Skip to content

Instantly share code, notes, and snippets.

@confile
Created June 12, 2015 21:33
Show Gist options
  • Save confile/fe32f7b6035660f72571 to your computer and use it in GitHub Desktop.
Save confile/fe32f7b6035660f72571 to your computer and use it in GitHub Desktop.
CameraManagerImpl.java
package buddyis.core.app.photoEditor.cameraManager;
import javax.inject.Inject;
import buddyis.core.app.photoEditor.events.PhotoCreatedEvent;
import buddyis.core.i18n.Message;
import buddyis.core.plugins.actionSheet.ActionSheet;
import buddyis.core.plugins.actionSheet.ActionSheetCallback;
import buddyis.core.plugins.actionSheet.ActionSheetOptions;
import buddyis.core.plugins.bcamera.BCamera;
import buddyis.core.plugins.bcamera.BCameraCallback;
import buddyis.core.plugins.cameraFallback.CameraFallback;
import buddyis.core.plugins.cameraFallback.CameraFallbackCallback;
import buddyis.core.plugins.notification.Notification;
import buddyis.core.plugins.spinner.Spinner;
import buddyis.core.plugins.systemConfig.SystemConfig;
import buddyis.core.prototype.eventBus.BEventBus;
public class CameraManagerImpl implements CameraManager {
private final BEventBus eventBus;
private final Message message;
private final Spinner spinner;
private final Notification notification;
private final ActionSheet actionSheet;
private final BCamera bCamera;
private final SystemConfig systemConfig;
private final CameraFallback cameraFallback;
@Inject
public CameraManagerImpl(BEventBus eventBus, Message message, Spinner spinner, Notification notification,
ActionSheet actionSheet, BCamera bCamera, SystemConfig systemConfig, CameraFallback cameraFallback) {
this.eventBus = eventBus;
this.message = message;
this.spinner = spinner;
this.notification = notification;
this.actionSheet = actionSheet;
this.bCamera = bCamera;
this.systemConfig = systemConfig;
this.cameraFallback = cameraFallback;
}
private void getCameraURI() {
cameraFallback.getImage(SourceType.CAMERA_IMAGE, new CameraFallbackCallback() {
@Override
public void onPicture(String imageURI) {
// spinner.show();
eventBus.fireEventFromSource(new PhotoCreatedEvent(imageURI), CameraManagerImpl.this);
}
});
}
private void getPhotoURI() {
cameraFallback.getImage(SourceType.ALBUM_IMAGE, new CameraFallbackCallback() {
@Override
public void onPicture(String imageURI) {
// spinner.show();
eventBus.fireEventFromSource(new PhotoCreatedEvent(imageURI), CameraManagerImpl.this);
}
});
}
@Override
public void getPhotoWorkaround() {
if (systemConfig.isIOs()) {
bCamera.getPicture(new BCameraCallback() {
@Override
public void onSuccess(String uri) {
spinner.show();
eventBus.fireEvent(new PhotoCreatedEvent(uri));
}
@Override
public void onFailure() {
}
});
}
else {
// Android device
ActionSheetOptions actionOptions = new ActionSheetOptions();
String[] buttonLabel = new String[] {
message.lookup("camera"), message.lookup("album") };
actionOptions.addButtonLabels(buttonLabel);
actionOptions.addCancelButtonWithText(message.lookup("cancel"));
actionOptions.androidEnableCancelButton(true);
actionSheet.show(actionOptions, new ActionSheetCallback() {
@Override
public void onButtonTap(int index) {
if (index == 1) {
getCameraURI();
}
else if (index == 2) {
getPhotoURI();
}
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment