public String uploadGPXFile(String tagstring, String description, String visibility, File f) { String url = URL_TO_UPLOAD_GPX; Map<String, String> additionalData = new LinkedHashMap<String, String>(); additionalData.put("description", description); additionalData.put("tags", tagstring); additionalData.put("visibility", visibility); return NetworkUtils.uploadFile( url, f, settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(), "file", true, additionalData); }
protected List<OpenStreetNote> loadingBugs( double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) { final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; String SITE_API; if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { SITE_API = "https://api.openstreetmap.org/"; } else { SITE_API = "http://api.openstreetmap.org/"; } List<OpenStreetNote> bugs = new ArrayList<OpenStreetNote>(); StringBuilder b = new StringBuilder(); b.append(SITE_API + "api/0.6/notes?bbox="); // $NON-NLS-1$ b.append(leftLongitude); // $NON-NLS-1$ b.append(",").append(bottomLatitude); // $NON-NLS-1$ b.append(",").append(rightLongitude); // $NON-NLS-1$ b.append(",").append(topLatitude); // $NON-NLS-1$ try { log.info("Loading bugs " + b); // $NON-NLS-1$ URLConnection connection = NetworkUtils.getHttpURLConnection(b.toString()); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); XmlPullParser parser = Xml.newPullParser(); parser.setInput(reader); int tok; OpenStreetNote current = null; int commentIndex = 0; while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { if (tok == XmlPullParser.START_TAG) { if (parser.getName().equals("note")) { current = new OpenStreetNote(); commentIndex = -1; current.setLongitude(Double.parseDouble(parser.getAttributeValue("", "lon"))); current.setLatitude(Double.parseDouble(parser.getAttributeValue("", "lat"))); current.setOpened(true); bugs.add(current); } else if (parser.getName().equals("status") && current != null) { current.setOpened("open".equals(readText(parser, "status"))); } else if (parser.getName().equals("id") && current != null) { current.id = Long.parseLong(readText(parser, "id")); } else if (parser.getName().equals("comment")) { commentIndex++; } else if (parser.getName().equals("user") && current != null) { if (commentIndex == current.users.size()) { current.users.add(readText(parser, "user")); } } else if (parser.getName().equals("date") && current != null) { if (commentIndex == current.dates.size()) { current.dates.add(readText(parser, "date")); } } else if (parser.getName().equals("text") && current != null) { if (commentIndex == current.comments.size()) { current.comments.add(readText(parser, "text")); } } } } reader.close(); } catch (IOException e) { log.warn("Error loading bugs", e); // $NON-NLS-1$ } catch (NumberFormatException e) { log.warn("Error loading bugs", e); // $NON-NLS-1$ } catch (RuntimeException e) { log.warn("Error loading bugs", e); // $NON-NLS-1$ } catch (XmlPullParserException e) { log.warn("Error loading bugs", e); // $NON-NLS-1$ } for (OsmNotesPoint p : local.getOsmbugsPoints()) { if (p.getId() < 0) { OpenStreetNote bug = new OpenStreetNote(); bug.setId(p.getId()); bug.setLongitude(p.getLongitude()); bug.setLatitude(p.getLatitude()); bug.dates.add(""); bug.users.add(activity.getMyApplication().getSettings().USER_NAME.get()); bug.comments.add(p.getText()); bug.setOpened(p.getAction() == Action.CREATE || p.getAction() == Action.MODIFY); bug.setLocal(true); bugs.add(bug); } } return bugs; }