Skip to content

6. Native Components

Mihail Varbanov edited this page Apr 19, 2022 · 4 revisions

NativeCommunicator

NativeCommunicator service is the main gateway for assessing functionality that is natively handled for the operating system. It uses MethodChannel to access the native implementations. The native implementations themself reside in AppDelegate for iOS and MainActivity for Android.

NativeCommunicator exposes the following APIs:

init

This API is used internally by NativeCommunicator and it is called when the service is initialized. It passes all SDK keys, tokens, etc. to the native sites that are responsible to initialize the various SDKs at application launch.

map

Launches a Map controller/activity containing embedded map view and displaying specific location.

pickLocation

Launches a Map controller/activity containing embedded map view and allowing the user to select location in that map. Used in CreateEventPanel for selecting event's location on a map.

directions

Launch a Map controller/activity containing embedded map view and presenting navigation directions from current user's location to given explore target: event, dining, laundry, etc.

dismissLaunchScreen

This API is for iOS use only where the native iOS application creates its own launch screen on application:didFinishLaunchingWithOptions: notification. The Flutter application calls this method when all services get initialized and the application is ready to display its UI.

setLaunchScreenStatus

This API notifies the native side to present a status text while the application is initializing. This API is used in debug or dev builds to provide visual indication for each service initialization.

addToWallet

This API is for iOS use only for adding pass to iOS Wallet app. This API was intended to add user's iCard to the Wallet app but did not actually get used.

enabledOrientations

Gets or sets the currently enabled interface orientations. This API is used to force landscape mode when playing a video tutorial.

barcode

Generates a barcode (incl. QR) image with given content. Used by WalletPanel to generate the library card's barcode. The library card interface is currently disabled in FlexUI service so this API is not currently used by the application.

test

This is native API placeholder for test purposes, currently not used in the application.

NativeCommunicator handles the following notifications from native sides and fires a corresponding notification in Flutter side:

map.explore.select

Fired by MapWidget native implementation when the user selects a marker of an explore item. Typically the embedding panel presents a popup with explore item details and commands.

map.explore.clear

Fired by MapWidget native implementation when the user selects a location outside a marker of an explore item. Used to clear the popup for currently selected explore item.

map.route.start

Fired by Map controller/activity with navigation directions inside when the navigation starts. Used for analytics purposes.

map.route.finish

Fired by Map controller/activity with navigation directions inside when the navigation finishes. Used for analytics purposes.

Android Native

init

Initializes different modules with keys that come from the server. Such modules are: MapsIndoors SDK or Meridian SDK.

map

Displays MapActivity that represents Google map. It can take two arguments - target and options.

  • target represents where the camera will be positioned based on latitude, longitude and zoom level.
  • options contains only two fields - hideLevels and showDebugLocation. If hideLevels is true, floor levels of MapsIndoors SDK will be hidden, otherwise - visible. If showDebugLocation is true, the label with location is displayed, false - not displayed. MapActivity also has the ability to show user location on the map based on positioning from android core location services and Meridian SDK.

pickLocation

Displays SelectLocationActivity. It represents a map where user can select location for a event in create event UI flow. The main components that SelectLocationActivity embeds are SupportMapFragment (GoogleMaps) and MapControl (MapsIndoors). It accepts JSONObject location arguments on initialization. If such location parameter exist, then it is visualized on the map as marker and the camera is centered on it. Otherwise no marker is displayed and the camera is centered at the default camera position. When the user taps on a specific position, a marker is added on that position and the user is allowed to save it as an event location. If the user choose to save it, the location is returned to flutter code and SelectLocationActivity is closed.

directions

Displays MapDirectionsActivity. It represents a map where the user could navigate between his/hers location and the chosen location in different travel modes. The main components that MapDirectionsActivity embeds are SupportMapFragment (GoogleMaps) and MapControl (MapsIndoors). MapDirectionsActivity takes explore string as argument which can be a single explore object or multiple explore objects that persist on the same location. It presents explore location on the map as custom marker and searches for route between the user location and the marker. User location is determined based on Meridian SDK for indoors handling and built-in Android location services for outdoors handling. The route between explore location and user location is processed by MapsIndoors SDK based on the selected travel mode (walk, bicycle, drive and transit). Also the floor of the current MapsIndoors building is changed based on the current navigation step. The user can:

  • navigate step by step
  • change travel mode and recalculate the route based on the newly selected mode
  • autofocus camera on the current location
  • recalculate the route based on the current location.

dismissLaunchScreen

This API is not supported in Android.

setLaunchScreenStatus

Displays launch screen status (if available) as toast.

addToWallet

