/// <summary> /// Code to the executed when the activity is created /// </summary> /// <param name="bundle">Any additional data sent to the activity</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view SetContentView(Resource.Layout.message_spinner); //Create the spinner for the name of the nearby users Spinner spinner = FindViewById <Spinner> (Resource.Id.spinner); spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected); // Get the location manager locationManager = (LocationManager)Config.context.GetSystemService(Context.LocationService); // Define the criteria how to select the location provider -> use default Criteria criteria = new Criteria(); criteria.Accuracy = Accuracy.Fine; provider = locationManager.GetBestProvider(criteria, true); Location location = locationManager.GetLastKnownLocation(provider); //Create a Geolocation object which handles most of the location related functionality, including server calls Geolocation currentLocation = new Geolocation(MainActivity.username, location.Latitude, location.Longitude); //Get the list of nearby profiles Task <List <Profile> > nearbyProfiles = Task <List <Profile> > .Factory.StartNew(() => { return(currentLocation.GetNearbyUsers().Result); }); //Filter the list of profiles, removing the profile for this user, if it was returned by the server nearbyUserslist = new List <Profile> (); try { nearbyUserslist = nearbyProfiles.Result; foreach (Profile p in nearbyUserslist) { if (p.username.Equals(MainActivity.credentials.username)) { nearbyUserslist.Remove(p); break; } } } catch (Exception e) { string error = e.Message; System.Diagnostics.Debug.WriteLine("\n\nServer offline\n\n" + error); } //Create an array containing all the usernames of the nearby users string[] nearbyUsers = new string[nearbyUserslist.Count]; for (int i = 0; i < nearbyUserslist.Count; i++) { nearbyUsers [i] = nearbyUserslist [i].username; } //Set up the spinner object to user the array of nearby users var adapter = new ArrayAdapter <String> (this, Android.Resource.Layout.SimpleListItemChecked, nearbyUsers); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner.Adapter = adapter; mMessage = FindViewById <EditText> (Resource.Id.sendMessageTxt); mSendMessage = FindViewById <Button> (Resource.Id.btnSendMsg); mSendMessage.Click += MSendMessage_Click; }
/// <summary> /// Code to the executed when the activity is created /// </summary> /// <param name="bundle">Any additional data sent to the activity</param> protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view SetContentView (Resource.Layout.message_spinner); //Create the spinner for the name of the nearby users Spinner spinner = FindViewById<Spinner> (Resource.Id.spinner); spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected); // Get the location manager locationManager = (LocationManager)Config.context.GetSystemService (Context.LocationService); // Define the criteria how to select the location provider -> use default Criteria criteria = new Criteria (); criteria.Accuracy = Accuracy.Fine; provider = locationManager.GetBestProvider (criteria, true); Location location = locationManager.GetLastKnownLocation (provider); //Create a Geolocation object which handles most of the location related functionality, including server calls Geolocation currentLocation = new Geolocation (MainActivity.username, location.Latitude, location.Longitude); //Get the list of nearby profiles Task<List<Profile>> nearbyProfiles = Task<List<Profile>>.Factory.StartNew (() => { return currentLocation.GetNearbyUsers ().Result; }); //Filter the list of profiles, removing the profile for this user, if it was returned by the server nearbyUserslist = new List<Profile> (); try { nearbyUserslist = nearbyProfiles.Result; foreach (Profile p in nearbyUserslist) { if (p.username.Equals (MainActivity.credentials.username)) { nearbyUserslist.Remove (p); break; } } } catch (Exception e) { string error = e.Message; System.Diagnostics.Debug.WriteLine ("\n\nServer offline\n\n" + error); } //Create an array containing all the usernames of the nearby users string[] nearbyUsers = new string[nearbyUserslist.Count]; for (int i = 0; i < nearbyUserslist.Count; i++) { nearbyUsers [i] = nearbyUserslist [i].username; } //Set up the spinner object to user the array of nearby users var adapter = new ArrayAdapter<String> (this, Android.Resource.Layout.SimpleListItemChecked, nearbyUsers); adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner.Adapter = adapter; mMessage = FindViewById<EditText> (Resource.Id.sendMessageTxt); mSendMessage = FindViewById<Button> (Resource.Id.btnSendMsg); mSendMessage.Click += MSendMessage_Click; }
/// <summary> /// Gets the location manager and creates a new Geolocation object with /// the user's current location and receives a list from our server /// containing all of the nearby users based on that geolocation. /// The list is parsed and the profile bios are formatted and placed /// into a string array with the same corresponding index of the string /// array of nearby usernames. /// </summary> /// <param name="savedInstanceState">Bundle.</param> public override void OnActivityCreated(Bundle savedInstanceState) { base.OnActivityCreated(savedInstanceState); var ProfileFrame = Activity.FindViewById<View>(Resource.Id.UserProfile); // If running on a tablet, then the layout in Resources/Layout-Large will be loaded. // That layout uses fragments, and defines the detailsFrame. We use the visiblity of // detailsFrame as this distinguisher between tablet and phone. isDualPane = ProfileFrame != null && ProfileFrame.Visibility == ViewStates.Visible; // Get the location manager locationManager = (LocationManager) Config.context.GetSystemService(Context.LocationService); // Define the criteria how to select the location provider -> use default Criteria criteria = new Criteria(); criteria.Accuracy = Accuracy.Fine; provider = locationManager.GetBestProvider(criteria, true); Location location = locationManager.GetLastKnownLocation(provider); //Create a Geolocation object which handles most of the location related functionality, including server calls Geolocation currentLocation = new Geolocation (MainActivity.username, location.Latitude, location.Longitude); //Get the list of nearby profiles Task<List<Profile>> nearbyProfiles = Task<List<Profile>>.Factory.StartNew(() => { return currentLocation.GetNearbyUsers().Result; }); //Filter the list of profiles, removing the profile for this user, if it was returned by the server nearbyUserslist = new List<Profile>(); try{ nearbyUserslist = nearbyProfiles.Result; foreach (Profile p in nearbyUserslist){ if(p.username.Equals(MainActivity.credentials.username)){ nearbyUserslist.Remove(p); break; } } } catch(Exception e) { string error = e.Message; System.Diagnostics.Debug.WriteLine ("\n\nServer offline\n\n" + error); } //Create the arrays containing the information about the users int numUsers = nearbyUserslist.Count; string[] nearbyUsers = new string[numUsers]; nearbyBios = new string[numUsers]; //Process the information about the nearby users in a formatted string, for display for (int i = 0; i < numUsers; i++) { nearbyUsers [i] = nearbyUserslist [i].username; nearbyBios [i] = "⇧ " + nearbyUserslist[i].positive_votes + "\n⇩ " + nearbyUserslist[i].negative_votes + "\n\n" + nearbyUserslist [i].gender + "\n\n" + nearbyUserslist [i].bio; } //Set up the adapted to display the list of users var adapter = new ArrayAdapter<String>(Activity, Android.Resource.Layout.SimpleListItemChecked, nearbyUsers); ListAdapter = adapter; if (savedInstanceState != null) { selectedUserId = savedInstanceState.GetInt("selected_user_id", 0); } if (isDualPane) { ListView.ChoiceMode = ChoiceMode.Single; ShowProfile(selectedUserId); } }
/// <summary> /// Gets the location manager and creates a new Geolocation object with /// the user's current location and receives a list from our server /// containing all of the nearby users based on that geolocation. /// The list is parsed and the profile bios are formatted and placed /// into a string array with the same corresponding index of the string /// array of nearby usernames. /// </summary> /// <param name="savedInstanceState">Bundle.</param> public override void OnActivityCreated(Bundle savedInstanceState) { base.OnActivityCreated(savedInstanceState); var ProfileFrame = Activity.FindViewById <View>(Resource.Id.UserProfile); // If running on a tablet, then the layout in Resources/Layout-Large will be loaded. // That layout uses fragments, and defines the detailsFrame. We use the visiblity of // detailsFrame as this distinguisher between tablet and phone. isDualPane = ProfileFrame != null && ProfileFrame.Visibility == ViewStates.Visible; // Get the location manager locationManager = (LocationManager)Config.context.GetSystemService(Context.LocationService); // Define the criteria how to select the location provider -> use default Criteria criteria = new Criteria(); criteria.Accuracy = Accuracy.Fine; provider = locationManager.GetBestProvider(criteria, true); Location location = locationManager.GetLastKnownLocation(provider); //Create a Geolocation object which handles most of the location related functionality, including server calls Geolocation currentLocation = new Geolocation(MainActivity.username, location.Latitude, location.Longitude); //Get the list of nearby profiles Task <List <Profile> > nearbyProfiles = Task <List <Profile> > .Factory.StartNew(() => { return(currentLocation.GetNearbyUsers().Result); }); //Filter the list of profiles, removing the profile for this user, if it was returned by the server nearbyUserslist = new List <Profile>(); try{ nearbyUserslist = nearbyProfiles.Result; foreach (Profile p in nearbyUserslist) { if (p.username.Equals(MainActivity.credentials.username)) { nearbyUserslist.Remove(p); break; } } } catch (Exception e) { string error = e.Message; System.Diagnostics.Debug.WriteLine("\n\nServer offline\n\n" + error); } //Create the arrays containing the information about the users int numUsers = nearbyUserslist.Count; string[] nearbyUsers = new string[numUsers]; nearbyBios = new string[numUsers]; //Process the information about the nearby users in a formatted string, for display for (int i = 0; i < numUsers; i++) { nearbyUsers [i] = nearbyUserslist [i].username; nearbyBios [i] = "⇧ " + nearbyUserslist[i].positive_votes + "\n⇩ " + nearbyUserslist[i].negative_votes + "\n\n" + nearbyUserslist [i].gender + "\n\n" + nearbyUserslist [i].bio; } //Set up the adapted to display the list of users var adapter = new ArrayAdapter <String>(Activity, Android.Resource.Layout.SimpleListItemChecked, nearbyUsers); ListAdapter = adapter; if (savedInstanceState != null) { selectedUserId = savedInstanceState.GetInt("selected_user_id", 0); } if (isDualPane) { ListView.ChoiceMode = ChoiceMode.Single; ShowProfile(selectedUserId); } }