Exemplo n.º 1
0
  public static void main(String[] args) {
    if (args.length == 0) {
      System.out.println("Usage: java -jar geolocgen.jar [PATH_TO_ZOOM_9_TILES_DIR]");
      return;
    }

    String MAP_DIR = args[0];

    DataOutputStream os = null;
    try {
      File lf = new File(LOOKUP_FILE);
      if (!lf.exists()) lf.createNewFile();

      os = new DataOutputStream(new FileOutputStream(lf.getAbsoluteFile()));

      File[] files = new File(MAP_DIR).listFiles();
      for (File file : files) {
        if (file.isFile()) {
          // ignore wget duplicates (e.g .png.1)
          String fileName = file.getName();
          if (fileName.charAt(fileName.length() - 1) != 'g') continue;

          BufferedImage img = null;
          try {
            img = ImageIO.read(file);
          } catch (IOException e) {
            System.err.println("Cannot read map tile.");
            e.printStackTrace();
          }

          img = Geoloc.preprocessMapTile(img);
          MapTileData mtd = Geoloc.getHash(img);

          if (mtd.weight != 0) {
            os.writeShort(mtd.weight);
            os.writeLong(mtd.hash);
            String[] coords = fileName.substring(0, fileName.length() - 4).split("_");
            os.writeShort(Short.valueOf(coords[0]));
            os.writeShort(Short.valueOf(coords[1]));
          }
        }
      }
    } catch (IOException e) {
      System.err.println("Failed to write lookup file.");
      e.printStackTrace();
    } finally {
      try {
        os.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Write parcelable object
   *
   * @param dest The Parcel in which the object should be written
   * @param flags Additional flags about how the object should be written
   */
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeLong(timestamp);
    dest.writeString(status);
    dest.writeString(freetext);

    if (favoriteLink != null) {
      dest.writeByte((byte) 1);
      favoriteLink.writeToParcel(dest, flags);
    } else {
      dest.writeByte((byte) 0);
    }

    if (photo != null) {
      dest.writeByte((byte) 1);
      photo.writeToParcel(dest, flags);
    } else {
      dest.writeByte((byte) 0);
    }

    if (geoloc != null) {
      dest.writeByte((byte) 1);
      geoloc.writeToParcel(dest, flags);
    } else {
      dest.writeByte((byte) 0);
    }
  }
Exemplo n.º 3
0
 /**
  * Returns a string representation of the object
  *
  * @return String
  */
 public String toString() {
   String result =
       "- Timestamp: "
           + timestamp
           + "\n"
           + "- Status: "
           + status
           + "\n"
           + "- Freetext: "
           + freetext
           + "\n";
   if (favoriteLink != null) {
     result += "- Favorite link: " + favoriteLink.toString() + "\n";
   }
   if (photo != null) {
     result += "- Photo-icon: " + photo.toString() + "\n";
   }
   if (geoloc != null) {
     result += "- Geoloc: " + geoloc.toString() + "\n";
   }
   return result;
 }