@Override
  public void setMap(GroundOverlay newMap) throws MapImageTooLargeException {
    if (mapData == newMap || (mapData != null && mapData.equals(newMap))) {
      return;
    }
    removeAllMapMarkers();
    if (mapImage != null) {
      // Release memory used by the old map image
      mapImage.recycle();
      mapImage = null;
      mapData = null;
    }
    try {
      mapImage = loadMapImage(newMap);
    } catch (IOException ex) {
      // TODO: throw IOException here, and display error message in caller
      Log.w(CustomMaps.LOG_TAG, "Failed to load map image for " + newMap.getName(), ex);
      mapImage = null;
      // Failed to read image, display error message
      String mapName = newMap.getName();
      if (mapName == null || mapName.trim().length() == 0) {
        mapName = getContext().getString(R.string.unnamed_map);
      }
      final String errorMsg = getContext().getString(R.string.map_image_load_failed, mapName);
      post(
          new Runnable() {
            @Override
            public void run() {
              Toast.makeText(getContext(), errorMsg, Toast.LENGTH_LONG).show();
            }
          });
    }
    if (mapImage == null) {
      if (newMap != null) {
        Log.w(CustomMaps.LOG_TAG, "Map image failed to load, map not set.");
      }
      spotSet = false;
      mapData = null;
      return;
    }
    mapData = newMap;

    displayState.setMapData(mapData);
    displayState.setScreenView(this);
    invalidate();
  }
Ejemplo n.º 2
0
  @Override
  public void setMap(GroundOverlay newMap) throws MapImageTooLargeException {
    if (mapData == newMap || (mapData != null && mapData.equals(newMap))) {
      return;
    }
    if (mapImage != null) {
      // Release memory used by the old map image
      mapImage.recycle();
      mapImage = null;
      mapData = null;
    }
    try {
      mapImage = loadMapImage(newMap);
    } catch (IOException ex) {
      mapImage = null;
      // Failed to read image, display error message
      String mapName = newMap.getName();
      final String errorMsg =
          "Failed to load map image"
              + (mapName == null || mapName.trim().length() == 0 ? "" : " for " + mapName);
      post(
          new Runnable() {
            @Override
            public void run() {
              Toast.makeText(getContext(), errorMsg, Toast.LENGTH_LONG).show();
            }
          });
    }
    if (mapImage == null) {
      spotSet = false;
      mapData = null;
      return;
    }
    mapData = newMap;

    displayState.setMapData(mapData);
    displayState.setScreenView(this);
    invalidate();
  }