Пример #1
0
        protected override void OnPause()
        {
            SDLActivity.OnPause();
            // Reflection <UrhoSurface>: Urho.Application.HandlePause();
            var handleResume = typeof(Urho.Application).GetMethod("HandlePause", BindingFlags.NonPublic | BindingFlags.Static);

            handleResume.Invoke(default, default);
Пример #2
0
        public async Task <Application> Show(Type appType, ApplicationOptions options = null, bool finishActivityOnExit = false)
        {
            await Stop();

            if (SDLSurface != null)
            {
                RemoveView(SDLSurface);
            }

            SDLSurface = SDLActivity.CreateSurface(Context as Activity);
            AddView(SDLSurface, ViewGroup.LayoutParams.MatchParent);

            var    tcs            = new TaskCompletionSource <Application>();
            Action startedHandler = null;

            startedHandler = () =>
            {
                Application.Started -= startedHandler;
                tcs.TrySetResult(Application.Current);
            };

            Application.Started += startedHandler;
            UrhoSurface.SetSdlMain(() => Application.CreateInstance(appType, options), finishActivityOnExit, SDLSurface);
            return(await tcs.Task);
        }
Пример #3
0
        /// <summary>
        /// Creates a view (SurfaceView) that can be added anywhere
        /// </summary>
        public static SDLSurface CreateSurface(Activity activity, Func <Application> applicationFactory, bool finishActivtiyOnExit = false)
        {
            var surface = SDLActivity.CreateSurface(activity);

            SetSdlMain(applicationFactory, finishActivtiyOnExit, surface);
            return(surface);
        }
Пример #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            requestedOrientation = (ApplicationOptions.OrientationType)Intent.GetIntExtra(nameof(ApplicationOptions.OrientationType), 0);
            switch (requestedOrientation)
            {
            case ApplicationOptions.OrientationType.Landscape:
                RequestedOrientation = ScreenOrientation.SensorLandscape;
                break;

            case ApplicationOptions.OrientationType.Portrait:
                RequestedOrientation = ScreenOrientation.SensorPortrait;
                break;

            case ApplicationOptions.OrientationType.LandscapeAndPortrait:
                RequestedOrientation = ScreenOrientation.Unspecified;
                break;
            }

            SDLSurface  surface = SDLActivity.CreateSurface(this);
            FrameLayout layout  = new FrameLayout(this);

            layout.AddView(surface);
            SetContentView(layout);
        }
