/**
   * 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;
  }
Beispiel #2
0
  @Override
  public boolean onTap(GeoPoint p, MapView mapView) {
    tappedIndex = -1;
    boolean itemTapped = super.onTap(p, mapView);
    if (!isPinch && itemTapped) {
      PopupViewHolder popupVH = (PopupViewHolder) popupView.getTag();

      SearchResult item = items.get(tappedIndex);
      mapParams.point = item.getPoint();
      mapView.setTag(R.id.tag_geopoint, item.getPoint());
      popupVH.buttonCreate.setVisibility(View.VISIBLE);
      popupVH.buttonDelete.setVisibility(View.GONE);
      popupVH.buttonSave.setVisibility(View.GONE);

      Address address = item.getAddress();
      String feature = address.getFeatureName();
      if (feature != null) popupVH.editTitle.setText(feature);
      else popupVH.editTitle.setText(null);

      String addressStr = "";
      int lines = address.getMaxAddressLineIndex() + 1;
      for (int i = 0; i < lines; i++) {
        addressStr += address.getAddressLine(i);
        if (i != lines - 1) addressStr += "\n";
      }
      popupVH.editSnippet.setText(addressStr);

      mapView.removeView(popupView);
      popupView.setLayoutParams(mapParams);
      mapView.addView(popupView);

      tappedItem = item;
    } else {
      tappedItem = null;
    }
    return false;
  }
  /**
   * 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;
  }