private void getImageByTye(UIImagePickerControllerSourceType type,
final IActionListener listener) {
final UIViewController uiViewController = ((IOSApplication) Gdx.app)
.getUIViewController();
UIImagePickerController imagePicker = new UIImagePickerController();
uiViewController.addChildViewController(imagePicker);
uiViewController.getView().addSubview(imagePicker.getView());
imagePicker.getView().setBounds(uiViewController.getView().getBounds());
imagePicker
.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary);
UIImagePickerControllerDelegate delegate = new UIImagePickerControllerDelegate.Adapter() {
@Override
public void didFinishPickingMedia(UIImagePickerController picker,
NSDictionary info) {
String imageUrl = info.get(
new NSString("UIImagePickerControllerReferenceURL"))
.toString();
System.out.println(imageUrl);
}
};
imagePicker.setDelegate(delegate);
imagePicker.addStrongRef((ObjCObject) delegate);
}
--
You received this message because you are subscribed to the Google Groups "RoboVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
@implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
@endBut in eclipse java project I dont know how to bridge it. Can you help me please? Thanks
UIViewController controller =((IOSApplication) Gdx.app).getUIViewController();
But if I create MyUIViewController with:
public class MyUIViewController extends UIViewController{
@Override
public boolean shouldAutorotate() {
return true;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(){
return UIInterfaceOrientationMask.Landscape;
}
And put:
MyUIViewController myvc =(MyUIViewController) ((IOSApplication) Gdx.app).getUIViewController();
It crashes complaining about an impossible casting:
Exception in thread "main" java.lang.ClassCastException: com.badlogic.gdx.backends.iosrobovm.IOSGraphics$IOSUIViewController cannot be cast to com.myApp.demo.MyUIViewController
Any idea? Many many thanks in advanced!
Best regards,
Luis.
For more options, visit https://groups.google.com/d/optout.
14/05/14 15:42:13: [ERROR] AppLauncher failed with an exception:
14/05/14 15:42:13: [ERROR] java.lang.RuntimeException: Unexpected response from debugserver: $X00#00
14/05/14 15:42:13: [ERROR] at org.robovm.libimobiledevice.util.AppLauncher.launchInternal(AppLauncher.java:708)
14/05/14 15:42:13: [ERROR] at org.robovm.libimobiledevice.util.AppLauncher.launch(AppLauncher.java:814)
14/05/14 15:42:13: [ERROR] at org.robovm.compiler.target.ios.AppLauncherProcess$1.run(AppLauncherProcess.java:67)
Root VC - Supported orientations: UIInterfaceOrientationMask(0x1a = AllButUpsideDown(0x1a))
Root VC - Should Autorotate: true
MyImagePicker - Supported orientations: UIInterfaceOrientationMask(0x1e = All(0x1e))
MyImagePicker - Should Autorotate: false
So, I believe that MyImagePicker is performing as required and the problem comes from RootViewController.
How to override ShouldAutorotate or getSupportedInterfaceOrientations() of my RootViewController?
Why if it is returning 0x1a = AllButUpsideDown(0x1a), it fails even when landscape it is supposed to be in 0x1a?
My app is landscape only and it issue avoids me finishing the App. Please, could yo help me?
Any advice Niklas?
Sources:
MyImagePickerController: This works perfect upon it enters in camera or gallery!
public class MyImagePickerController extends UIImagePickerController {
@Override
public boolean shouldAutorotate() {
return false;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(){
return UIInterfaceOrientationMask.All;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(){
return UIInterfaceOrientation.Portrait;
}
}
IOSLauncher: I think problem is that RootViewController needs to be overridden, but I don't know how to do that. Need help please!
public class IOSLauncher extends IOSApplication.Delegate implements ImagePicker {
byte[] byteArray = null;
@Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
MyApp myApp = new MyApp(this, null, null);
config.orientationLandscape = true;
config.orientationPortrait = false;
IOSApplication myIOSApp = new IOSApplication(myApp, config);
return myIOSApp;
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
@Override
public void openGallery() {
MyImagePickerController imagePicker = new MyImagePickerController();
imagePicker
.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary);
UIWindow keyWindow = UIApplication.getSharedApplication()
.getKeyWindow();
UIViewController rootVC = keyWindow.getRootViewController();
rootVC.presentViewController(imagePicker, true, null);
System.out.println("Root VC - Supported orientations: "
+ rootVC.getSupportedInterfaceOrientations());
System.out.println("Root VC - Should Autorotate: "
+ rootVC.shouldAutorotate());
System.out.println("MyImagePicker - Supported orientations: "
+ imagePicker.getSupportedInterfaceOrientations());
System.out.println("MyImagePicker - Should Autorotate: "
+ imagePicker.shouldAutorotate());
UIImagePickerControllerDelegateAdapter delegate = new UIImagePickerControllerDelegateAdapter() {
@Override
public long getSupportedInterfaceOrientations(
UINavigationController navigationController) {
System.out.println(navigationController
.getSupportedInterfaceOrientations());
// TODO Auto-generated method stub
return 0x18;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(
UINavigationController navigationController) {
// TODO Auto-generated method stub
return UIInterfaceOrientation.LandscapeLeft;
}
@Override
public void didFinishPickingImage(UIImagePickerController picker,
UIImage image, NSDictionary info) {
NSData misbites = image.toPNGData();
byteArray = misbites.getBytes();
System.out.println(byteArray);
picker.dismissViewController(true, null);
// TODO Auto-generated method stub
}
};
imagePicker.setDelegate(delegate);
imagePicker.addStrongRef((ObjCObject) delegate);
}
Many thanks in advance!
Best regards,
Luis.
public class MyImagePickerController extends UIImagePickerController {
@Override
public boolean shouldAutorotate() {
return false;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(){
return UIInterfaceOrientationMask.All;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(){
return UIInterfaceOrientation.LandscapeLeft;
}
}
public class MyUIViewController extends UIViewController{
@Override
public boolean shouldAutorotate() {
return false;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(){
return UIInterfaceOrientationMask.All;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(){
return UIInterfaceOrientation.LandscapeLeft;
}
}
Info.plist.xml: My App cannot be in portrait anyway, it only can draw in landscape.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
IOSLauncher:
public void openGallery() {
final UIWindow keyWindow = UIApplication.getSharedApplication()
.getKeyWindow();
System.out.println(UIApplication.getSharedApplication()
.getSupportedInterfaceOrientations(keyWindow)); //It returns 24. What does it mean?
MyUIViewController rootVC = new MyUIViewController();
final UIViewController originalRootVC = keyWindow.getRootViewController();
keyWindow.setRootViewController(rootVC);
System.out.println("Root VC - Supported orientations: "
+ rootVC.getSupportedInterfaceOrientations());
System.out.println("Root VC - Should Autorotate: "
+ rootVC.shouldAutorotate());
MyImagePickerController imagePicker = new MyImagePickerController();
imagePicker
.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary);
rootVC.presentViewController(imagePicker, true, null);
System.out.println("MyImagePicker - Supported orientations: "
+ imagePicker.getSupportedInterfaceOrientations());
System.out.println("MyImagePicker - Should Autorotate: "
+ imagePicker.shouldAutorotate());
...
...
It throws:
Folder on...
24
Root VC - Supported orientations: UIInterfaceOrientationMask(0x1e = All(0x1e))
Root VC - Should Autorotate: false
MyImagePicker - Supported orientations: UIInterfaceOrientationMask(0x1e = All(0x1e))
MyImagePicker - Should Autorotate: false
2014-05-15 11:23:14.438 IOSLauncher[1784:70b] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
*** First throw call stack:
(
0 CoreFoundation 0x055e51e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x04d828e5 objc_exception_throw + 44
2 CoreFoundation 0x055e4fbb +[NSException raise:format:] + 139
3 UIKit 0x02e675f2 -[UIViewController __supportedInterfaceOrientations] + 509
4 UIKit 0x02e6761e -[UIViewController __withSupportedInterfaceOrientation:apply:] + 34
5 UIKit 0x02e67c92 -[UIViewController setInterfaceOrientation:] + 139
6 UIKit 0x02e5ca8d -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 999
7 UIKit 0x02da240c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1534
8 UIKit 0x02da2109 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 763
9 UIKit 0x02d9996f __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 158
10 UIKit 0x02d997fb -[UIView(Hierarchy) _postMovedFromSuperview:] + 260
11 UIKit 0x02da4dd4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1875
12 UIKit 0x02d97dba -[UIView(Hierarchy) addSubview:] + 56
13 UIKit 0x0307dc5b -[UINavigationTransitionView transition:fromView:toView:] + 501
14 UIKit 0x0307da5e -[UINavigationTransitionView transition:toView:] + 55
15 UIKit 0x02e7e577 -[UINavigationController _startTransition:fromViewController:toViewController:] + 3186
16 UIKit 0x02e7e8cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
17 UIKit 0x02e7f4e9 -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x02fc00d1 -[UILayoutContainerView layoutSubviews] + 213
19 UIKit 0x02da7964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
20 libobjc.A.dylib 0x04d9482b -[NSObject performSelector:withObject:] + 70
21 QuartzCore 0x03d8745a -[CALayer layoutSublayers] + 148
22 QuartzCore 0x03d7b244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
23 QuartzCore 0x03d7b0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
24 QuartzCore 0x03ce17fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
25 QuartzCore 0x03ce2b85 _ZN2CA11Transaction6commitEv + 393
26 QuartzCore 0x03ce3258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
27 CoreFoundation 0x055ad36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
28 CoreFoundation 0x055ad2bf __CFRunLoopDoObservers + 399
29 CoreFoundation 0x0558b254 __CFRunLoopRun + 1076
30 CoreFoundation 0x0558a9d3 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x0558a7eb CFRunLoopRunInMode + 123
32 GraphicsServices 0x05dd35ee GSEventRunModal + 192
33 GraphicsServices 0x05dd342b GSEventRun + 104
34 UIKit 0x02d38f9b UIApplicationMain + 1225
35 IOSLauncher 0x008f16a1 org_robovm_apple_uikit_UIApplication_main__ILorg_robovm_rt_bro_ptr_BytePtr$24BytePtrPtr$3BLjava_lang_String$3BLjava_lang_String$3B__I + 255
36 IOSLauncher 0x008efcb7 org_robovm_apple_uikit_UIApplication_main__$5BLjava_lang_String$3BLjava_lang_Class$3BLjava_lang_Class$3B__V + 291
37 IOSLauncher 0x008efd0e org_robovm_apple_uikit_UIApplication_main__$5BLjava_lang_String$3BLjava_lang_Class$3BLjava_lang_Class$3B__V_clinit + 79
38 IOSLauncher 0x003f21dd com_neurodigital_babyeduca_IOSLauncher_main__$5BLjava_lang_String$3B__V + 85
39 IOSLauncher 0x00bddbcd _call0 + 45
40 IOSLauncher 0x00bd5ac1 callVoidMethod + 93
41 IOSLauncher 0x00bd6f18 rvmCallVoidClassMethodA + 86
42 IOSLauncher 0x00bd6f51 rvmCallVoidClassMethodV + 49
43 IOSLauncher 0x00bd6f7a rvmCallVoidClassMethod + 34
44 IOSLauncher 0x00bd26eb rvmRun + 592
45 IOSLauncher 0x00bc8ab1 main + 273
46 IOSLauncher 0x00219d01 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
public class IOSLauncher extends IOSApplication.Delegate implements ImagePicker {
byte[] byteArray = null;
@Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
MyApp myApp = new MyApp(this, null, null);
config.orientationLandscape = true;
config.orientationPortrait = false;
IOSApplication myIOSApp = new IOSApplication(myApp, config);
return myIOSApp;
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
public class MyImagePickerControllerGallery extends UIImagePickerController {
@Override
public boolean shouldAutorotate() {
return false;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(){
return UIInterfaceOrientationMask.All;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(){
return UIInterfaceOrientation.Portrait;
}
}
IOSLauncher.java:
@Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.orientationLandscape = true;
config.orientationPortrait = false;
return new IOSApplication(new Demo(this, null, this), config);
}
@Override
public void openGallery() {
keyWindow = UIApplication.getSharedApplication().getKeyWindow();
imagePickerGallery = new MyImagePickerControllerGallery();
imagePickerGallery.setAllowsEditing(true);
imagePickerGallery
.setModalPresentationStyle(UIModalPresentationStyle.CurrentContext);
imagePickerGallery
.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary);
rootVC = keyWindow.getRootViewController();
rootVC.presentViewController(imagePickerGallery, true, null);
UIImagePickerControllerDelegateAdapter delegate = new UIImagePickerControllerDelegateAdapter() {
@Override
public void didFinishPickingImage(UIImagePickerController picker,
UIImage image, NSDictionary info) {
System.out.println(image.getOrientation());
NSData bytes = image.toPNGData();
byteArray = bytes.getBytes();
picker.dismissViewController(true, null);
}
};
imagePickerGallery.setDelegate(delegate);
imagePickerGallery.addStrongRef((ObjCObject) delegate);
}
2014-05-18 11:00:47.174 IOSLauncher[10001:60b] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.