Пример #5
0
        public bool OnKey(View v, Keycode keyCode, KeyEvent e)
        {
            // This handles the hardware keyboard input
            if (e.IsPrintingKey)
            {
                if (e.Action == KeyEventActions.Down)
                {
                    ic.CommitText(Java.Lang.String.ValueOf(e.GetUnicodeChar(0)), 1);
                }
                return(true);
            }

            if (e.Action == KeyEventActions.Down)
            {
                SDLActivity.onNativeKeyDown(keyCode);
                return(true);
            }
            else if (e.Action == KeyEventActions.Up)
            {
                SDLActivity.onNativeKeyUp(keyCode);
                return(true);
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// Creates a view (SurfaceView) that can be added anywhere
        /// </summary>
        public static SDLSurface CreateSurface(Activity activity, bool finishActivtiyOnExit = false, Type appDelegateType = null)
        {
            AndroidSDLSurface.appDelegateType = appDelegateType;
            var surface = SDLActivity.CreateSurface(activity);

            SetSDLEntryCallback(finishActivtiyOnExit, surface);
            return(surface);
        }
Пример #7
0
        protected override void OnElementChanged(ElementChangedEventArgs <UrhoSurface> e)
        {
            SDLActivity.OnResume();
            var surface = new AndroidUrhoSurface(Context);

            e.NewElement.UrhoApplicationLauncher = surface.Launcher;
            SetNativeControl(surface);
            base.OnElementChanged(e);
        }
Пример #8
0
        public override bool DispatchKeyEvent(KeyEvent e)
        {
            if (!SDLActivity.DispatchKeyEvent(e))
            {
                return(false);
            }

            if (e.KeyCode == Keycode.Back)
            {
                Finish();
            }
            return(base.DispatchKeyEvent(e));
        }
Пример #9
0
        internal async Task <Urho.Application> Launcher(Type type, ApplicationOptions options)
        {
            await launcherSemaphore.WaitAsync();

            SDLActivity.OnDestroy();
            applicationTaskSource     = new TaskCompletionSource <Application>();
            Urho.Application.Started += UrhoApplicationStarted;
            var surfaceView = Urho.Droid.UrhoSurface.CreateSurface((Activity)Context, type, options);

            SDLActivity.OnResume();
            surfaceViewPlaceholder.AddView(surfaceView);
            return(await applicationTaskSource.Task);
        }
Пример #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <Urho.Forms.UrhoSurface> e)
        {
            SDLActivity.OnResume();
            var surface = new AndroidUrhoSurface(Context);

            if (e.NewElement == null)
            {
                return;
            }

            e.NewElement.RegisterRunner(surface.Launcher);
            SetNativeControl(surface);
            base.OnElementChanged(e);
        }
Пример #11
0
        public async Task <Application> Show(Type appType, ApplicationOptions options = null, bool finishActivityOnExit = false)
        {
            Stop();
            launching = true;
            if (SDLSurface != null)
            {
                RemoveView(SDLSurface);
            }

            SDLSurface = SDLActivity.CreateSurface(Context as Activity);
            AddView(SDLSurface, ViewGroup.LayoutParams.MatchParent);
            // Reflection <UrhoSurfacePlaceholder>: Urho.Application.CurrentSurface = new WeakReference(SDLSurface);
            var currentSurface = typeof(Application).GetProperty(nameof(Application.CurrentSurface), BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty);

            currentSurface.SetValue(default, new WeakReference(SDLSurface));
Пример #12
0
        public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e)
        {
            // As seen on StackOverflow: http://stackoverflow.com/questions/7634346/keyboard-hide-event
            // FIXME: Discussion at http://bugzilla.libsdl.org/show_bug.cgi?id=1639
            // FIXME: This is not a 100% effective solution to the problem of detecting if the keyboard is showing or not
            // FIXME: A more effective solution would be to change our Layout from AbsoluteLayout to Relative or Linear
            // FIXME: And determine the keyboard presence doing this: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
            // FIXME: An even more effective way would be if Android provided this out of the box, but where would the fun be in that :)
            if (e.Action == KeyEventActions.Up && keyCode == Keycode.Back)
            {
                if (SDLActivity.mTextEdit != null && SDLActivity.mTextEdit.Visibility == ViewStates.Visible)
                {
                    SDLActivity.onNativeKeyboardFocusLost();
                }
            }

            return(base.OnKeyPreIme(keyCode, e));
        }
Пример #13
0
        public override bool SendKeyEvent(KeyEvent e)
        {
            var keyCode = e.KeyCode;

            if (e.Action == KeyEventActions.Down)
            {
                if (e.IsPrintingKey)
                {
                    CommitText(Java.Lang.String.ValueOf(e.GetUnicodeChar(0)), 1);
                }
                SDLActivity.onNativeKeyDown(keyCode);
                return(true);
            }
            else if (e.Action == KeyEventActions.Up)
            {
                SDLActivity.onNativeKeyUp(keyCode);
                return(true);
            }

            return(base.SendKeyEvent(e));
        }
Пример #14
0
 public bool OnGenericMotion(View v, MotionEvent e)
 {
     return(SDLActivity.handleJoystickMotionEvent(e));
 }
Пример #15
0
 public static void OnWindowFocusChanged(bool focus)
 {
     SDLActivity.OnWindowFocusChanged(focus);
 }
Пример #16
0
 public static bool DispatchKeyEvent(KeyEvent keyEvent)
 {
     return(SDLActivity.DispatchKeyEvent(keyEvent));
 }
Пример #17
0
 public static void OnDestroy()
 {
     SDLActivity.OnDestroy();
 }
Пример #18
0
 public static void OnLowMemory()
 {
     SDLActivity.OnLowMemory();
 }
Пример #19
0
 public static void OnPause()
 {
     SDLActivity.OnPause();
 }
Пример #20
0
 public override void OnLowMemory()
 {
     base.OnLowMemory();
     SDLActivity.OnLowMemory();
 }
Пример #21
0
 /// <summary>
 /// Creates a view (SurfaceView) that can be added anywhere
 /// </summary>
 public static SDLSurface CreateSurface(Activity activity, Type applicationType, ApplicationOptions options = null)
 {
     RegisterSdlLauncher(contextPtr => Application.CreateInstance(applicationType, options).Run());
     return(SDLActivity.CreateSurface(activity));
 }
Пример #22
0
 protected override void OnResume()
 {
     base.OnResume();
     SDLActivity.OnResume();
 }
Пример #23
0
 protected override void OnPause()
 {
     base.OnPause();
     SDLActivity.OnPause();
 }
Пример #24
0
 /// <summary>
 /// Creates a view (SurfaceView) that can be added anywhere
 /// </summary>
 public static SDLSurface CreateSurface(Activity activity) => SDLActivity.CreateSurface(activity);
Пример #25
0
 protected override void OnDestroy()
 {
     base.OnDestroy();
     SDLActivity.OnDestroy();
 }
Пример #26
0
 public static void OnResume()
 {
     SDLActivity.OnResume();
     Urho.Application.HandleResume();
 }
Пример #27
0
 public static void OnResume()
 {
     SDLActivity.OnResume();
 }
Пример #28
0
 public static void OnPause()
 {
     SDLActivity.OnPause();
     Urho.Application.HandlePause();
 }
Пример #29
0
 public override void OnWindowFocusChanged(bool hasFocus)
 {
     base.OnWindowFocusChanged(hasFocus);
     SDLActivity.OnWindowFocusChanged(hasFocus);
 }