/**
     * Returns an icon for the vehicle that should be shown on the map
     *
     * @param isRealtime true if the marker shown indicate real-time info, false if it should
     *     indicate schedule
     * @param status the vehicles status to add to the map
     * @param response the response which contained the provided status
     * @return an icon for the vehicle that should be shown on the map
     */
    private BitmapDescriptor getVehicleIcon(
        boolean isRealtime, ObaTripStatus status, ObaTripsForRouteResponse response) {
      int colorResource;
      Resources r = Application.get().getResources();

      if (isRealtime) {
        long deviationMin = TimeUnit.SECONDS.toMinutes(status.getScheduleDeviation());
        colorResource = ArrivalInfo.computeColorFromDeviation(deviationMin);
      } else {
        colorResource = R.color.stop_info_scheduled_time;
      }
      int color = r.getColor(colorResource);
      double direction = MathUtils.toDirection(status.getOrientation());
      int halfWind = MathUtils.getHalfWindIndex((float) direction, NUM_DIRECTIONS - 1);
      // Log.d(TAG, "VehicleId=" + status.getVehicleId() + ", orientation= " +
      // status.getOrientation() + ", direction=" + direction + ", halfWind= " + halfWind + ",
      // deviation=" + status.getScheduleDeviation());

      String key = createBitmapCacheKey(halfWind, colorResource);
      Bitmap b = getBitmapFromCache(key);
      if (b == null) {
        // Cache miss - create Bitmap and add to cache
        b = UIUtils.colorBitmap(vehicle_icons[halfWind], color);
        addBitmapToCache(key, b);
      }
      return BitmapDescriptorFactory.fromBitmap(b);
    }
Пример #2
0
  private void drawArrow(Canvas c) {
    int height = getHeight();
    int width = getWidth();

    // Create a buffer around the arrow so when it rotates it doesn't get clipped by view edge
    final float BUFFER = width / 5;

    // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle)
    final float CUTOUT_HEIGHT = getHeight() / 5;

    float x1, y1; // Tip of arrow
    x1 = width / 2;
    y1 = BUFFER;

    float x2, y2; // lower left
    x2 = BUFFER;
    y2 = height - BUFFER;

    float x3, y3; // cutout in arrow bottom
    x3 = width / 2;
    y3 = height - CUTOUT_HEIGHT - BUFFER;

    float x4, y4; // lower right
    x4 = width - BUFFER;
    y4 = height - BUFFER;

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    path.lineTo(x1, y1);
    path.close();

    float direction = mHeading - mBearingToStop;
    // Make sure value is between 0-360
    direction = MathUtils.mod(direction, 360.0f);

    // Rotate arrow around center point
    Matrix matrix = new Matrix();
    matrix.postRotate((float) -direction, width / 2, height / 2);
    path.transform(matrix);

    c.drawPath(path, mArrowPaint);
    c.drawPath(path, mArrowFillPaint);

    // Update content description, so screen readers can announce direction to stop
    String[] spokenDirections = getResources().getStringArray(R.array.spoken_compass_directions);
    String directionName = spokenDirections[MathUtils.getHalfWindIndex(direction)];
    setContentDescription(directionName);
  }