4 #if SILICONSTUDIO_PLATFORM_ANDROID
7 using Android.Graphics;
11 using Android.Content;
13 using OpenTK.Platform.Android;
14 using SiliconStudio.Core;
15 using SiliconStudio.Paradox.Games;
16 using SiliconStudio.Paradox.Games.Android;
17 using SiliconStudio.Paradox.UI;
19 namespace SiliconStudio.
Paradox.Starter
21 public class AndroidParadoxActivity :
Activity, View.IOnTouchListener
23 private AndroidGameView gameView;
28 protected GameContext GameContext;
35 private RelativeLayout mainLayout;
36 private RingerModeIntentReceiver ringerModeIntentReceiver;
38 protected override void OnCreate(Bundle bundle)
40 base.OnCreate(bundle);
43 if (PlatformAndroid.Context == null)
44 PlatformAndroid.Context =
this;
48 Window.SetFormat(Format.Rgba8888);
51 RequestWindowFeature(WindowFeatures.NoTitle);
57 gameView =
new AndroidParadoxGameView(
this);
60 SetupGameViewAndGameContext();
63 ringerModeIntentReceiver =
new RingerModeIntentReceiver((AudioManager)GetSystemService(AudioService));
64 RegisterReceiver(ringerModeIntentReceiver,
new IntentFilter(AudioManager.RingerModeChangedAction));
67 private void SetupGameViewAndGameContext()
70 SetContentView(
Resource.Layout.Game);
71 mainLayout = FindViewById<RelativeLayout>(Resource.Id.GameViewLayout);
72 mainLayout.AddView(gameView);
75 GameContext =
new GameContext(gameView, FindViewById<RelativeLayout>(
Resource.Id.EditTextLayout));
78 public override void SetContentView(View view)
80 gameView = view as AndroidGameView;
81 SetupGameViewAndGameContext();
84 public override void SetContentView(View view, ViewGroup.LayoutParams @params)
86 gameView = view as AndroidGameView;
87 SetupGameViewAndGameContext();
90 protected override void OnPause()
94 UnregisterReceiver(ringerModeIntentReceiver);
100 protected override void OnResume()
104 RegisterReceiver(ringerModeIntentReceiver,
new IntentFilter(AudioManager.RingerModeChangedAction));
106 if (gameView != null)
110 public bool OnTouch(View v, MotionEvent e)
112 throw new NotImplementedException();
115 private class RingerModeIntentReceiver : BroadcastReceiver
117 private readonly AudioManager audioManager;
119 private int muteCounter;
121 public RingerModeIntentReceiver(AudioManager audioManager)
123 this.audioManager = audioManager;
126 public override void OnReceive(Context context, Intent intent)
128 UpdateMusicMuteStatus();
131 private void UpdateMusicMuteStatus()
133 switch (audioManager.RingerMode)
135 case RingerMode.Normal:
136 for (
int i = 0; i < muteCounter; i++)
137 audioManager.SetStreamMute(Stream.Music,
false);
140 case RingerMode.Silent:
141 case RingerMode.Vibrate:
142 audioManager.SetStreamMute(Stream.Music,
true);
146 throw new ArgumentOutOfRangeException();