private void setOverlayImage(int idx) {
    try {
      String groupPath = "images/overlays/svg/" + overlayGroup;

      if (overlays == null) overlays = getAssets().list(groupPath);

      bitmap =
          Bitmap.createBitmap(
              mOverlayView.getWidth(), mOverlayView.getHeight(), Bitmap.Config.ARGB_8888);
      canvas = new Canvas(bitmap);

      String imgPath = groupPath + '/' + overlays[idx];
      //    SVG svg = SVGParser.getSVGFromAsset(getAssets(), "images/overlays/svg/" +
      // overlays[idx],0xFFFFFF,0xCC0000);

      SVG svg = SVGParser.getSVGFromAsset(getAssets(), imgPath);

      Rect rBounds = new Rect(0, 0, mOverlayView.getWidth(), mOverlayView.getHeight());
      Picture p = svg.getPicture();
      canvas.drawPicture(p, rBounds);

      mOverlayView.setImageBitmap(bitmap);
    } catch (IOException ex) {
      Log.e(AppConstants.TAG, "error rendering overlay", ex);
      return;
    }
  }
Example #2
0
  public SVGTileProvider(File file, float dpi) throws IOException {
    mScale = Math.round(dpi + .3f); // Make it look nice on N7 (1.3 dpi)
    mDimension = BASE_TILE_SIZE * mScale;

    mPool = new TileGeneratorPool(POOL_MAX_SIZE);

    SVG svg = new SVGBuilder().readFromInputStream(new FileInputStream(file)).build();
    mSvgPicture = svg.getPicture();
    RectF limits = svg.getLimits();

    // These values map the SVG file to world coordinates.
    // See: http://stackoverflow.com/questions/21167584/google-io-2013-app-mystery-values
    mBaseMatrix = new Matrix();
    mBaseMatrix.setPolyToPoly(
        new float[] {
          0,
          0, // North-West
          limits.width(),
          0, // North-East
          limits.width(),
          limits.height() // South-East
        },
        0,
        BuildConfig.MAP_FLOORPLAN_MAPPING,
        0,
        3);
  }
  public SVGTileProvider(File file, float dpi) throws IOException {
    mScale = Math.round(dpi + .3f); // Make it look nice on N7 (1.3 dpi)
    mDimension = BASE_TILE_SIZE * mScale;

    mPool = new TileGeneratorPool(POOL_MAX_SIZE);

    SVG svg = new SVGBuilder().readFromInputStream(new FileInputStream(file)).build();
    mSvgPicture = svg.getPicture();
    RectF limits = svg.getLimits();

    mBaseMatrix = new Matrix();
    mBaseMatrix.setPolyToPoly(
        new float[] {0, 0, limits.width(), 0, limits.width(), limits.height()},
        0,
        new float[] {
          40.95635986328125f, 98.94217824936158f,
          40.95730018615723f, 98.94123077396628f,
          40.95791244506836f, 98.94186019897214f
        },
        0,
        3);
  }
Example #4
0
  public void addRoutesInSvg(ArrayList<Route> routes) {
    SVG svg1 = SVGParser.getSVGFromResource(getResources(), R.raw.example_map);

    Picture picture1 = svg1.getPicture();

    this.imageHeight = picture1.getHeight();
    this.imageWidth = picture1.getWidth();
    InputStream inputStream = this.getResources().openRawResource(R.raw.example_map);

    InputStreamReader inputreader = new InputStreamReader(inputStream);
    BufferedReader buffreader = new BufferedReader(inputreader);
    String line;
    StringBuilder text = new StringBuilder();
    try {
      while ((line = buffreader.readLine()) != null) {

        //        		Log.d(TAG, "Line: "+count++ +": "+line);
        if (line.contains("</svg>")) {
          Log.d(TAG, "found closing tag");
          String pathSvgString = "";
          for (int i = 0; i < routes.size(); i++) {
            Route r = routes.get(i);
            float fromX = (float) (r.fromX * imageWidth);
            float fromY = (float) (r.fromY * imageHeight);

            float toX = (float) (r.toX * imageWidth);
            float toY = (float) (r.toY * imageHeight);
            pathSvgString =
                pathSvgString
                    + "<line x1=\""
                    + fromX
                    + "\" y1=\""
                    + fromY
                    + "\" x2=\""
                    + toX
                    + "\" y2=\""
                    + toY
                    + "\" style=\"stroke-dasharray: 0;stroke:#003399;stroke-width:3;\"/>\n";

            //	       			    Log.d(TAG, "Path Added: "+"<line x1=\""+fromX+"\" y1=\""+fromY+"\"
            // x2=\""+toX+"\" y2=\""+toY+"\" style=\"stroke-width:1;stroke:#003399;\"/>\n");
          }
          Log.d(TAG, "line before editing: " + line);

          line = line.replace("</svg>", pathSvgString + "</svg>");
          Log.d(TAG, "line after editing: " + line);
        }
        text.append(line + '\n');
      }
    } catch (IOException e) {
    }

    File file = new File("/sdcard/FileWriterTest.svg");
    try {
      if (file.exists()) file.delete();
      FileWriter writer = new FileWriter(file, true);
      writer.write(text.toString());
      writer.flush();
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }