Search code examples
androidinfowindowcontextual-action-bar

Coordinate contextual actionbar with Maps API v2 info window display


I would like to sync the display of a contextual actionbar menu with info windows from the Google Maps API v2. The main issue I am having is that there appears to be no way to reliably monitor the state of an info window and the two UI pieces easily get out of sync.

This is roughly what I have so far:

private ActionMode mActionMode;
private ActionMode.Callback mActionModeCallback 
  = new ActionMode.Callback() { ... };

public boolean onMarkerClick(Marker marker) {
    if (mActionMode != null) {
        // This case should occur if the user taps an already selected marker.
        mActionMode.finish();
        return false;
    }

    // Start the contextual actionbar using the ActionMode.Callback defined above
    mActionMode = this.startActionMode(mActionModeCallback);
    return false;
}

public void onMapClick(LatLng point) {
    // Clicking the map normally only closes any info windows.
    // We must close the contextual action bar menu as well.
    if (mActionMode != null)
        mActionMode.finish();
}

The main issue seems to be that onMarkerClick and onMapClick are not called when a marker itself is clicked while the info window is shown; this interaction is still enough to close the info window though...

If anyone has a more reliable way of keeping track of an info window's state or a way to monitor those missing click events, I would be glad to hear!


Solution

  • The gmaps api v2 is still missing a lot of components that were present in the flash and javascript api's, so after a quick skim im not sure they have the appropriate listeners that you're looking for.

    best bet would be to add a feature enhancement or bug report here:

    http://code.google.com/p/gmaps-api-issues/issues/list?can=2&q=apitype%3AAndroid2