Skip to content
Snippets Groups Projects
Commit 427d9d4d authored by Drahomír Karchňák's avatar Drahomír Karchňák
Browse files

#612 WIP Added first version of IOS Camera Opener.

parent 8d6670dc
Branches feature-test-profile
Tags
No related merge requests found
......@@ -17,17 +17,109 @@
package cz.nic.tablexia;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.graphics.Pixmap;
import org.robovm.apple.foundation.NSData;
import org.robovm.apple.uikit.UIImage;
import org.robovm.apple.uikit.UIImagePickerController;
import org.robovm.apple.uikit.UIImagePickerControllerCameraCaptureMode;
import org.robovm.apple.uikit.UIImagePickerControllerCameraDevice;
import org.robovm.apple.uikit.UIImagePickerControllerDelegate;
import org.robovm.apple.uikit.UIImagePickerControllerEditingInfo;
import org.robovm.apple.uikit.UIImagePickerControllerSourceType;
import org.robovm.apple.uikit.UIInterfaceOrientation;
import org.robovm.apple.uikit.UIInterfaceOrientationMask;
import org.robovm.apple.uikit.UINavigationController;
import org.robovm.apple.uikit.UINavigationControllerDelegateAdapter;
import org.robovm.apple.uikit.UIViewController;
import java.nio.ByteBuffer;
import cz.nic.tablexia.util.CameraOpener;
public class IOSCameraOpener extends CameraOpener{
public class IOSCameraOpener extends CameraOpener {
private class PickerControllerDelegate extends UINavigationControllerDelegateAdapter implements UIImagePickerControllerDelegate {
@Override
public void didFinishPickingMedia(UIImagePickerController picker, UIImagePickerControllerEditingInfo info) {
UIImage uiImage = info.getOriginalImage();
NSData nsData = uiImage.toPNGData();
ByteBuffer buffer = nsData.asByteBuffer();
byte[] imgData = new byte[buffer.capacity()]; //limit ?
buffer.get(imgData);
Pixmap pixmap = new Pixmap(imgData, 0, imgData.length);
nsData.dispose();
uiImage.dispose();
closeCamera();
onPhotoTaken(pixmap, true);
}
@Override
public void didCancel(UIImagePickerController picker) {
picker.dismissViewController(true, null);
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(UINavigationController navigationController) {
return UIInterfaceOrientationMask.All;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(UINavigationController navigationController) {
return UIInterfaceOrientation.LandscapeLeft;
}
}
private UIViewController appController;
private PickerControllerDelegate delegate;
private UIImagePickerController imagePickerController;
@Override
public void onCameraOpen() {
// TODO: 17.1.17 add iOS implementation
appController = ((IOSApplication) Gdx.app).getUIViewController();
imagePickerController = new UIImagePickerController() {
@Override
public boolean shouldAutorotate() {
return false;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation() {
return UIInterfaceOrientation.LandscapeRight;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations() {
return UIInterfaceOrientationMask.All;
}
};
imagePickerController.getView().setBounds(appController.getView().getBounds());
imagePickerController.setSourceType(UIImagePickerControllerSourceType.Camera);
imagePickerController.setCameraCaptureMode(UIImagePickerControllerCameraCaptureMode.Photo);
imagePickerController.setCameraDevice(UIImagePickerControllerCameraDevice.Front);
delegate = new PickerControllerDelegate();
imagePickerController.setDelegate(delegate);
appController.presentViewController(imagePickerController, true, null);
}
@Override
public void onCameraClose() {
delegate.dispose();
delegate = null;
imagePickerController.dismissViewController(true, null);
imagePickerController.removeFromParentViewController();
imagePickerController = null;
}
@Override
......
......@@ -21,11 +21,8 @@ import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
import org.robovm.apple.coreservices.CFHost;
import org.robovm.apple.coreservices.CFHostInfoType;
import org.robovm.apple.foundation.NSData;
import org.robovm.apple.foundation.NSException;
import org.robovm.apple.uikit.UIImage;
......@@ -37,11 +34,7 @@ import org.robovm.apple.uikit.UIInterfaceOrientation;
import org.robovm.apple.uikit.UIInterfaceOrientationMask;
import org.robovm.apple.uikit.UINavigationController;
import org.robovm.apple.uikit.UINavigationControllerDelegateAdapter;
import org.robovm.apple.uikit.UINavigationControllerOperation;
import org.robovm.apple.uikit.UIViewController;
import org.robovm.apple.uikit.UIViewControllerAnimatedTransitioning;
import org.robovm.apple.uikit.UIViewControllerInteractiveTransitioning;
import org.robovm.apple.uikit.UIWindow;
import org.robovm.objc.ObjCObject;
import org.robovm.objc.block.VoidBlock1;
import org.robovm.apple.foundation.NSAutoreleasePool;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment