2013-02-16 8 views
1

我試圖用C#編寫一個android動態壁紙使用xamarin
這樣做,我轉換在GLWallPaperService代碼在這裏發現到C#:
http://www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/

(直接跳轉到這裏Java實現:https://github.com/learnopengles/Learn-OpenGLES-Tutorials/tree/master/android/AndroidOpenGLESLessons/src/com/learnopengles/android/livewallpaper

編譯後,我得到的錯誤:gles2動態壁紙轉換爲C#(xamarin)符合錯誤「... mono.android.TypeManager不能應用於

Activate(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object[]) in mono.android.TypeManager cannot be applied to (java.lang.String,java.lang.String,com.[redacted].OpenGLES2WallpaperService.OpenGLES2WallpaperService_OpenGLES2Engine,java.lang.Object[]) mono.android.TypeManager.Activate ("com.[redacted].OpenGLES2WallpaperService/OpenGLES2Engine, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "com.[redacted].WallpaperServiceUtil.OpenGLES2WallpaperService, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", this, new java.lang.Object[] { OpenGLES2WallpaperService.this }); D:\[redacted]\obj\Debug\android\src\com\[redacted] \wallpaperserviceutil\OpenGLES2WallpaperService.java


這是我的C#實現......遺憾的長度:

public abstract class GLWallpaperService : WallpaperService 
{ 
    public class GLEngine : Engine 
    { 
     private readonly GLWallpaperService outerInstance; 

     public GLEngine(GLWallpaperService outerInstance) : base(outerInstance) 
     { 
      this.outerInstance = outerInstance; 
     } 

     internal class WallpaperGLSurfaceView : GLSurfaceView 
     { 
      private readonly GLWallpaperService.GLEngine outerInstance; 
      ISurfaceHolder _surfaceHolder; 

      internal WallpaperGLSurfaceView(GLWallpaperService.GLEngine outerInstance, Context context, ISurfaceHolder surfaceHolder) 
       : base(context) 
      { 
       this.outerInstance = outerInstance; 
       _surfaceHolder = surfaceHolder; 
      } 

      public override ISurfaceHolder Holder 
      { 
       get 
       { 
        return _surfaceHolder; 
       } 
      } 

      public virtual void OnDestroy() 
      { 
       base.OnDetachedFromWindow(); 
      } 
     } 

     private WallpaperGLSurfaceView glSurfaceView; 
     private bool rendererHasBeenSet; 

     public override void OnCreate(ISurfaceHolder surfaceHolder) 
     { 
      base.OnCreate(surfaceHolder); 

      glSurfaceView = new WallpaperGLSurfaceView(this, outerInstance, surfaceHolder); 
     } 

     public override void OnVisibilityChanged(bool visible) 
     { 
      base.OnVisibilityChanged(visible); 

      if (rendererHasBeenSet) 
      { 
       if (visible) 
       { 
        glSurfaceView.OnResume(); 
       } 
       else 
       { 
        if (!IsPreview) 
        { 
         glSurfaceView.OnPause(); 
        } 
       } 
      } 
     } 

     public override void OnDestroy() 
     { 
      base.OnDestroy(); 
      glSurfaceView.OnDestroy(); 
     } 

     protected internal virtual Android.Opengl.GLSurfaceView.IRenderer NewRenderer//was just Renderer 
     { 
      set 
      { 
       glSurfaceView.SetRenderer(value); 
       rendererHasBeenSet = true; 
      } 
     } 

     protected internal virtual int EGLContextClientVersion 
     { 
      set 
      { 
       glSurfaceView.SetEGLContextClientVersion(value); 
      } 
     } 
    } 
} 

public abstract class OpenGLES2WallpaperService : GLWallpaperService 
{ 
    public override Engine OnCreateEngine() 
    { 
     return new OpenGLES2Engine(this); 
    } 

    internal class OpenGLES2Engine : GLWallpaperService.GLEngine 
    { 
     private readonly OpenGLES2WallpaperService outerInstance; 

     public OpenGLES2Engine(OpenGLES2WallpaperService outerInstance) 
      : base(outerInstance) 
     { 
      this.outerInstance = outerInstance; 
     } 

     public override void OnCreate(ISurfaceHolder surfaceHolder) 
     { 
      base.OnCreate(surfaceHolder); 

      // Check if the system supports OpenGL ES 2.0. 
      //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': 
      //ORIGINAL LINE: final android.app.ActivityManager activityManager = (android.app.ActivityManager) getSystemService(android.content.Context.ACTIVITY_SERVICE); 
      ActivityManager activityManager = (ActivityManager)outerInstance.GetSystemService(Context.ActivityService); 
      //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': 
      //ORIGINAL LINE: final android.content.pm.ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); 
      ConfigurationInfo configurationInfo = activityManager.DeviceConfigurationInfo; 
      //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': 
      //ORIGINAL LINE: final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; 
      bool supportsEs2 = configurationInfo.ReqGlEsVersion >= 0x20000; 

      if (supportsEs2) 
      { 
       // Request an OpenGL ES 2.0 compatible context. 
       EGLContextClientVersion = 2; 

       // Set the renderer to our user-defined renderer. 
       NewRenderer = outerInstance.NewRenderer;//was just Renderer 
      } 
      else 
      { 
       // This is where you could create an OpenGL ES 1.x compatible 
       // renderer if you wanted to support both ES 1 and ES 2. 
       return; 
      } 
     } 
    } 

    internal abstract Android.Opengl.GLSurfaceView.IRenderer NewRenderer { get; } 
} 

public class LessonThreeWallpaperService : OpenGLES2WallpaperService 
{ 
    internal override Android.Opengl.GLSurfaceView.IRenderer NewRenderer 
    { 
     get 
     { 
      return new LessonThreeRenderer(); // is a GLSurfaceView.IRenderer 
     } 
    } 
} 


我指定版本的SDK版本8,並使用Visual Studio 2012
任何幫助表示讚賞。

回答

1

這是我們的Android Callable Wrapper生成器代碼中的一個錯誤:我們不能正確支持C#中的「中間」非靜態內部類。具體而言,GLWallpaperService.Engine正確生成,但OpenGLES2WallpaperService.OpenGLES2Engine不正確。請致電bugzilla.xamarin.com

+0

謝謝喬恩,生病了。 – Jon 2013-02-18 23:39:42