This API is not supported in Android.

enabledOrientations

Enables and sets specified device screen orientations and returns previously set device orientations.

barcode

Generates barcode image as encoded base64 string based on the input parameters - height, width and format.

test

Handled with an empty processing at the moment.

iOS Platform Native Handling

init

Initializes third party SDKs and service. In a typical iOS app this would be performed on application:didFinishLaunchingWithOptions: notification. However, because some SDK keys and secrets come from Flutter's Config service, this method is invoked on application launch to initialize the third party SDKs and services: Meridian, GoogleMaps and MapsIndoors.

map

Displays MapController on specified target or the current user location, if available.

pickLocation

Used to get location from CreateEventPanel in Flutter side. Presents MapLocationPickerController. It embeds GMSMapView and MPMapControl inside. On creation it initializes GMSMapView with predefined camera position as set in kInitialCameraLocation. When the user clicks on a given position it adds a marker on that position. If the user confirms this position the controller is dismissed and it is returned to Flutter side as event location.

directions

Presents MapDirectionsController. It embeds GMSMapView and MPMapControl inside. On create it initializes GMSMapView with predefined camera position as set in kInitialCameraLocation.

It takes as an input parameter a single explore (event or dining) item’s JSON. It adds Google marker at this explore position that uses MapMarkerView as a custom marker view. It searches for a route from current user location to this explore marker (location) using MapsIndoors MPDirectionsService. MapDirectionsController exposes UI for travel mode selection (MPTravelMode). Once the route is generated it can be browsed step by step displaying navigation instructions on each step.

Current user position is always presented on the map. MapDirectionsController is a location provider (MPPositionProvider) for MPMapControl. It uses Meridian SDK for indoor location handling and built-in CoreLocation service for outdoor location handling. MapDirectionsController combines both services to always provide current user location to MPMapControl, that displays it as a blue dot. While browsing the route the user is always able to focus the camera on the current location by clicking on navAutoUpdateButton button.

dismissLaunchScreen

Removes the custom launch screen presented on app launch. This API is called from Flutter side when the initialization process on startup has finished.

setLaunchScreenStatus

Updates statusText property of LaunchScreenView, if available.

addToWallet

Presents PKAddPassesViewController with pass data supplied as parameter to this API.

enabledOrientations

Sets enabled interface orientations. Used to force application rotation in order display video tutorial content in landscape orientation, and to restore default portrait orientation when this panel gets closed.

barcode

Generates a barcode image from source data using the ZXing library. The input parameters take image width and height, as well as the barcode image format.

test

This is native API placeholder for test purposes, currently not used in the application.

MapWidget

MapWidget is a custom widget with platform specific implementation. It displays a map inside using the native GoogleMaps view.

Android Native

Implements Android part for the MapView flutter widget.

MapView

Represents google map view with integrated indoors map for specific building/s that shows custom markers. It is a FrameLayout that implements Google maps OnMapReadyCallback and embeds GoogleMap (GoogleMaps) and MapControl (MapsIndoors).

MapView provides the following public interfaces:

  • applyExplores - takes JSONArray of explores and JSONObject of options as arguments. MapView displays these explores on the map as custom markers. The marker could be single or group. The single marker represents single explore and is visualized in different color based on the explore type. The group marker represents multiple explores located on the same or close location and is visualized as orange circle with the number of the explores on it.
    • explores could be three types - events, dinings or laundry rooms.
    • options has just field at the moment - LocationThresoldDistance. It represents how close to each other could be two explores so that to be grouped in group marker.
  • enableMyLocation - takes one boolean argument. Based on it, MapView displays or hides my location button in GoogleMap.

MapViewFactory

Registers MapView in PlatformViewRegistry in terms of flutter framework.

MapViewController

Serves bridge between flutter and native code for method channel of MapView. It handles the following method calls:

  • placePOIs - calls applyExplores method of MapView;
  • enable - not implemented. It is used only for iOS part;
  • enableMyLocation - calls enableMyLocation method of MapView.

MapMarkerViewType

Enum that defines different marker types. It could be SINGLE, GROUP or UNKNOWN. Based on that, markers on the map take a different look and feel.

iOS Native

MapView plugin implements iOS part of Flutter's MapWidget custom widget. It uses FlutterPluginRegistrar model to register for this plugin type. The implementation is located in MapView class

MapView

