protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Places); // Create your application here var gpsTracker = new GPSTracker(this); var googlePlaces = new GooglePlacesApi.GooglePlaces(); var loading = ProgressDialog.Show(this, "Retrieving Nearby Places", "Please wait...", true); googlePlaces.Search(gpsTracker.Latitude, gpsTracker.Longitude, 500, null, placesList => RunOnUiThread(() => { var placesListView = FindViewById<ListView>(Resource.Id.Places); placesListView.Adapter = new PlacesListAdapter(this, placesList.results); loading.Hide(); })); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Places); _gpsTracker = ((AfaApplication)ApplicationContext).GetGpsTracker(this); _googlePlaces = new GooglePlacesApi.GooglePlaces(AfaConfig.GoogleApiKey); _loading = DialogManager.ShowLoadingDialog(this, "Retrieving Nearby Places"); Log.Debug("Position Lat:", _gpsTracker.Latitude.ToString()); Log.Debug("Position Lng:", _gpsTracker.Longitude.ToString()); _placesListView = FindViewById<ListView>(Resource.Id.Places); var layout = new LinearLayout(this); _loadMoreButton = new Button(this); _loadMoreButton.Text = "Load More Results"; _loadMoreButton.LayoutParameters = new TableLayout.LayoutParams(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.WrapContent, 1f); layout.AddView(_loadMoreButton); _addNewPlaceButton = new Button(this); _addNewPlaceButton.Text = "Add New"; _addNewPlaceButton.LayoutParameters = new TableLayout.LayoutParams(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.WrapContent, 1f); layout.AddView(_addNewPlaceButton); _placesListView.AddFooterView(layout); _loadMoreButton.Click += (sender, args) => FetchMoreResults(); _addNewPlaceButton.Click += (sender, args) => { var intent = new Intent(this, typeof (AddPlaceActivity)); StartActivity(intent); }; DoPlacesSearch(); var searchButton = FindViewById<ImageButton>(Resource.Id.searchButton); searchButton.Click += (sender, args) => { _loading.Show(); var inputManager = (InputMethodManager) GetSystemService(Context.InputMethodService); inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways); var placeNameInput = FindViewById<EditText>(Resource.Id.placeNameSearch); var locationNameInput = FindViewById<EditText>(Resource.Id.locationSearch); var placeNameSpecified = !String.IsNullOrWhiteSpace(placeNameInput.Text); var locationNameSpecified = !String.IsNullOrWhiteSpace(locationNameInput.Text); if (!placeNameSpecified && !locationNameSpecified) { // Nothing specified, do default search DoPlacesSearch(); } else if (locationNameSpecified) { _googlePlaces.Search(this, locationNameInput.Text, PlaceTypes, placeNameInput.Text, SearchCallback); } else { _googlePlaces.Search(_gpsTracker.Latitude, _gpsTracker.Longitude, PlaceTypes, placeNameInput.Text, SearchCallback); } }; }