-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainActivity.cs
229 lines (180 loc) · 7.43 KB
/
MainActivity.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
///
/// WF.Player.Android - A Wherigo Player for Android, which use the Wherigo Foundation Core.
/// Copyright (C) 2012-2014 Dirk Weltz <web@weltz-online.de>
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Lesser General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License, or (at your option) any later version.
///
/// This program 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 Lesser General Public License for more details.
///
/// You should have received a copy of the GNU Lesser General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Android;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Hardware;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Locations;
using Vernacular;
using WF.Player.Core;
using WF.Player.Core.Live;
using WF.Player.Location;
using WF.Player.Preferences;
namespace WF.Player
{
[Activity (Label = "WF.Player", Theme="@android:style/Theme.NoTitleBar")]
public class MainActivity : Activity
{
const string HOCKEYAPP_APPID = "acc974c814cad87cf7e01b8e8c4d5ece";
protected override void OnCreate (Bundle bundle)
{
Main.SetTheme(this);
base.OnCreate (bundle);
//Register to with the Update Manager
HockeyApp.UpdateManager.Register (this, HOCKEYAPP_APPID);
if (String.IsNullOrEmpty (Main.Path)) {
Finish ();
return;
}
Catalog.Implementation = new Vernacular.AndroidCatalog (Resources, typeof (Resource.String));
// Create object for location listener
Main.GPS = new GPSListener (GetSystemService (Context.LocationService) as LocationManager, GetSystemService (Context.SensorService) as SensorManager, this.WindowManager);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
ISharedPreferences pref = GetPreferences (FileCreationMode.WorldWriteable);
Main.Prefs.GetString ("Username", GetString (Resource.String.main_unknown));
var textUsername = FindViewById<TextView> (Resource.Id.textUsername);
textUsername.Text = "charlenni";
var textFounds = FindViewById<TextView> (Resource.Id.textFounds);
textFounds.Text = String.Format (GetString (Resource.String.main_founds),0);
var textCoordText = FindViewById<TextView> (Resource.Id.textCoordText);
textCoordText.Text = GetString (Resource.String.main_last_known_location);
var textCoords = FindViewById<TextView> (Resource.Id.textCoords);
textCoords.Text = GetString (Resource.String.main_unknown_location);
var textAccuracyText = FindViewById<TextView> (Resource.Id.textAccuracyText);
textAccuracyText.Text = GetString (Resource.String.main_accuracy);
var textAccuracy = FindViewById<TextView> (Resource.Id.textAccuracy);
textAccuracy.Text = String.Format ("{0} m", Strings.Infinite);
var buttonOffline = FindViewById<Button>(Resource.Id.buttonOffline);
buttonOffline.Click += buttonOfflineClick;
var buttonNearby = FindViewById<Button>(Resource.Id.buttonNearby);
buttonNearby.Enabled = false;
buttonNearby.Click += buttonNearbyClick;
var buttonSearchParam = FindViewById<Button>(Resource.Id.buttonSearchParam);
buttonSearchParam.Enabled = false;
buttonSearchParam.Click += buttonSearchParamClick;
var buttonSearchWGCode = FindViewById<Button>(Resource.Id.buttonSearchWGCode);
buttonSearchWGCode.Enabled = false;
buttonSearchWGCode.Click += buttonSearchWGCodeClick;
var buttonSettings = FindViewById<Button>(Resource.Id.buttonSettings);
buttonSettings.Click += buttonSettingsClick;
}
protected override void OnResume()
{
base.OnResume ();
//Register for Crash detection / handling
// You should do this in your main activity
HockeyApp.CrashManager.Register (this, HOCKEYAPP_APPID);
//Start Tracking usage in this activity
HockeyApp.Tracking.StartUsage (this);
// Add to location listener
Main.GPS.AddLocationListener(OnLocationChanged);
}
protected override void OnPause()
{
// Remove to location listener
Main.GPS.RemoveLocationListener(OnLocationChanged);
//Stop Tracking usage in this activity
HockeyApp.Tracking.StopUsage (this);
base.OnPause ();
}
public void buttonOfflineClick(object sender, EventArgs args)
{
Cartridges carts = new Cartridges();
List<string> fileList = new List<string> ();
FileInfo[] files = null;
string path = Main.Path;
try {
// Read all GWC, GWZ, WFC and WFZ from default directory
files = new DirectoryInfo(global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + Java.IO.File.Separator + "WF.Player").GetFiles("*");
}
catch(Exception e) {
AlertDialog.Builder builder = new AlertDialog.Builder (this);
builder.SetTitle (GetString (Resource.String.main_error));
builder.SetMessage(e.Message);
builder.SetCancelable (true);
builder.SetNeutralButton(Resource.String.ok,(obj,arg) => { });
builder.Show ();
return;
}
foreach (FileInfo fi in files)
{
string ext = Path.GetExtension (fi.Name).ToUpper ();
if (ext.Equals (".GWC") || ext.Equals (".GWZ") || ext.Equals ("WFC") || ext.Equals ("WFZ"))
fileList.Add (fi.FullName);
}
if (fileList.Count == 0)
{
AlertDialog.Builder builder = new AlertDialog.Builder (this);
builder.SetTitle (GetString (Resource.String.main_error));
builder.SetMessage(String.Format(GetString(Resource.String.main_error_no_cartridges),path));
builder.SetCancelable (true);
builder.SetNeutralButton(Resource.String.ok,(obj,arg) => { });
builder.Show ();
}
// Create CartridgesList
carts.GetByFileList (fileList);
MainApp.Cartridges = carts;
Intent intent = new Intent (this, typeof(CartridgesActivity));
StartActivity (intent);
}
public void buttonSearchWGCodeClick(object sender, EventArgs args)
{
// TODO: Insert token for user in constructor
Cartridges carts = new Cartridges ();
carts.BeginGetByName (FindViewById<EditText> (Resource.Id.editWGCode).Text);
MainApp.Cartridges = carts;
Intent intent = new Intent (this, typeof(CartridgesActivity));
StartActivity (intent);
}
public void buttonSearchParamClick(object sender, EventArgs args)
{
Intent intent = new Intent (this, typeof(SearchActivity));
intent.PutExtra ("Cartridges", "Test");
StartActivity (intent);
}
void buttonNearbyClick (object sender, EventArgs e)
{
}
void buttonSettingsClick (object sender, EventArgs e)
{
Intent intent = new Intent (this, typeof(PreferencesActivity));
intent.PutExtra ("Cartridges", "Test");
StartActivity (intent);
}
public void OnLocationChanged(object sender, WF.Player.Location.LocationChangedEventArgs e)
{
var textCoordText = FindViewById<TextView> (Resource.Id.textCoordText);
textCoordText.Text = e.Location.HasAccuracy ? GetString (Resource.String.main_active_location) : GetString (Resource.String.main_last_known_location);
var textCoords = FindViewById<TextView> (Resource.Id.textCoords);
textCoords.Text = e.Location.ToString();
var textAccuracy = FindViewById<TextView> (Resource.Id.textAccuracy);
textAccuracy.Text = String.Format ("{0:0} m", e.Location.Accuracy);
}
}
}