/**
   * 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;
  }
示例#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;
  }
示例#3
0
  public void init() {

    LogManager.d("init");

    geoBeijing = new GeoPoint((int) (39.932 * 1000000), (int) (116.461 * 1000000));
    mDefaultCurrentLocation =
        new GeoPoint((int) (41.892910 * 1000000), (int) (12.48251990 * 1000000));

    mapView = (MapView) findViewById(R.id.map_view);
    map_view_enable = findViewById(R.id.map_view_enable);
    mapView.getLayoutParams().height = BaseActivity.screen_height * 1 / 2;
    map_view_enable.getLayoutParams().height = BaseActivity.screen_height * 1 / 2;
    mapView.setOnTouchListener(this);
    mapView.setSaveEnabled(true);
    mapView.setBuiltInZoomControls(false);

    mapCon = mapView.getController();
    mapCon.setZoom(defaultZoom);

    // geo = new Geocoder(getContext(), Locale.CHINA);
    mapCon.setCenter(mDefaultCurrentLocation);
    mapView.setTraffic(false);
    mapView.setSatellite(false);

    mPopView = (ViewGroup) mapActivity.getLayoutInflater().inflate(R.layout.map_popover, null);

    // MapActivity mapActivity = (MapActivity)getContext();
    // WindowManager windowManager = mapActivity.getWindowManager();
    // int width = windowManager.getDefaultDisplay().getWidth();

    mapView.addView(
        mPopView,
        new MapView.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            null,
            MapView.LayoutParams.TOP_LEFT));
    mPopView.setVisibility(View.GONE);
    overlays = mapView.getOverlays();

    Drawable currentLocationMarker =
        this.getContext().getResources().getDrawable(R.drawable.user_location);
    mCurrentLocationOverlay = new MapItemizedOverlay(currentLocationMarker, this);
    mCurrentLocationOverlay.showPop = false;
    Drawable search = this.getContext().getResources().getDrawable(R.drawable.pin);

    bankOverlay = new MapItemizedOverlay(search, this);

    overlays.add(mCurrentLocationOverlay);
    overlays.add(bankOverlay);

    locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);

    mLocationListener1 =
        new LocationListener() {
          public void onLocationChanged(Location location) {
            Log.e(
                "Location",
                "GPSListener  "
                    + "latitude:"
                    + Double.toString(location.getLatitude())
                    + " longtitude:"
                    + Double.toString(location.getLongitude())
                    + " from:"
                    + location.getProvider());
            if (isBetterLocation(location, mCurrentLocation)) {
              setCurrentLocation(location);
              if (mMapShowingForLocationUpdate) {
                addCurrentLocationOverlay();
              }
            }
          }

          public void onStatusChanged(String provider, int status, Bundle extras) {}

          public void onProviderEnabled(String provider) {}

          public void onProviderDisabled(String provider) {}
        };

    mLocationListener2 =
        new LocationListener() {
          private boolean mFirstLaunch;

          public void onLocationChanged(Location location) {
            Log.e(
                "Location",
                "NetworkListener  "
                    + "latitude:"
                    + Double.toString(location.getLatitude())
                    + " longtitude:"
                    + Double.toString(location.getLongitude())
                    + " from:"
                    + location.getProvider());
            if (isBetterLocation(location, mCurrentLocation)) {
              setCurrentLocation(location);
              if (mMapShowingForLocationUpdate) {
                addCurrentLocationOverlay();
              }
            }
            if (mFirstLaunch == true) {
              mFirstLaunch = false;
              locationManager.removeUpdates(mLocationListener2);
            }
          }

          public void onStatusChanged(String provider, int status, Bundle extras) {}

          public void onProviderEnabled(String provider) {}

          public void onProviderDisabled(String provider) {}
        };
    myLocation = (ImageButton) findViewById(R.id.my_location);
    mapLayer = (ImageButton) findViewById(R.id.map_layer);
    showItems = (ImageButton) findViewById(R.id.show_items);
    searchButton = (ImageButton) findViewById(R.id.search_btn);
    searchEdt = (EditText) findViewById(R.id.search_input);
    distance_input = (EditText) findViewById(R.id.distance_input);
    if (App.app.initValue) {

      searchEdt.setText("05387");

      searchEdt.setText("via del tintoretto,200,roma");
    }

    searchButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // BaseMapActivity baseactivity = (BaseMapActivity)getContext();
            // baseactivity.hideKeyboard(searchButton);
            KeyBoardUtils.hideSoftInputFromWindow(mapActivity, searchEdt.getWindowToken());
            ProgressOverlay progressOverlay = new ProgressOverlay(getContext());
            progressOverlay.show(
                "searching...",
                new OnProgressEvent() {

                  @Override
                  public void onProgress() {

                    // Locale locale =
                    // getResources().getConfiguration().locale;

                    final String keyText = searchEdt.getText().toString();
                    searchGeoPoint = searchLocation(keyText);
                    if (searchGeoPoint != null) {
                      searchBarch(keyText);
                    }
                  }
                });
          }
        });

    mapLayer.setOnClickListener(
        new OnClickListener() {

          int i;

          @Override
          public void onClick(View v) {

            i++;
            int value = i % 2;
            switch (value) {
              case 0:
                mapView.setTraffic(false);
                mapView.setSatellite(false);
                break;
              case 1:
                mapView.setTraffic(false);
                mapView.setSatellite(true);

                break;
            }
          }
        });
    showItems.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (enter_distance_layout.getVisibility() == View.VISIBLE) {
              enter_distance_layout.setVisibility(View.GONE);
            } else {

              enter_distance_layout.setVisibility(View.VISIBLE);
            }
          }
        });
    myLocation.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            goToMyLocation();
          }
        });
    handler = new Handler();
    enter_distance_layout = (ViewGroup) findViewById(R.id.enter_distance_layout);
  }
  /**
   * 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;
  }
示例#5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    fl = (FrameLayout) findViewById(R.id.content);
    mSlidingDrawer = (SlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    // Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
              infoLayer.inflateStation(stations.get(msg.arg1));
            }
          }
        };

    RelativeLayout.LayoutParams zoomControlsLayoutParams =
        new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            changeMode(!getBike);
          }
        });

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    stations =
        new StationOverlayList(
            this,
            mapOverlays,
            new Handler() {
              @Override
              public void handleMessage(Message msg) {
                if (msg.what == hOverlay.MOTION_CIRCLE_STOP && !view_all) {
                  // Home Circle has changed its radius
                  try {
                    view_near();
                  } catch (Exception e) {

                  }
                } else if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                  // One station has been touched
                  stations.setCurrent(msg.arg1, getBike);
                  infoLayer.inflateStation(stations.getCurrent());
                } else if (msg.what == hOverlay.LOCATION_CHANGED) {
                  // Location has changed
                  mDbHelper.setCenter(hOverlay.getPoint());

                  try {
                    mDbHelper.updateDistances(hOverlay.getPoint());
                    infoLayer.update();

                    if (view_all) {
                      view_all();
                    } else {
                      view_near();
                    }
                  } catch (Exception e) {

                  }
                  ;
                }
              }
            });
    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper =
        new StationsDBAdapter(
            this,
            mapView,
            new Handler() {
              @Override
              public void handleMessage(Message msg) {
                switch (msg.what) {
                  case StationsDBAdapter.FETCH:
                    ////// Log.i("openBicing", "Data fetched");
                    break;
                  case StationsDBAdapter.UPDATE_MAP:
                    ////// Log.i("openBicing", "Map Updated");
                    progressDialog.dismiss();
                    SharedPreferences settings =
                        getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putBoolean("reload_network", false);
                    editor.commit();
                    StationOverlay current = stations.getCurrent();
                    if (current == null) {
                      infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                    }
                    if (current != null) {
                      current.setSelected(true, getBike);
                      infoLayer.inflateStation(current);
                      if (view_all) view_all();
                      else view_near();
                    } else {
                      //// Log.i("openBicing", "Error getting an station..");
                    }
                    mapView.invalidate();
                    break;
                  case StationsDBAdapter.UPDATE_DATABASE:

                    //// Log.i("openBicing", "Database updated");
                    break;
                  case StationsDBAdapter.NETWORK_ERROR:
                    //// Log.i("openBicing", "Network error, last update from " +
                    // mDbHelper.getLastUpdated());
                    Toast toast =
                        Toast.makeText(
                            getApplicationContext(),
                            getString(R.string.network_error) + mDbHelper.getLastUpdated(),
                            Toast.LENGTH_LONG);
                    toast.show();
                    break;
                }
              }
            },
            stations);

    mDbHelper.setCenter(stations.getHome().getPoint());

    if (savedInstanceState != null) {
      stations.updateHome();
      stations.getHome().setRadius(savedInstanceState.getInt("homeRadius"));
      this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
      updateHome();
    }

    try {
      mDbHelper.loadStations();
      if (savedInstanceState == null) {
        String strUpdated = mDbHelper.getLastUpdated();

        SharedPreferences settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);
        Boolean dirty = settings.getBoolean("reload_network", false);

        if (strUpdated == null || dirty) {
          this.fillData(view_all);
        } else {
          Toast toast =
              Toast.makeText(
                  this.getApplicationContext(),
                  "Last Updated: " + mDbHelper.getLastUpdated(),
                  Toast.LENGTH_LONG);
          toast.show();
        }
      }

    } catch (Exception e) {
      //// Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all) view_all();
    else view_near();
    hOverlay = stations.getHome();
    //// Log.i("openBicing", "CREATE!");
  }