Exemplo n.º 1
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();
  }