protected override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); Console.WriteLine("enter OVRVrCubeWorldSurfaceViewX onCreate"); #region xCallback // X:\jsc.svn\examples\java\android\synergy\OVRVrCubeWorldSurfaceView\OVRVrCubeWorldSurfaceView\ApplicationActivity.cs var xCallback = new xCallback { onsurfaceCreated = holder => { //Console.WriteLine("enter onsurfaceCreated " + new { appThread }); if (appThread == 0) { return; } appThread.onSurfaceCreated(holder.getSurface()); mSurfaceHolder = holder; //Console.WriteLine("exit onsurfaceCreated " + new { appThread }); }, onsurfaceChanged = (SurfaceHolder holder, int format, int width, int height) => { if (appThread == 0) { return; } appThread.onSurfaceChanged(holder.getSurface()); mSurfaceHolder = holder; }, onsurfaceDestroyed = holder => { if (appThread == 0) { return; } appThread.onSurfaceDestroyed(); mSurfaceHolder = null; } }; #endregion mView = new SurfaceView(this); this.setContentView(mView); var sw = Stopwatch.StartNew(); #region mDraw var mDraw = new DrawOnTop(this) { // yes it appears top left. //text = "GearVR HUD" // (out) VrApi.vrapi_GetVersionString() text = () => sw.ElapsedMilliseconds + "ms " + GLES3JNILib.stringFromJNI() }; //Task.Run( new Thread( delegate() { // bg thread while (true) { //Thread.Sleep(1000 / 15); Thread.Sleep(1000 / 30); mDraw.postInvalidate(); } } ).Start(); #endregion #region ondispatchTouchEvent this.ondispatchTouchEvent = @event => { if (appThread == 0) { return; } int action = @event.getAction(); float x = @event.getRawX(); float y = @event.getRawY(); //if (action == MotionEvent.ACTION_UP) { var halfx = 2560 / 2; var halfy = 1440 / 2; mDraw.x = (int)(500 + halfx - x); mDraw.y = (int)(600 + y - halfy); //mDraw.text = () => sw.ElapsedMilliseconds + "ms \n" + new { x, y, action }.ToString(); //Console.WriteLine(" ::dispatchTouchEvent( " + action + ", " + x + ", " + y + " )"); } appThread.onTouchEvent(action, x, y); // can we move hud around and record it to gif or mp4? }; #endregion #region ondispatchKeyEvent this.ondispatchKeyEvent = @event => { if (appThread == 0) { return(false); } int keyCode = @event.getKeyCode(); int action = @event.getAction(); if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_UP) { return(base.dispatchKeyEvent(@event)); } if (action == KeyEvent.ACTION_UP) { // keycode 4 mDraw.text = () => sw.ElapsedMilliseconds + "ms \n" + new { keyCode, action }.ToString(); //Log.v(TAG, "GLES3JNIActivity::dispatchKeyEvent( " + keyCode + ", " + action + " )"); } appThread.onKeyEvent(keyCode, action); return(true); }; #endregion addContentView(mDraw, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mView.getHolder().addCallback(xCallback); getWindow().addFlags(WindowManager_LayoutParams.FLAG_KEEP_SCREEN_ON); appThread = com.oculus.gles3jni.GLES3JNILib.onCreate(this); Console.WriteLine("after OVRVrCubeWorldSurfaceViewX onCreate, attach the headset!"); }