forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidGameActivity.cs
More file actions
114 lines (96 loc) · 3 KB
/
Copy pathAndroidGameActivity.cs
File metadata and controls
114 lines (96 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Hardware;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Microsoft.Xna.Framework.Input.Touch;
namespace Microsoft.Xna.Framework
{
[CLSCompliant(false)]
public class AndroidGameActivity : Activity
{
public static Game Game { get; set; }
private OrientationListener o;
private ScreenReceiver screenReceiver;
private bool _AutoPauseAndResumeMediaPlayer = true;
public bool AutoPauseAndResumeMediaPlayer
{
get{return _AutoPauseAndResumeMediaPlayer;}
set{_AutoPauseAndResumeMediaPlayer = value;}
}
/// <summary>
/// OnCreate called when the activity is launched from cold or after the app
/// has been killed due to a higher priority app needing the memory
/// </summary>
/// <param name='savedInstanceState'>
/// Saved instance state.
/// </param>
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
o = new OrientationListener(this);
if (o.CanDetectOrientation())
{
o.Enable();
}
IntentFilter filter = new IntentFilter();
filter.AddAction(Intent.ActionScreenOff);
filter.AddAction(Intent.ActionScreenOn);
filter.AddAction(Intent.ActionUserPresent);
screenReceiver = new ScreenReceiver();
RegisterReceiver(screenReceiver, filter);
RequestWindowFeature(WindowFeatures.NoTitle);
}
public static event EventHandler Paused;
public override void OnConfigurationChanged (Android.Content.Res.Configuration newConfig)
{
// we need to refresh the viewport here.
base.OnConfigurationChanged (newConfig);
}
protected override void OnPause()
{
base.OnPause();
if (Paused != null)
Paused(this, EventArgs.Empty);
}
public static event EventHandler Resumed;
protected override void OnResume()
{
base.OnResume();
if (Resumed != null)
Resumed(this, EventArgs.Empty);
var deviceManager = (IGraphicsDeviceManager)Game.Services.GetService(typeof(IGraphicsDeviceManager));
if (deviceManager == null)
return;
(deviceManager as GraphicsDeviceManager).ForceSetFullScreen();
Game.Window.RequestFocus();
}
protected override void OnDestroy ()
{
UnregisterReceiver(screenReceiver);
if (Game != null)
Game.Dispose();
Game = null;
base.OnDestroy ();
}
}
[CLSCompliant(false)]
public static class ActivityExtensions
{
public static ActivityAttribute GetActivityAttribute(this AndroidGameActivity obj)
{
var attr = obj.GetType().GetCustomAttributes(typeof(ActivityAttribute), true);
if (attr != null)
{
return ((ActivityAttribute)attr[0]);
}
return null;
}
}
}