Example #1
0
  public void showMultihostSelectDialog(final ArrayList<HostBriefInfo> hosts) {
    String[] mPossibleItems = new String[hosts.size()];

    double distance =
        Tools.calculateDistanceBetween(
            hosts.get(0).getLatLng(), mLastDeviceLocation, mDistanceUnit);
    String distanceSummary =
        getString(R.string.distance_from_current, (int) distance, mDistanceUnit);

    LinearLayout customTitleView =
        (LinearLayout) getLayoutInflater().inflate(R.layout.multihost_dialog_header, null);
    TextView titleView = (TextView) customTitleView.findViewById(R.id.title);
    titleView.setText(
        getString(R.string.hosts_at_location, hosts.size(), hosts.get(0).getStreetCityAddress()));

    TextView distanceView = (TextView) customTitleView.findViewById(R.id.distance_from_current);
    distanceView.setText(distanceSummary);

    for (int i = 0; i < hosts.size(); i++) {
      mPossibleItems[i] = hosts.get(i).getFullname();
    }
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setCustomTitle(customTitleView);

    alertDialogBuilder
        .setNegativeButton(
            R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                return;
              }
            })
        .setItems(
            mPossibleItems,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int index) {
                Intent intent = new Intent(Maps2Activity.this, HostInformationActivity.class);
                HostBriefInfo briefHost = hosts.get(index);
                Host host = Host.createFromBriefInfo(hosts.get(index));
                intent.putExtra("host", host);
                intent.putExtra("id", briefHost.getId());
                startActivity(intent);
              }
            });
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
  }
Example #2
0
 @Override
 protected void onBeforeClusterItemRendered(HostBriefInfo host, MarkerOptions markerOptions) {
   String street = host.getStreet();
   String snippet = host.getCity() + ", " + host.getProvince().toUpperCase();
   if (street != null && street.length() > 0) {
     snippet = street + "<br/>" + snippet;
   }
   if (mLastDeviceLocation != null) {
     double distance =
         Tools.calculateDistanceBetween(host.getLatLng(), mLastDeviceLocation, mDistanceUnit);
     snippet +=
         "<br/>" + getString(R.string.distance_from_current, (int) distance, mDistanceUnit);
   }
   markerOptions.title(host.getFullname()).snippet(snippet);
   markerOptions.icon(mSingleHostBitmapDescriptor);
 }
Example #3
0
    @Override
    public View getInfoContents(Marker marker) {

      String hostList = "";
      ArrayList<HostBriefInfo> hosts = new ArrayList<HostBriefInfo>();
      if (mPopup == null) {
        mPopup = mInflater.inflate(R.layout.info_window, null);
      }
      TextView tv = (TextView) mPopup.findViewById(R.id.title);

      if (mLastClickedCluster != null) {

        if (mLastDeviceLocation != null) {
          double distance =
              Tools.calculateDistanceBetween(
                  marker.getPosition(), mLastDeviceLocation, mDistanceUnit);
          TextView distance_tv = (TextView) mPopup.findViewById(R.id.distance_from_current);
          distance_tv.setText(
              Html.fromHtml(
                  getString(R.string.distance_from_current, (int) distance, mDistanceUnit)));
        }

        hosts = (ArrayList<HostBriefInfo>) mLastClickedCluster.getItems();
        if (mLastClickedCluster != null) {
          for (HostBriefInfo host : hosts) {
            hostList += host.getFullname() + "<br/>";
          }

          hostList += getString(R.string.click_to_view_all);
        }
        String title =
            getString(R.string.hosts_at_location, hosts.size(), hosts.get(0).getLocation());

        tv.setText(Html.fromHtml(title));
        tv = (TextView) mPopup.findViewById(R.id.snippet);
        tv.setText(Html.fromHtml(hostList));
      }

      return (mPopup);
    }
Example #4
0
  @Override
  public void onCameraChange(CameraPosition position) {
    mLastCameraPosition = position;

    // If not connected, we'll switch to offline/starred hosts mode
    if (!Tools.isNetworkConnected(this)) {
      sendMessage(R.string.map_network_not_connected, false);
      // If we already knew we were offline, return
      if (mIsOffline) {
        return;
      }
      // Otherwise, set state to offline and load only offline hosts
      mIsOffline = true;
      loadOfflineHosts();
      return;
    }

    // If we were offline, switch back on, but remove the offline markers
    if (mIsOffline) {
      mIsOffline = false;
      mClusterManager.clearItems();
      mClusterManager.getMarkerCollection().clear();
      mHosts.clear();
    }

    // And get standard host list for region from server
    LatLngBounds curScreen = mMap.getProjection().getVisibleRegion().latLngBounds;
    Search search = new RestMapSearch(curScreen.northeast, curScreen.southwest);

    if (position.zoom < getResources().getInteger(R.integer.map_zoom_min_load)) {
      sendMessage(R.string.hosts_dont_load, false);
    } else {
      sendMessage(getResources().getString(R.string.loading_hosts), false);
      doMapSearch(search);
    }
  }