Inherits UIView. Embeds GMSMapView and MPMapControl inside. On create it initializes GMSMapView with predefined camera position as set in kInitialCameraLocation. It handles the following methods from flutter side:

  • placePOIs: takes a JSON list of explore (event or dinings) items as input parameter. Groups explore items by their locations, places markers in GMSMapView on these result locations, and focuses the camera to cover all markers. When multiple items fall into the same location the marker is orange circle with number of items inside. A single item is represented by standard GoogleMaps marker.

  • enable: Enables/Disables MapView content by adding/removing GMSMapView from UIView hierarchy. This was needed due to scroll performance issues in iOS when Flutter ListView with ExploreCards inside overlapped MapView plugin content.

  • enableMyLocation: Enables myLocation button in GMSMapView. This is not enabled by default because the plugin does not have the knowledge whether my location should be enabled since it depends on privacy level and location services status.

When a marker is clicked MapView sends a MetodChannel notification to Flutter side named map_select_explore passing item(s) JSON representation. When the user clicks anywhere on the map MapView sends map_clear_explore notification to Flutter side, that is used to hide the popup presented on map_select_explore notification.

MapMarkerView

MapMarkerView inherits UIView and serves as a custom marker view in GMSMapView. It supports three display modes:

  • plain: only the marker's icon (UIImageView) is displayed.
  • title: A title label (UILabel) is displayed in addition under the icon.
  • extended: A description label (UILabel) is displayed in addition under the title. When the user increases zoom level in GMSMapView, MapView increases display mode towards more verbose (plain -> title -> extended).

Utilities

Android Native

Android Native Utilities are defined in a single java file Utils.java.

showDialog

Displays an AlertDialog with up to two buttons/options.

DateTime

Provides functionality for parsing Date from string and formatting Date to string.

Explore

Provides helper utility methods for retrieving explore properties from a HashMap and for manipulating marker options and appearance.

Location

Provides functionality for calculating the distance between two locations (LatLng).

Map

Provides functionality for retrieving values from a Map object based on the key path.

Str

Helpers for converting bytes to string, string to bytes, checking if a given string is empty and returning null if a given string is empty.

Guid

Helpers for converting UUID to bytes and bytes to UUID.

Base64

Helpers for encoding bytes to base64 string and decoding base64 string to bytes.

AppSharedPrefs

Provides helpers for retrieving and saving boolean values from / to application’s Shared Preferences.

AppSecureSharedPrefs

Provides helpers for retrieving and saving string values from / to application’s Encrypted Shared Preferences.

iOS Native

Most of the iOS native utilities are implemented as class categories.

NSDictionary (UIUCExplore)

Helpers for accessing explore (event or dining) properties. Used by MapMarkerView, MapView or MapDirectionsController.

NSDictionary (UIUCConfig)

Helpers for accessing config data applied on init API. It supports different values for the same key depending on current platform - Android/iOS.

NSDate (UIUCUtils)

Helper for formating event time.

CommonCrypto (UIUCUtils)

Provides a helper for AES encryption.

Security (UIUCUtils)

Provides helpers to access the secure device storage.

CBPeripheral (InaUtils)

Helpers on CBPeripheral level. Currently it implements serviceWithUuid which retrieves a service for the specified Uuid and clear which clears all resources for the desired periphere

CBService (InaUtils)

Helpers on CBService level. Currently it implements characteristicWithUuid which finds and returns characteristic by Uuid

CBCharacteristic (InaUtils)

Helpers on CBCharacteristic level. Currently it implements descriptorWithUUid which finds and returns descriptor by Uuid

CGGeometry (InaUtils)

Contains CGSize scaling utilities.

CLLocationCoordinate2D (InaUtils)

Calculates distance between two location coordinates (CLLocationCoordinate2D).

NSDate (InaUtils)

NSDate parsing/formatting utilities.

NSData (InaHex)

NSData helper - inaHexString converts NSData to a hexadecimal string.

NSString (InaHex)

NSData helper - inaDataFromHex converts hexadecimal string to NSData.

NSDictionary (InaTypedValue)

Type check/conversion helpers for retrieving JSON values from NSDictionary.

NSDictionary (InaPathKey)

Helpers for accessing nested NSDictionary objects identified by URI-like paths.

NSArray (InaTypedValue)

Type check/conversion helpers for retrieving JSON values from NSArray.

NSString (InaJson)

Type check helpers for JSON decoding from NSString.

NSObject (InaJson)

Helpers for JSON encoding to NSString.

NSUserDefaults (InaUtils)

Type check/conversion helpers for retrieving values from NSUserDefaults.

UIColor (InaParse)

UIColor parsing utility from hexadecimal color representation.

NSDictionary (InaTypedColor)

Helpers for retrieving color JSON entries from NSDictionary.

UILabel (InaMeasure)

Helpers for calculating text size in UILabel.

InaSymbols

Preprocessor helper definitions.