-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.cs
155 lines (111 loc) · 4.88 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
using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Gms.Common;
using Android.OS;
using Android.Support.V7.App;
using Android.Util;
using Android.Widget;
using Java.Util;
using Newtonsoft.Json;
using Uri = Android.Net.Uri;
namespace SimpleMapDemo
{
using AndroidUri = Uri;
// [Activity(Label = "@string/app_name", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/AppTheme")]
[Activity(Label = "@string/activity_label_mapwithmarkers")]
public class MainActivity : AppCompatActivity
{
public static readonly int RC_INSTALL_GOOGLE_PLAY_SERVICES = 1000;
public static readonly string TAG = "XamarinMapDemo";
// This is a list of the examples that will be display in the Main Activity.
bool isGooglePlayServicesInstalled;
ListView listView;
string[] items;
ListView mainList;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
items = new string[] {
"London",
"New York",
};
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.MainActivity);
mainList = (ListView)FindViewById<ListView>(Resource.Id.listView);
mainList.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, items);
mainList.ItemClick += (s, e) => {
var t = items[e.Position];
// Android.Widget.Toast.MakeText(this, (e.Position+1).ToString(), Android.Widget.ToastLength.Short).Show();
Intent intent = new Intent(this, typeof(MapWithMarkersActivity));
// intent.PutExtra("User", JsonConvert.SerializeObject(list));
intent.PutExtra("locationCode", e.Position+1);
//intent.PutExtra("cordinate",)
this.StartActivity(intent);
};
isGooglePlayServicesInstalled = TestIfGooglePlayServicesIsInstalled();
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (RC_INSTALL_GOOGLE_PLAY_SERVICES == requestCode && resultCode == Result.Ok)
{
isGooglePlayServicesInstalled = true;
}
else
{
Log.Warn(TAG, $"Don't know how to handle resultCode {resultCode} for request {requestCode}.");
}
}
protected override void OnResume()
{
base.OnResume();
// listView.ItemClick += SampleSelected;
}
void SampleSelected(object sender, AdapterView.ItemClickEventArgs e)
{
var position = e.Position;
if (position == 0)
{
var geoUri = AndroidUri.Parse("geo:42.374260,-71.120824");
var mapIntent = new Intent(Intent.ActionView, geoUri);
StartActivity(mapIntent);
return;
}
Dictionary<double, double> list = new Dictionary<double, double>
{
{ 51.507351, -0.127758}
};
Intent intent = new Intent(this, typeof(MapWithMarkersActivity));
// intent.PutExtra("User", JsonConvert.SerializeObject(list));
intent.PutExtra("locationCode", 1);
//intent.PutExtra("cordinate",)
this.StartActivity(intent);
// var sampleToStart = SampleMetaDataList[position];
//sampleToStart.Start(this);
}
protected override void OnPause()
{
//listView.ItemClick -= SampleSelected;
base.OnPause();
}
bool TestIfGooglePlayServicesIsInstalled()
{
var queryResult = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
if (queryResult == ConnectionResult.Success)
{
Log.Info(TAG, "Google Play Services is installed on this device.");
return true;
}
if (GoogleApiAvailability.Instance.IsUserResolvableError(queryResult))
{
var errorString = GoogleApiAvailability.Instance.GetErrorString(queryResult);
Log.Error(TAG, "There is a problem with Google Play Services on this device: {0} - {1}", queryResult, errorString);
var errorDialog = GoogleApiAvailability.Instance.GetErrorDialog(this, queryResult, RC_INSTALL_GOOGLE_PLAY_SERVICES);
var dialogFrag = new ErrorDialogFragment(errorDialog);
dialogFrag.Show(FragmentManager, "GooglePlayServicesDialog");
}
return false;
}
}
}