@Override protected void onPostExecute(Boolean result) { if (result) { Toast.makeText(m_a, m_a.getResources().getString(R.string.add_success), Toast.LENGTH_LONG) .show(); } else { Toast.makeText(m_a, m_a.getResources().getString(R.string.add_failed), Toast.LENGTH_LONG) .show(); } // Hide the add UI m_a.cancel_node_add_handler(); }
@Override protected Boolean doInBackground(HashMap<String, String>... params) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); // Load the saved accessToken Token accessToken = new Token( settings.getString("accessToken", null), settings.getString("accessSecret", null)); OAuthService service = new ServiceBuilder() .provider(OpenStreetMapAPI.class) .apiKey("3rTM4by36P1CsMfiwZ1g58L1c1tZOpQWLUo591tx") .apiSecret("Cl2NKl6LFAvKqXpI7Kvccwyamdz80rHAXLruWhbG") .build(); Toast.makeText(m_a, m_a.getResources().getString(R.string.add_loading), Toast.LENGTH_LONG) .show(); /** Getting a changeset from the api */ OAuthRequest changeset_request = new OAuthRequest(Verb.PUT, "http://api.openstreetmap.org/api/0.6/changeset/create"); String changeset_payload = "<osm>\n" + "<changeset>\n" + "<tag k=\"created_by\" v=\"TakeABreak 1.5\"/>\n" + "</changeset>\n" + "</osm>"; changeset_request.addPayload(changeset_payload); changeset_request.addHeader("Content-Length", Integer.toString(changeset_payload.length())); changeset_request.addHeader("Content-Type", "text/xml"); service.signRequest(accessToken, changeset_request); // the access token from step 4 Response changeset_response = changeset_request.send(); Log.d("TakeABreak", "Changeset: " + changeset_response.getBody()); params[0].put("changeset", changeset_response.getBody()); /** PUT-ing the change proper. */ OAuthRequest request = new OAuthRequest(Verb.PUT, "http://api.openstreetmap.org/api/0.6/node/create"); String payload = generatePayload(params[0]); request.addPayload(payload); request.addHeader("Content-Length", Integer.toString(payload.length())); request.addHeader("Content-Type", "text/xml"); service.signRequest(accessToken, request); // the access token from step 4 Response response = request.send(); // Log.d("TakeABreak", response.toString()); Iterator<Entry<String, String>> it = response.getHeaders().entrySet().iterator(); Log.d("TakeABreak", response.getBody()); // System.out.println(response.getBody()); return response.isSuccessful(); // return true; }