5454import java .util .List ;
5555import java .util .Locale ;
5656
57+ // Provides UI elements for indoor route calculation and displays an indoor route on the map.
5758public class IndoorRoutingUIController implements LongPressListener {
5859 private static final String TAG = IndoorRoutingUIController .class .getSimpleName ();
5960 private VenueMap venueMap ;
@@ -83,9 +84,15 @@ public IndoorRoutingUIController(
8384 this .venueMap = venueEngine .getVenueMap ();
8485 this .mapView = mapView ;
8586 context = indoorRoutingLayout .getContext ();
86- mapView .getGestures ().setLongPressListener (this );
87+
88+ // Initialize IndoorRoutingEngine to be able to calculate indoor routes.
8789 engine = new IndoorRoutingEngine (venueEngine .getVenueService ());
90+ // Initialize IndoorRoutingController to be able to display indoor routes on the map.
8891 controller = new IndoorRoutingController (venueMap , mapView .getMapScene ());
92+ // Set a long press listener.
93+ mapView .getGestures ().setLongPressListener (this );
94+
95+ // Get end setup needed UI elements.
8996 this .indoorRoutingLayout = indoorRoutingLayout ;
9097 indoorRoutingButton .setOnClickListener (v -> setVisible (!visible ));
9198 indoorRoutingSettings = indoorRoutingLayout .findViewById (R .id .indoorRouteSettingsLayout );
@@ -120,22 +127,35 @@ public IndoorRoutingUIController(
120127 .setOnClickListener (this ::onAvoidFeatureChanged );
121128 }
122129
130+ // Hide UI elements for indoor routes calculation.
123131 setVisible (false );
132+ // Hide UI elements for indoor route settings.
124133 setSettingsVisible (false );
134+ // Setup IndoorRouteStyle object.
125135 setUpRouteStyle ();
126136 }
127137
138+ // Get visibility of UI elements for indoor routes calculation.
128139 public boolean isVisible () {
129140 return visible ;
130141 }
131142
143+ // Setup IndoorRouteStyle object, which will be used in indoor route rendering.
132144 private void setUpRouteStyle () {
145+ // Set start, end, walk and drive markers. The start marker will be shown at the start of
146+ // the route and the destination marker at the destination of the route. The walk marker
147+ // will be shown when the route switches from drive to walk mode and the drive marker
148+ // vice versa.
133149 Anchor2D middleBottomAnchor = new Anchor2D (0.5 , 1.0 );
134150 routeStyle .setStartMarker (initMapMarker (R .drawable .ic_route_start , middleBottomAnchor ));
135151 routeStyle .setDestinationMarker (initMapMarker (R .drawable .ic_route_end , middleBottomAnchor ));
136152 routeStyle .setWalkMarker (initMapMarker (R .drawable .indoor_walk ));
137153 routeStyle .setDriveMarker (initMapMarker (R .drawable .indoor_drive ));
138154
155+ // Set markers for some of the indoor features. The 'up' marker indicates that the route
156+ // is going up, and the 'down' marker indicates that the route is going down. The default
157+ // marker indicates that a user should exit the current indoor feature (e.g. an elevator)
158+ // to enter the current floor.
139159 IndoorFeatures [] features = new IndoorFeatures [] {IndoorFeatures .ELEVATOR ,
140160 IndoorFeatures .ESCALATOR ,
141161 IndoorFeatures .STAIRS ,
@@ -148,6 +168,7 @@ private void setUpRouteStyle() {
148168 }
149169 }
150170
171+ // Creates a marker with a resource ID of an image and an anchor.
151172 private @ Nullable MapMarker initMapMarker (final int resourceID , final Anchor2D anchor ) {
152173 if (resourceID == 0 ) {
153174 return null ;
@@ -160,6 +181,9 @@ private void setUpRouteStyle() {
160181 return null ;
161182 }
162183
184+ // Gets a resource ID of an image based on the indoor feature and delta Z, where 0 means
185+ // a standard icon, 1 means that the icon shows that route is going up, and -1 that it is
186+ // going down.
163187 private int getIndoorFeatureResource (IndoorFeatures feature , int delta_z ) {
164188 switch (feature ) {
165189 case ELEVATOR :
@@ -214,6 +238,7 @@ private int getIndoorFeatureResource(IndoorFeatures feature, int delta_z) {
214238 return initMapMarker (resourceID , new Anchor2D ());
215239 }
216240
241+ // Set visibility of UI elements for indoor routes calculation.
217242 private void setVisible (final boolean value ) {
218243 if (visible == value ) {
219244 return ;
@@ -222,6 +247,7 @@ private void setVisible(final boolean value) {
222247 indoorRoutingLayout .setVisibility (visible ? View .VISIBLE : View .GONE );
223248 }
224249
250+ // Set visibility of UI elements for indoor routes settings.
225251 private void setSettingsVisible (final boolean value ) {
226252 if (settingsVisible == value ) {
227253 return ;
@@ -230,31 +256,39 @@ private void setSettingsVisible(final boolean value) {
230256 indoorRoutingSettings .setVisibility (settingsVisible ? View .VISIBLE : View .GONE );
231257 }
232258
259+ // Create an indoor waypoint based on the tap point on the map.
233260 private @ Nullable IndoorWaypoint getIndoorWaypoint (@ NonNull final Point2D origin ) {
234261 GeoCoordinates position = mapView .viewToGeoCoordinates (origin );
235262 if (position != null ) {
263+ // Check if there is a venue in the tap position.
236264 Venue venue = venueMap .getVenue (position );
237265 if (venue != null ) {
238266 VenueModel venueModel = venue .getVenueModel ();
239267 Venue selectedVenue = venueMap .getSelectedVenue ();
240268 if (selectedVenue != null &&
241269 venueModel .getId () == selectedVenue .getVenueModel ().getId ()) {
270+ // If the venue is the selected one, return an indoor waypoint
271+ // with indoor information.
242272 return new IndoorWaypoint (
243273 position ,
244274 String .valueOf (venueModel .getId ()),
245275 String .valueOf (venue .getSelectedLevel ().getId ()));
246276 } else {
277+ // If the venue is not the selected one, select it.
247278 venueMap .setSelectedVenue (venue );
248279 return null ;
249280 }
250281 }
251282
283+ // If the tap position is outside of any venue, return an indoor waypoint with
284+ // outdoor information.
252285 return new IndoorWaypoint (position );
253286 }
254287
255288 return null ;
256289 }
257290
291+ // Update the text view with a new indoor waypoint.
258292 private void updateWaypointTextView (final TextView textView , final IndoorWaypoint waypoint ) {
259293 StringBuilder text = new StringBuilder ();
260294 if (waypoint .getVenueId () != null && waypoint .getLevelId () != null ) {
@@ -273,43 +307,54 @@ private void updateWaypointTextView(final TextView textView, final IndoorWaypoin
273307 textView .setText (text .toString ());
274308 }
275309
276- public void onTap (@ NonNull final Point2D origin ) {
277- IndoorWaypoint waypoint = getIndoorWaypoint (origin );
278- if (visible && waypoint != null ) {
279- destinationWaypoint = waypoint ;
280- updateWaypointTextView (destinationTextView , waypoint );
281- }
282- }
283-
310+ // Handle the long press events.
284311 @ Override
285312 public void onLongPress (@ NonNull final GestureState state , @ NonNull final Point2D origin ) {
286313 if (!visible || state != GestureState .END ) {
287314 return ;
288315 }
289316 IndoorWaypoint waypoint = getIndoorWaypoint (origin );
290317 if (waypoint != null ) {
318+ // Set a start waypoint.
291319 startWaypoint = waypoint ;
292320 updateWaypointTextView (startTextView , waypoint );
293321 }
294322 }
295323
324+ // Handle the tap events.
325+ public void onTap (@ NonNull final Point2D origin ) {
326+ IndoorWaypoint waypoint = getIndoorWaypoint (origin );
327+ if (visible && waypoint != null ) {
328+ // Set a destination waypoint.
329+ destinationWaypoint = waypoint ;
330+ updateWaypointTextView (destinationTextView , waypoint );
331+ }
332+ }
333+
334+ // Calculate an indoor route based on the start and destination waypoints, and
335+ // the indoor route options.
296336 private void calculateRoute () {
297337 engine .calculateRoute (startWaypoint , destinationWaypoint , routeOptions , this ::showRoute );
298338 }
299339
340+ // Show the resulting route.
300341 private void showRoute (
301342 @ Nullable final RoutingError routingError , @ Nullable final List <Route > routeList ) {
343+ // Hide the existing route, if any.
302344 controller .hideRoute ();
303345 if (routingError == null && routeList != null ) {
304346 Route route = routeList .get (0 );
347+ // Show the resulting route with predefined indoor routing styles.
305348 controller .showRoute (route , routeStyle );
306349 } else {
350+ // Show a toast message in case of error.
307351 Toast toast = Toast .makeText (
308352 context , "Failed to calculate the indoor route!" , Toast .LENGTH_LONG );
309353 toast .show ();
310354 }
311355 }
312356
357+ // Change optimization mode for the indoor route calculation.
313358 private void onRouteModeChanged () {
314359 if (fastRadioButton .isChecked ()) {
315360 routeOptions .routeOptions .optimizationMode = OptimizationMode .FASTEST ;
@@ -318,6 +363,7 @@ private void onRouteModeChanged() {
318363 }
319364 }
320365
366+ // Change transport mode for the indoor route calculation.
321367 private void onTransportModeChanged () {
322368 if (pedestrianRadioButton .isChecked ()) {
323369 routeOptions .transportMode = IndoorTransportMode .PEDESTRIAN ;
@@ -326,6 +372,7 @@ private void onTransportModeChanged() {
326372 }
327373 }
328374
375+ // Change walking speed for the indoor route calculation.
329376 private boolean onWalkSpeedEditorAction (TextView textView , int actionId , KeyEvent event ) {
330377 if (actionId == EditorInfo .IME_ACTION_SEARCH || actionId == EditorInfo .IME_ACTION_DONE ||
331378 event != null && event .getAction () == KeyEvent .ACTION_DOWN &&
@@ -353,6 +400,7 @@ private boolean onWalkSpeedEditorAction(TextView textView, int actionId, KeyEven
353400 return false ;
354401 }
355402
403+ // Adds or removes avoidance features for indoor route calculation.
356404 private void onAvoidFeatureChanged (View view ) {
357405 CheckBox checkBox = (CheckBox ) view ;
358406 if (checkBox == null ) {
@@ -371,6 +419,7 @@ private void onAvoidFeatureChanged(View view) {
371419 }
372420 }
373421
422+ // Get an indoor feature based on the name.
374423 private IndoorFeatures getIndoorFeature (String checkboxName ) throws IllegalStateException {
375424 switch (checkboxName ) {
376425 case "Elevator" :
0 commit comments