FullscreenUrhoActivity.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Android.App;
  2. using Android.Content.PM;
  3. using Android.OS;
  4. using Android.Views;
  5. using Android.Widget;
  6. using Org.Libsdl.App;
  7. namespace Urho.Droid
  8. {
  9. [Activity(Label = "UrhoSharp",
  10. ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize,
  11. Theme = "@android:style/Theme.NoTitleBar",
  12. ScreenOrientation = ScreenOrientation.Unspecified)]
  13. public class FullscreenUrhoActivity : Activity
  14. {
  15. static ApplicationOptions.OrientationType requestedOrientation = 0;
  16. protected override void OnCreate(Bundle savedInstanceState)
  17. {
  18. base.OnCreate(savedInstanceState);
  19. requestedOrientation = (ApplicationOptions.OrientationType)Intent.GetIntExtra(nameof(ApplicationOptions.OrientationType), 0);
  20. switch (requestedOrientation)
  21. {
  22. case ApplicationOptions.OrientationType.Landscape:
  23. RequestedOrientation = ScreenOrientation.SensorLandscape;
  24. break;
  25. case ApplicationOptions.OrientationType.Portrait:
  26. RequestedOrientation = ScreenOrientation.SensorPortrait;
  27. break;
  28. case ApplicationOptions.OrientationType.LandscapeAndPortrait:
  29. RequestedOrientation = ScreenOrientation.Unspecified;
  30. break;
  31. }
  32. SDLSurface surface = SDLActivity.CreateSurface(this);
  33. FrameLayout layout = new FrameLayout(this);
  34. layout.AddView(surface);
  35. SetContentView(layout);
  36. }
  37. protected override void OnResume()
  38. {
  39. base.OnResume();
  40. SDLActivity.OnResume();
  41. }
  42. protected override void OnPause()
  43. {
  44. base.OnPause();
  45. SDLActivity.OnPause();
  46. }
  47. protected override void OnDestroy()
  48. {
  49. base.OnDestroy();
  50. SDLActivity.OnDestroy();
  51. }
  52. public override void OnLowMemory()
  53. {
  54. base.OnLowMemory();
  55. SDLActivity.OnLowMemory();
  56. }
  57. public override void OnWindowFocusChanged(bool hasFocus)
  58. {
  59. base.OnWindowFocusChanged(hasFocus);
  60. SDLActivity.OnWindowFocusChanged(hasFocus);
  61. }
  62. public override bool DispatchKeyEvent(KeyEvent e)
  63. {
  64. if (!SDLActivity.DispatchKeyEvent(e))
  65. return false;
  66. if (e.KeyCode == Keycode.Back)
  67. Finish();
  68. return base.DispatchKeyEvent(e);
  69. }
  70. }
  71. }