protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            #region xCallback
            // X:\jsc.svn\examples\java\android\synergy\OVRVrCubeWorldSurfaceView\OVRVrCubeWorldSurfaceView\ApplicationActivity.cs
            var xCallback = new xCallback
            {
                onsurfaceCreated = holder =>
                {
                    if (mNativeHandle != 0)
                    {
                        GLES3JNILib.onSurfaceCreated(mNativeHandle, holder.getSurface());
                        mSurfaceHolder = holder;
                    }
                },

                onsurfaceChanged = (SurfaceHolder holder, int format, int width, int height) =>
                {
                    if (mNativeHandle != 0)
                    {
                        GLES3JNILib.onSurfaceChanged(mNativeHandle, holder.getSurface());
                        mSurfaceHolder = holder;
                    }
                },

                onsurfaceDestroyed = holder =>
                {
                    if (mNativeHandle != 0)
                    {
                        GLES3JNILib.onSurfaceDestroyed(mNativeHandle);
                        mSurfaceHolder = null;
                    }
                }
            };
            #endregion



            mView = new SurfaceView(this);
            this.setContentView(mView);



            //            E/AndroidRuntime(22718): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference
            //E/AndroidRuntime(22718):        at android.view.ViewGroup.addViewInner(ViewGroup.java:4216)
            //E/AndroidRuntime(22718):        at android.view.ViewGroup.addView(ViewGroup.java:4070)
            //E/AndroidRuntime(22718):        at android.view.ViewGroup.addView(ViewGroup.java:4046)
            //E/AndroidRuntime(22718):        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:478)
            //E/AndroidRuntime(22718):        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:459)
            //E/AndroidRuntime(22718):        at android.app.Activity.setContentView(Activity.java:2298)

            var sw = Stopwatch.StartNew();

            #region mDraw
            var mDraw = new DrawOnTop(this)
            {
                // yes it appears top left.

                //text = "GearVR HUD"
                text = () => sw.ElapsedMilliseconds + "ms !"
            };

            //Task.Run(

            new Thread(
                delegate()
            {
                // bg thread

                while (true)
                {
                    //Thread.Sleep(1000 / 15);
                    Thread.Sleep(1000 / 30);


                    mDraw.postInvalidate();
                }
            }
                ).Start();
            #endregion


            this.ondispatchTouchEvent = @event =>
            {
                if (mNativeHandle == 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 + " )");
                }
                GLES3JNILib.onTouchEvent(mNativeHandle, action, x, y);

                // can we move hud around and record it to gif or mp4?
            };

            this.ondispatchKeyEvent = @event =>
            {
                if (mNativeHandle == 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 + " )");
                }
                GLES3JNILib.onKeyEvent(mNativeHandle, keyCode, action);

                return(true);
            };

            // X:\jsc.svn\examples\java\android\synergy\OVRVrCubeWorldSurfaceView\OVRVrCubeWorldSurfaceView\ApplicationActivity.cs
            // X:\jsc.svn\examples\java\android\AndroidLacasCameraServerActivity\AndroidLacasCameraServerActivity\ApplicationActivity.cs
            addContentView(mDraw, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            mView.getHolder().addCallback(xCallback);

            // Force the screen to stay on, rather than letting it dim and shut off
            // while the user is watching a movie.

            // does this disable the face sensor?
            getWindow().addFlags(WindowManager_LayoutParams.FLAG_KEEP_SCREEN_ON);

            // Force screen brightness to stay at maximum
            //WindowManager_LayoutParams _params = getWindow().getAttributes();
            //_params.screenBrightness = 1.0f;
            //getWindow().setAttributes(_params);

            mNativeHandle = com.oculus.gles3jni.GLES3JNILib.onCreate(this);

            // can we now overlay something on top of the surface?
        }
