private void doFocusChange(ObaStop stop) { mMarkerData.setFocus(stop); HashMap<String, ObaRoute> routes = mMarkerData.getCachedRoutes(); // Notify listener mOnFocusChangedListener.onFocusChanged(stop, routes, stop.getLocation()); }
/** * Removes the stop focus and notify listener * * @param latLng the location on the map where the user tapped if the focus change was triggered * by the user tapping on the map, or null if the focus change was otherwise triggered * programmatically. */ private void removeFocus(LatLng latLng) { if (mMarkerData.getFocus() != null) { mMarkerData.removeFocus(); } // Set map clicked location, if it exists Location location = null; if (latLng != null) { location = MapHelpV2.makeLocation(latLng); } // Notify focus changed every time the map is clicked away from a stop marker mOnFocusChangedListener.onFocusChanged(null, null, location); }
public synchronized int size() { if (mMarkerData != null) { return mMarkerData.size(); } else { return 0; } }
/** * Returns the currently focused stop, or null if no stop is in focus * * @return the currently focused stop, or null if no stop is in focus */ public ObaStop getFocus() { if (mMarkerData != null) { return mMarkerData.getFocus(); } return null; }
/** * Updates vehicles for the provided routeIds from the status info from the given * ObaTripsForRouteResponse * * @param routeIds routeIds for which to add vehicle markers to the map. If a vehicle is running a * route that is not contained in this list, the vehicle won't be shown on the map. * @param response response that contains the real-time status info */ public void updateVehicles(HashSet<String> routeIds, ObaTripsForRouteResponse response) { // Make sure that the MarkerData has been initialized setupMarkerData(); // Cache the response, so when a marker is tapped we can look up route names from routeIds, etc. mLastResponse = response; // Show the markers on the map mMarkerData.populate(routeIds, response); }
/** Clears any vehicle markers from the map */ public synchronized void clear() { if (mMarkerData != null) { mMarkerData.clear(); mMarkerData = null; } if (mCustomInfoWindowAdapter != null) { mCustomInfoWindowAdapter.clear(); } }
@Override public boolean onMarkerClick(Marker marker) { long startTime = Long.MAX_VALUE, endTime = Long.MAX_VALUE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { startTime = SystemClock.elapsedRealtimeNanos(); } ObaStop stop = mMarkerData.getStopFromMarker(marker); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { endTime = SystemClock.elapsedRealtimeNanos(); Log.d( TAG, "Stop HashMap read time: " + TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS) + "ms"); } if (stop == null) { // The marker isn't a stop that is contained in this StopOverlay - return unhandled return false; } if (BuildConfig.DEBUG) { // Show the stop_id in a toast for debug purposes Toast.makeText(mActivity, stop.getId(), Toast.LENGTH_SHORT).show(); } doFocusChange(stop); // Report Stop distance metric Location stopLocation = stop.getLocation(); Location myLocation = Application.getLastKnownLocation(mActivity, null); // Track the users distance to bus stop ObaAnalytics.trackBusStopDistance(stop.getId(), myLocation, stopLocation); return true; }
/** * Sets focus to a particular stop, or pass in null for the stop to clear the focus * * @param stop ObaStop to focus on, or null to clear the focus * @param routes a list of all route display names that serve this stop */ public void setFocus(ObaStop stop, List<ObaRoute> routes) { // Make sure that the MarkerData has been initialized setupMarkerData(); if (stop == null) { // Clear the focus removeFocus(null); return; } /** * If mMarkerData exists before this method is called, the stop reference passed into this * method might not match any existing stop reference in our HashMaps, since this stop came from * an external REST API call - is this a problem??? * * <p>If so, we'll need to keep another HashMap mapping stopIds to ObaStops so we can pull out * an internal reference to an ObaStop object that has the same stopId as the ObaStop object * passed into this method. Then, we would use that internal reference in place of the ObaStop * passed into this method. We don't want to maintain Yet Another HashMap for memory/performance * reasons if we don't have to. For now, I think we can get away with a separate reference that * doesn't match the internal HashMaps, since we don't need to match the references. */ /** * Make sure that this stop is added to the overlay. If an intent/orientation change started the * map fragment to focus on a stop, no markers may exist on the map */ if (!mMarkerData.containsStop(stop)) { ArrayList<ObaStop> l = new ArrayList<ObaStop>(); l.add(stop); populateStops(l, routes); } // Add the focus marker to the map by setting focus to this stop doFocusChange(stop); }
@Override public void onInfoWindowClick(Marker marker) { ObaTripStatus status = mMarkerData.getStatusFromMarker(marker); // Show trip details screen for this vehicle TripDetailsActivity.start(mActivity, status.getActiveTripId()); }
/** * Clears any stop markers from the map * * @param clearFocusedStop true to clear the currently focused stop, false to leave it on map */ public synchronized void clear(boolean clearFocusedStop) { if (mMarkerData != null) { mMarkerData.clear(clearFocusedStop); } }
private void populate(List<ObaStop> stops, List<ObaRoute> routes) { // Make sure that the MarkerData has been initialized setupMarkerData(); mMarkerData.populate(stops, routes); }