AutocompleteModalViewController.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2016 Google LLC. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompleteModalViewController.h"
  16. #import <GooglePlaces/GooglePlaces.h>
  17. @interface AutocompleteModalViewController () <GMSAutocompleteViewControllerDelegate>
  18. @end
  19. @implementation AutocompleteModalViewController {
  20. UIButton *_showAutocompleteWidgetButton;
  21. }
  22. + (NSString *)demoTitle {
  23. return NSLocalizedString(
  24. @"Demo.Title.Autocomplete.FullScreen",
  25. @"Title of the full-screen autocomplete demo for display in a list or nav header");
  26. }
  27. #pragma mark - View Lifecycle
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Configure the UI. Tell our superclass we want a button and a result view below that.
  31. _showAutocompleteWidgetButton =
  32. [self createShowAutocompleteButton:@selector(showAutocompleteWidgetButtonTapped)];
  33. }
  34. #pragma mark - Actions
  35. - (IBAction)showAutocompleteWidgetButtonTapped {
  36. // When the button is pressed modally present the autocomplete view controller.
  37. GMSAutocompleteViewController *autocompleteViewController =
  38. [[GMSAutocompleteViewController alloc] init];
  39. autocompleteViewController.delegate = self;
  40. autocompleteViewController.autocompleteFilter = self.autocompleteFilter;
  41. autocompleteViewController.placeFields = self.placeFields;
  42. [self presentViewController:autocompleteViewController animated:YES completion:nil];
  43. [_showAutocompleteWidgetButton setHidden:YES];
  44. }
  45. #pragma mark - GMSAutocompleteViewControllerDelegate
  46. - (void)viewController:(GMSAutocompleteViewController *)viewController
  47. didAutocompleteWithPlace:(GMSPlace *)place {
  48. // Dismiss the view controller and tell our superclass to populate the result view.
  49. [viewController dismissViewControllerAnimated:YES completion:nil];
  50. [self autocompleteDidSelectPlace:place];
  51. }
  52. - (void)viewController:(GMSAutocompleteViewController *)viewController
  53. didFailAutocompleteWithError:(NSError *)error {
  54. // Dismiss the view controller and notify our superclass of the failure.
  55. [viewController dismissViewControllerAnimated:YES completion:nil];
  56. [self autocompleteDidFail:error];
  57. }
  58. - (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
  59. // Dismiss the controller and show a message that it was canceled.
  60. [viewController dismissViewControllerAnimated:YES completion:nil];
  61. [self autocompleteDidCancel];
  62. }
  63. - (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
  64. [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  65. }
  66. - (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
  67. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
  68. }
  69. @end