/**
   * Creates and displays the balloon overlay by recycling the current balloon or by inflating it
   * from xml.
   *
   * @return true if the balloon was recycled false otherwise
   */
  private boolean createAndDisplayBalloonOverlay() {
    boolean isRecycled;
    if (balloonView == null) {
      balloonView = createBalloonOverlayView();
      clickRegion = (View) balloonView.findViewById(R.id.balloon_inner_layout);
      clickRegion.setOnTouchListener(createBalloonTouchListener());
      isRecycled = false;
    } else {
      isRecycled = true;
    }

    balloonView.setVisibility(View.GONE);

    // List<Overlay> mapOverlays = mapView.getOverlays();
    List<Overlay> mapOverlays = Collections.synchronizedList(mapView.getOverlays());
    synchronized (mapOverlays) {
      if (mapOverlays.size() > 1) {
        hideOtherBalloons(mapOverlays);
      }
    }
    if (currentFocussedItem != null) balloonView.setData(currentFocussedItem);

    GeoPoint point = currentFocussedItem.getPoint();
    MapView.LayoutParams params =
        new MapView.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            point,
            MapView.LayoutParams.BOTTOM_CENTER);
    params.mode = MapView.LayoutParams.MODE_MAP;

    balloonView.setVisibility(View.VISIBLE);

    if (isRecycled) {
      balloonView.setLayoutParams(params);
    } else {
      mapView.addView(balloonView, params);
    }

    return isRecycled;
  }
 /** Sets the visibility of this overlay's balloon view to GONE. */
 protected void hideBalloon() {
   if (balloonView != null) {
     balloonView.setVisibility(View.GONE);
   }
 }
 /** Sets the visibility of this overlay's balloon view to GONE and unfocus the item. */
 public void hideBalloon() {
   if (balloonView != null) {
     balloonView.setVisibility(View.GONE);
   }
   currentFocusedItem = null;
 }
  /**
   * Creates and displays the balloon overlay by recycling the current balloon or by inflating it
   * from xml.
   *
   * @return true if the balloon was recycled false otherwise
   */
  private boolean createAndDisplayBalloonOverlay() {
    boolean isRecycled;
    if (balloonView == null) {
      balloonView = createBalloonOverlayView();
      clickRegion = balloonView.findViewById(R.id.balloon_inner_layout);
      clickRegion.setOnTouchListener(createBalloonTouchListener());
      closeRegion = balloonView.findViewById(R.id.balloon_close);
      if (closeRegion != null) {
        if (!showClose) {
          closeRegion.setVisibility(View.GONE);
        } else {
          closeRegion.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  hideBalloon();
                }
              });
        }
      }
      if (showDisclosure && !showClose) {
        View v = balloonView.findViewById(R.id.balloon_disclosure);
        if (v != null) {
          v.setVisibility(View.VISIBLE);
        }
      }
      isRecycled = false;
    } else {
      isRecycled = true;
    }

    balloonView.setVisibility(View.GONE);

    List<Overlay> mapOverlays = mapView.getOverlays();
    if (mapOverlays.size() > 1) {
      hideOtherBalloons(mapOverlays);
    }

    if (currentFocusedItem != null) {
      balloonView.setData(currentFocusedItem);
    }

    GeoPoint point = currentFocusedItem.getPoint();
    MapView.LayoutParams params =
        new MapView.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            point,
            MapView.LayoutParams.BOTTOM_CENTER);
    params.mode = MapView.LayoutParams.MODE_MAP;

    balloonView.setVisibility(View.VISIBLE);

    if (isRecycled) {
      balloonView.setLayoutParams(params);
    } else {
      mapView.addView(balloonView, params);
    }

    return isRecycled;
  }
 /** Makes the balloon the topmost item by calling View.bringToFront(). */
 public void bringBalloonToFront() {
   if (balloonView != null) {
     balloonView.bringToFront();
   }
 }