2014-05-08 2 views
3

먼저 게시 된 의심에 대한 귀하의 지원과 답변에 많은 감사를드립니다.RoboVM을 사용한 이미지 갤러리 및 카메라 액세스

사용자 구성 화면이있어서 이미지 갤러리와 카메라에 대한 액세스가 필요한 앱을 개발 중입니다. 은 내가 RoboVM으로 그 물건을 수행하는 방법에 대한 깊은 검색을 수행하고 발견 생각 : What is startActivityForResult analogue in RoboVM? https://groups.google.com/forum/#!topic/robovm/BX5MsTF1tws https://groups.google.com/forum/#!topic/robovm/CZR4KwTBlkg

하지만 구현이 :

ImagePicker.java :

MyImagePickerController.java :

나는 갤러리 열려고하면

package com.demo.app; 
import org.robovm.apple.foundation.NSAutoreleasePool; 
import org.robovm.apple.foundation.NSDictionary; 
import org.robovm.apple.foundation.NSString; 
import org.robovm.apple.uikit.UIApplication; 
import org.robovm.apple.uikit.UIImage; 
import org.robovm.apple.uikit.UIImagePickerController; 
import org.robovm.apple.uikit.UIImagePickerControllerDelegate; 
import org.robovm.apple.uikit.UIImagePickerControllerSourceType; 
import org.robovm.apple.uikit.UIInterfaceOrientation; 
import org.robovm.apple.uikit.UINavigationController; 
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.objc.ObjCObject; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.backends.iosrobovm.IOSApplication; 
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; 
import com.demo.app.interfaces.ImagePicker; 
import com.demo.app.screens.App; 
public class IOSLauncher extends IOSApplication.Delegate implements ImagePicker { 
    byte[] byteArray = null; 
    @Override 
    protected IOSApplication createApplication() { 
     IOSApplicationConfiguration config = new IOSApplicationConfiguration(); 
     return new IOSApplication(new App(this, null, null, null), config); 
    } 
    public static void main(String[] argv) { 
     NSAutoreleasePool pool = new NSAutoreleasePool(); 
     UIApplication.main(argv, null, IOSLauncher.class); 
     pool.close(); 
    } 
    @Override 
    public void openGallery() { 
     System.out.println("I am here: Open Gallery iOS"); 
     // Gallery 
     UIViewController controller = ((IOSApplication) Gdx.app).getUIViewController(); 
     MyImagePickerController imagePicker = new MyImagePickerController(); 
     controller.addChildViewController(imagePicker); 
     controller.getView().addSubview(imagePicker.getView()); 
     imagePicker.getView().setBounds(controller.getView().getBounds()); 
     imagePicker.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary); 
     UIImagePickerControllerDelegate delegate = new UIImagePickerControllerDelegate(){ 
      @Override 
      public void willShowViewController(
        UINavigationController navigationController, 
        UIViewController viewController, boolean animated) { 
       // TODO Auto-generated method stub 
      } 
      @Override 
      public void didShowViewController(
        UINavigationController navigationController, 
        UIViewController viewController, boolean animated) { 
       // TODO Auto-generated method stub 
      } 
      @Override 
      public long getSupportedInterfaceOrientations(
        UINavigationController navigationController) { 
       // TODO Auto-generated method stub 
       return 0; 
      } 
      @Override 
      public UIInterfaceOrientation getPreferredInterfaceOrientation(
        UINavigationController navigationController) { 
       // TODO Auto-generated method stub 
       return null; 
      } 
      @Override 
      public UIViewControllerInteractiveTransitioning getInteractionController(
        UINavigationController navigationController, 
        UIViewControllerAnimatedTransitioning animationController) { 
       // TODO Auto-generated method stub 
       return null; 
      } 
      @Override 
      public UIViewControllerAnimatedTransitioning getAnimationController(
        UINavigationController navigationController, 
        UINavigationControllerOperation operation, 
        UIViewController fromVC, UIViewController toVC) { 
       // TODO Auto-generated method stub 
       return null; 
      } 
      @Override 
      public void didFinishPickingImage(UIImagePickerController picker, 
        UIImage image, NSDictionary<NSString, ?> editingInfo) { 
       // TODO Auto-generated method stub 
      } 
      @Override 
      public void didFinishPickingMedia(UIImagePickerController picker, 
        NSDictionary<NSString, ?> info) { 
       // TODO Auto-generated method stub    
      } 
      @Override 
      public void didCancel(UIImagePickerController picker) { 
       // TODO Auto-generated method stub    
      }}; 
     imagePicker.setDelegate(delegate); 
     imagePicker.addStrongRef((ObjCObject) delegate); 
    } 
    @Override 
    public void startPreview() { 
     // Cam 
    } 
    @Override 
    public byte[] getBytes() { 
     // TODO Auto-generated method stub 
     return byteArray; 
    } 
    @Override 
    public void pictureJustSaved() { 
     byteArray = null; 

    } 
} 

그리고 :

package com.demo.app; 
import org.robovm.apple.uikit.UIImagePickerController; 
import org.robovm.apple.uikit.UIInterfaceOrientation; 
public class MyImagePickerController extends UIImagePickerController { 
    public boolean shouldAutorotate() { 
     return false; 
    } 
    public UIInterfaceOrientation getPreferredInterfaceOrientation() { 
     return UIInterfaceOrientation.Portrait; 
    } 
} 

IOSLauncher.java는

Folder on... 
I am here: Open Gallery iOS 
Exception in thread "main" java.lang.ClassCastException: com.demo.app.IOSLauncher$1 cannot be cast to org.robovm.objc.ObjCObject 
    at org.robovm.objc.ObjCObject$Marshaler.protocolToNative(ObjCObject.java) 
    at org.robovm.apple.uikit.UIImagePickerController.$m$super$setDelegate$(Native Method) 
    at org.robovm.apple.uikit.UIImagePickerController.setDelegate(UIImagePickerController.java) 
    at com.demo.app.IOSLauncher.openGallery(IOSLauncher.java) 
    at com.demo.app.screens.KidsManagerScreen$8.touchUp(KidsManagerScreen.java) 
    at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java) 
    at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java) 
    at com.badlogic.gdx.backends.iosrobovm.IOSInput.processEvents(IOSInput.java) 
    at com.badlogic.gdx.backends.iosrobovm.IOSGraphics.draw(IOSGraphics.java) 
    at com.badlogic.gdx.backends.iosrobovm.IOSGraphics$1.draw(IOSGraphics.java) 
    at org.robovm.apple.uikit.UIView.$cb$drawRect$(UIView.java) 
    at org.robovm.apple.uikit.UIApplication.main(Native Method) 
    at org.robovm.apple.uikit.UIApplication.main(UIApplication.java) 
    at com.demo.app.IOSLauncher.main(IOSLauncher.java) 

은 당신이 나를 도와 주 시겠어요? 나는 길을 잃었다! 많은 분들께 진심으로 감사드립니다!

감사합니다. Luis.

답변

2

문을 보여 주셔서 감사합니다. UINavigationControllerDelegateAdapter를 확장하는 UIImagePickerControllerDelegate에 대한 별도의 클래스를 만들어 예외를 해결할 수있었습니다. 정의한 익명의 내부 클래스는 java.lang.Object를 확장하므로이 예외가 발생합니다. 따라서 클래스 정의는 다음과 같아야합니다.

public class AppleUIImagePickerControllerDelegate extends UINavigationControllerDelegateAdapter implements UIImagePickerControllerDelegate