Exemplo n.º 2
0
        protected override void onCreate(android.os.Bundle savedInstanceState)
        {
            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20160102/x360videos
            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151006
            base.onCreate(savedInstanceState);


            nativeOnCreate(this);

            //setCurrentLanguage(Locale.getDefault().getLanguage());

            // Create the SoundPool
            soundPool           = new SoundPool(3 /* voices */, AudioManager.STREAM_MUSIC, 100);
            soundPoolSoundIds   = new java.util.ArrayList <int>();
            soundPoolSoundNames = new java.util.ArrayList <string>();

            AudioManager audioMgr;

            audioMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
            var rate = audioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
            var size = audioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);

            System.Console.WriteLine("rate = " + rate);
            System.Console.WriteLine("size = " + size);

            // Check preferences
            SharedPreferences prefs = getApplicationContext().getSharedPreferences("oculusvr", MODE_PRIVATE);
            var username            = prefs.getString("username", "guest");

            System.Console.WriteLine("username = "******"action:" + intent.getAction());
            System.Console.WriteLine("type:" + intent.getType());
            System.Console.WriteLine("fromPackageName:" + fromPackageNameString);
            System.Console.WriteLine("command:" + commandString);
            System.Console.WriteLine("uri:" + uriString);

            SurfaceView sv = new SurfaceView(this);

            setContentView(sv);


            #region xCallback
            // X:\jsc.svn\examples\java\android\synergy\OVRVrCubeWorldSurfaceView\OVRVrCubeWorldSurfaceView\ApplicationActivity.cs
            var xCallback = new xCallback
            {
                onsurfaceCreated = holder =>
                {
                    if (appPtr == 0)
                    {
                        return;
                    }

                    nativeSurfaceCreated(appPtr, holder.getSurface());
                    mSurfaceHolder = holder;
                },

                onsurfaceChanged = (SurfaceHolder holder, int format, int width, int height) =>
                {
                    if (appPtr == 0)
                    {
                        return;
                    }

                    nativeSurfaceChanged(appPtr, holder.getSurface());
                    mSurfaceHolder = holder;
                },

                onsurfaceDestroyed = holder =>
                {
                    if (appPtr == 0)
                    {
                        return;
                    }

                    nativeSurfaceDestroyed(appPtr);
                    mSurfaceHolder = holder;
                }
            };
            #endregion

            sv.getHolder().addCallback(xCallback);

            // Force the screen to stay on, rather than letting it dim and shut off
            // while the user is watching a movie.
            //getWindow().addFlags( WindowManager_LayoutParams.FLAG_KEEP_SCREEN_ON );

            //// Force screen brightness to stay at maximum
            //WindowManager.LayoutParams params = getWindow().getAttributes();
            //params.screenBrightness = 1.0f;
            //getWindow().setAttributes( params );

            this.ondispatchTouchEvent += (e) =>
            {
                int   action = e.getAction();
                float x      = e.getRawX();
                float y      = e.getRawY();
                Log.d(TAG, "onTouch dev:" + e.getDeviceId() + " act:" + action + " ind:" + e.getActionIndex() + " @ " + x + "," + y);
                nativeTouch(appPtr, action, x, y);
                return(true);
            };

            this.ondispatchKeyEvent = (e) =>
            {
                bool down;
                int  keyCode  = e.getKeyCode();
                int  deviceId = e.getDeviceId();

                if (e.getAction() == KeyEvent.ACTION_DOWN)
                {
                    down = true;
                }
                else if (e.getAction() == KeyEvent.ACTION_UP)
                {
                    down = false;
                }
                else
                {
                    Log.d(TAG,
                          "source " + e.getSource() + " action "
                          + e.getAction() + " keyCode " + keyCode);

                    return(base.dispatchKeyEvent(e));
                }

                Log.d(TAG, "source " + e.getSource() + " keyCode " + keyCode + " down " + down + " repeatCount " + e.getRepeatCount());

                if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
                {
                    if (down)
                    {
                        adjustVolume(1);
                    }
                    return(true);
                }

                if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
                {
                    if (down)
                    {
                        adjustVolume(-1);
                    }
                    return(true);
                }


                // Joypads will register as keyboards, but keyboards won't
                // register as position classes
                // || event.getSource() != 16777232)
                // Volume buttons are source 257
                if (e.getSource() == 1281)
                {
                    // do we have one we can test with?

                    //keyCode |= JoyEvent.BUTTON_JOYPAD_FLAG;
                }
                return(buttonEvent(deviceId, keyCode, down, e.getRepeatCount()));
            };
        }
Exemplo n.º 3
0
        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!");
        }