コード例 #1
0
  /**
   * 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_item_title);
      clickRegion.setOnTouchListener(
          new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
              balloonView.urlClick(v);
              return true;
            }
          });

      clickRegion = (View) balloonView.findViewById(R.id.balloon_item_phone);
      clickRegion.setOnTouchListener(
          new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
              balloonView.phoneClick(v);
              return true;
            }
          });

      clickRegion = (View) balloonView.findViewById(R.id.balloon_item_twitter);
      clickRegion.setOnTouchListener(
          new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
              balloonView.twitterClick(v);
              return true;
            }
          });

      isRecycled = false;
    } else {
      isRecycled = true;
    }

    balloonView.setVisibility(View.GONE);

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

    if (currentFocussedItem != null) balloonView.setData((BalloonOverlayItem) 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;
  }
コード例 #2
0
 /** Sets the visibility of this overlay's balloon view to GONE. */
 protected void hideBalloon() {
   if (balloonView != null) {
     balloonView.setVisibility(View.GONE);
   }
 }