예제 #1
0
 public static String getVersionForTracker(Context ctx) {
   String v = Version.getAppName(ctx);
   if (Version.isProductionVersion(ctx)) {
     v = Version.getFullVersion(ctx);
   } else {
     v += " test";
   }
   return v;
 }
예제 #2
0
  public static String writeGpxFile(File fout, GPXFile file, Context ctx) {
    try {
      SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT);
      format.setTimeZone(TimeZone.getTimeZone("UTC"));
      FileOutputStream output = new FileOutputStream(fout);
      XmlSerializer serializer = Xml.newSerializer();
      serializer.setOutput(output, "UTF-8"); // $NON-NLS-1$
      serializer.setFeature(
          "http://xmlpull.org/v1/doc/features.html#indent-output", true); // $NON-NLS-1$
      serializer.startDocument("UTF-8", true); // $NON-NLS-1$
      serializer.startTag(null, "gpx"); // $NON-NLS-1$
      serializer.attribute(null, "version", "1.1"); // $NON-NLS-1$ //$NON-NLS-2$
      if (file.author == null) {
        serializer.attribute(null, "creator", Version.getAppName(ctx)); // $NON-NLS-1$
      } else {
        serializer.attribute(null, "creator", file.author); // $NON-NLS-1$
      }
      serializer.attribute(
          null, "xmlns", "http://www.topografix.com/GPX/1/1"); // $NON-NLS-1$ //$NON-NLS-2$
      serializer.attribute(null, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      serializer.attribute(
          null,
          "xsi:schemaLocation",
          "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");

      for (Track track : file.tracks) {
        serializer.startTag(null, "trk"); // $NON-NLS-1$
        writeNotNullText(serializer, "name", track.name);
        writeNotNullText(serializer, "desc", track.desc);
        for (TrkSegment segment : track.segments) {
          serializer.startTag(null, "trkseg"); // $NON-NLS-1$
          for (WptPt p : segment.points) {
            serializer.startTag(null, "trkpt"); // $NON-NLS-1$
            writeWpt(format, serializer, p);
            serializer.endTag(null, "trkpt"); // $NON-NLS-1$
          }
          serializer.endTag(null, "trkseg"); // $NON-NLS-1$
        }
        writeExtensions(serializer, track);
        serializer.endTag(null, "trk"); // $NON-NLS-1$
      }

      for (Route track : file.routes) {
        serializer.startTag(null, "rte"); // $NON-NLS-1$
        writeNotNullText(serializer, "name", track.name);
        writeNotNullText(serializer, "desc", track.desc);

        for (WptPt p : track.points) {
          serializer.startTag(null, "rtept"); // $NON-NLS-1$
          writeWpt(format, serializer, p);
          serializer.endTag(null, "rtept"); // $NON-NLS-1$
        }
        writeExtensions(serializer, track);
        serializer.endTag(null, "rte"); // $NON-NLS-1$
      }

      for (WptPt l : file.points) {
        serializer.startTag(null, "wpt"); // $NON-NLS-1$
        writeWpt(format, serializer, l);
        serializer.endTag(null, "wpt"); // $NON-NLS-1$
      }

      serializer.endTag(null, "gpx"); // $NON-NLS-1$
      serializer.flush();
      serializer.endDocument();
    } catch (RuntimeException e) {
      log.error("Error saving gpx", e); // $NON-NLS-1$
      return ctx.getString(R.string.error_occurred_saving_gpx);
    } catch (IOException e) {
      log.error("Error saving gpx", e); // $NON-NLS-1$
      return ctx.getString(R.string.error_occurred_saving_gpx);
    }
    return null;
  }