コード例 #1
0
 @Override
 public void onDraw(Canvas canvas) {
   if (mapImage == null || mapImage.isRecycled()) {
     return;
   }
   canvas.drawBitmap(mapImage, displayState.getImageToScreenMatrix(), null);
 }
コード例 #2
0
 @Override
 public void centerOnMapCenterLocation() {
   float[] location = displayState.getMapCenterGeoLocation(null);
   if (location != null) {
     centerOnLocation(location[0], location[1]);
   }
 }
コード例 #3
0
 @Override
 public boolean centerOnLocation(float longitude, float latitude) {
   boolean result = displayState.centerOnGeoLocation(longitude, latitude);
   if (result) {
     invalidate();
   }
   return result;
 }
コード例 #4
0
  @Override
  public void onClick(@Nonnull DisplayState data, @Nonnull Context context) {
    final Generic result = data.getResult();

    if (result != null) {
      Locator.getInstance().getCalculator().convert(result, this.toNumeralBase);
    }
  }
コード例 #5
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (userLocation == null || !userLocation.hasAccuracy() || displayState == null) {
      return;
    }
    // Figure out distance from user location to screen center point
    float[] mapLonLat = displayState.getScreenCenterGeoLocation();
    screenCenterLocation.setLatitude(mapLonLat[1]);
    screenCenterLocation.setLongitude(mapLonLat[0]);
    int distanceM = Math.round(userLocation.distanceTo(screenCenterLocation));
    int accuracyM = Math.round(userLocation.getAccuracy());

    // Don't draw if centered
    if (distanceM == 0) {
      return;
    }

    // Format the distance and accuracy nicely
    String distanceStr;
    if (PreferenceStore.instance(getContext()).isMetric()) {
      distanceStr = getMetricDistanceString(distanceM, accuracyM);
    } else {
      distanceStr = getEnglishDistanceString(distanceM, accuracyM);
    }

    // Compute the pixel size of the distanceStr
    // -- set font size based on canvas density (dpi)
    textPaint.setTextSize(ptsToPixels(textSizePt, canvas));
    Rect distanceBox = new Rect();
    textPaint.getTextBounds(distanceStr, 0, distanceStr.length(), distanceBox);
    distanceBox.offsetTo(0, 0);
    int padding = Math.round(ptsToPixels(paddingPt, canvas));
    distanceBox.right += 2 * padding;
    distanceBox.bottom += 2 * padding;
    distanceBox.offset((getWidth() - distanceBox.width()) / 2, getHeight() - distanceBox.height());
    float baseline = distanceBox.bottom - padding;
    backgroundPaint.setAlpha(192);
    backgroundPaint.setStyle(Paint.Style.FILL);
    textPaint.setStrokeWidth(1f);
    textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    canvas.drawRoundRect(new RectF(distanceBox), padding, padding, backgroundPaint);
    canvas.drawText(distanceStr, distanceBox.exactCenterX(), baseline, textPaint);

    // Draw center circles
    int x = getWidth() / 2;
    int y = getHeight() / 2;
    backgroundPaint.setAlpha(255);
    backgroundPaint.setStyle(Paint.Style.STROKE);
    textPaint.setStrokeWidth(2f);
    textPaint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(x, y, 5, backgroundPaint);
    canvas.drawCircle(x, y, 5, textPaint);
  }
コード例 #6
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();
  }
コード例 #7
0
 private String localized(String strKey) {
   return DisplayState.getCurrent().getLocalizedString(strKey);
 }
コード例 #8
0
 @Override
 public void setZoomLevel(float zoom) {
   displayState.setZoomLevel(zoom);
   invalidate();
 }
コード例 #9
0
 @Override
 public void zoomMap(float factor) {
   displayState.zoom(factor);
   invalidate();
 }
コード例 #10
0
 @Override
 public float getZoomLevel() {
   return displayState.getZoomLevel();
 }
コード例 #11
0
 /**
  * Returns float[] containing longitude and latitude of the screen center point. If the system
  * fails to convert screen to image coordinates or image to geo coordinates, returns 'null' (that
  * should never happen).
  *
  * @return geo coordinates (longitude and latitude, in that order) of the screen center point
  */
 @Override
 public float[] getScreenCenterGeoLocation() {
   return displayState.getScreenCenterGeoLocation();
 }
コード例 #12
0
 /**
  * Translates the map image being displayed by (tx, ty). Returns a boolean indicating if the full
  * translation was allowed. Value {@code false} indicates the translation was truncated to avoid
  * scrolling the map off screen.
  *
  * @param tx amount of translation in east-west direction
  * @param ty amount of translation in north-south direction
  * @return {@code true} if the full translation was allowed, {@code false} if the full translation
  *     was not allowed to keep map on screen
  */
 @Override
 public boolean translateMap(float tx, float ty) {
   boolean result = displayState.translate(tx, ty);
   invalidate();
   return result;
 }
コード例 #13
0
 @Override
 public void onSizeChanged(int w, int h, int oldW, int oldH) {
   super.onSizeChanged(w, h, oldW, oldH);
   // Keep the same point centered in the view
   displayState.translate((w - oldW) / 2f, (h - oldH) / 2);
 }