/
Application.cs
194 lines (175 loc) · 8.98 KB
/
Application.cs
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.
using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using MPfm.Android.Classes.Fragments;
using MPfm.Android.Classes.Navigation;
using MPfm.Android.Classes.Providers;
using MPfm.Android.Classes.Receivers;
using MPfm.Library;
using MPfm.Library.Services.Interfaces;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Config.Providers;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;
using MPfm.Android.Classes.Services;
using org.sessionsapp.android;
namespace MPfm.Android.Classes
{
#if DEBUG
[Application(Name = "my.App", Debuggable = true, Label = "Sessions")]
#else
[Application (Name="my.App", Debuggable=false, Label="Sessions")]
#endif
public class MPfmApplication : Application
{
static Context _context;
ConnectionChangeReceiver _connectionChangeReceiver;
private LockReceiver _lockReceiver;
//private IntentFilter _intentFilter;
//private WifiP2pManager _wifiManager;
//private WifiP2pManager.Channel _wifiChannel;
//private WifiDirectReceiver _wifiDirectReceiver;
//private ActionListener _actionListener;
#if __ANDROID_16__
private AndroidDiscoveryService _discoveryService;
#endif
public MPfmApplication(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
public override void OnCreate()
{
base.OnCreate();
_context = ApplicationContext; // TODO: Probably creates a memory leak.
BootstrapApp();
// Set player plugin directory path
ApplicationInfo appInfo = PackageManager.GetApplicationInfo(PackageName, 0);
Player.Player.PluginDirectoryPath = appInfo.NativeLibraryDir;
try
{
Console.WriteLine("Application - Registering ConnectionChangeReceiver...");
_connectionChangeReceiver = new ConnectionChangeReceiver();
IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
filter.AddCategory(Intent.CategoryDefault);
RegisterReceiver(_connectionChangeReceiver, filter);
}
catch (Exception ex)
{
Console.WriteLine("Application - Error: Failed to setup connection change receiver! {0}", ex);
}
try
{
Console.WriteLine("Application - Registering LockReceiver...");
var intentFilter = new IntentFilter();
intentFilter.AddAction(Intent.ActionScreenOff);
intentFilter.AddAction(Intent.ActionScreenOn);
intentFilter.AddAction(Intent.ActionUserPresent);
intentFilter.AddCategory(Intent.CategoryDefault);
_lockReceiver = new LockReceiver();
RegisterReceiver(_lockReceiver, intentFilter);
}
catch (Exception ex)
{
Console.WriteLine("Application - Error: Failed to setup lock receiver! {0}", ex);
}
//#if __ANDROID_16__
// if (((int)global::Android.OS.Build.VERSION.SdkInt) >= 16) {
// _discoveryService = new AndroidDiscoveryService();
// _discoveryService.StartDiscovery();
// _discoveryService.DiscoverPeers();
// }
//#endif
}
public override void OnTerminate()
{
base.OnTerminate();
// Stop and clean up player
if (MPfm.Player.Player.CurrentPlayer.IsPlaying)
MPfm.Player.Player.CurrentPlayer.Stop();
MPfm.Player.Player.CurrentPlayer.Dispose();
//#if __ANDROID_16__
// if (((int)global::Android.OS.Build.VERSION.SdkInt) >= 16) {
// _discoveryService.Dispose();
// }
//#endif
}
//private void SetupWifiDirect()
//{
// _intentFilter = new IntentFilter();
// _intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
// _intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
// _intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
// _intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);
// _actionListener = new ActionListener();
// _wifiManager = (WifiP2pManager) GetSystemService(Context.WifiP2pService);
// _wifiChannel = _wifiManager.Initialize(this, MainLooper, null);
// _wifiDirectReceiver = new WifiDirectReceiver();
// RegisterReceiver(_wifiDirectReceiver, _intentFilter);
// _wifiManager.DiscoverPeers(_wifiChannel, _actionListener);
//}
public static Context GetApplicationContext()
{
return _context;
}
private void BootstrapApp()
{
// Complete IoC configuration
TinyIoC.TinyIoCContainer container = Bootstrapper.GetContainer();
container.Register<ISyncDeviceSpecifications, AndroidSyncDeviceSpecifications>().AsSingleton();
container.Register<ICloudService, AndroidDropboxService>().AsSingleton();
container.Register<IAppConfigProvider, AndroidAppConfigProvider>().AsSingleton();
container.Register<MobileNavigationManager, AndroidNavigationManager>().AsSingleton();
container.Register<IMobileOptionsMenuView, MainActivity>().AsMultiInstance();
container.Register<ISplashView, SplashActivity>().AsMultiInstance();
container.Register<IMobileMainView, MainActivity>().AsMultiInstance();
container.Register<IPlayerView, PlayerActivity>().AsMultiInstance();
container.Register<IPlayerMetadataView, PlayerMetadataFragment>().AsMultiInstance();
container.Register<IMarkersView, MarkersFragment>().AsMultiInstance();
container.Register<IMarkerDetailsView, MarkerDetailsActivity>().AsMultiInstance();
container.Register<ILoopsView, LoopsFragment>().AsMultiInstance();
container.Register<ITimeShiftingView, TimeShiftingFragment>().AsMultiInstance();
container.Register<IPitchShiftingView, PitchShiftingFragment>().AsMultiInstance();
container.Register<IUpdateLibraryView, UpdateLibraryFragment>().AsMultiInstance();
container.Register<IMobileLibraryBrowserView, MobileLibraryBrowserFragment>().AsMultiInstance();
container.Register<IPlaylistView, PlaylistActivity>().AsMultiInstance();
container.Register<ISyncView, SyncActivity>().AsMultiInstance();
container.Register<ISyncDownloadView, SyncDownloadActivity>().AsMultiInstance();
container.Register<ISyncMenuView, SyncMenuActivity>().AsMultiInstance();
container.Register<ISyncWebBrowserView, SyncWebBrowserActivity>().AsMultiInstance();
container.Register<ISyncCloudView, SyncCloudActivity>().AsMultiInstance();
container.Register<ICloudConnectView, CloudConnectFragment>().AsMultiInstance();
container.Register<IEqualizerPresetsView, EqualizerPresetsActivity>().AsMultiInstance();
container.Register<IEqualizerPresetDetailsView, EqualizerPresetDetailsActivity>().AsMultiInstance();
container.Register<IPreferencesView, PreferencesActivity>().AsMultiInstance();
container.Register<IAudioPreferencesView, AudioPreferencesFragment>().AsMultiInstance();
container.Register<IGeneralPreferencesView, GeneralPreferencesFragment>().AsMultiInstance();
container.Register<ILibraryPreferencesView, LibraryPreferencesFragment>().AsMultiInstance();
container.Register<IAboutView, AboutActivity>().AsMultiInstance();
container.Register<ISelectFoldersView, SelectFoldersFragment>().AsMultiInstance();
container.Register<ISelectPlaylistView, SelectPlaylistFragment>().AsMultiInstance();
container.Register<IAddPlaylistView, AddPlaylistFragment>().AsMultiInstance();
container.Register<IAddMarkerView, AddMarkerFragment>().AsMultiInstance();
container.Register<IResumePlaybackView, ResumePlaybackActivity>().AsMultiInstance();
container.Register<IStartResumePlaybackView, StartResumePlaybackFragment>().AsMultiInstance();
container.Register<IFirstRunView, FirstRunActivity>().AsMultiInstance();
}
}
}