/** * Returns a bitmap of the user's attached media * * <p>It seems we cannot use Uri's directly, without running out of memory. This will safely * generate a small bitmap ready to attach to an ImageView * * @param width * @param height * @param context * @return Bitmap */ public Bitmap getMediaBitmap(int width, int height, Context context) { String m = post_data.optString(Open311.MEDIA); if (!m.equals("")) { Uri imageUri = Uri.parse(m); if (imageUri != null) { String path = Media.getRealPathFromUri(imageUri, context); return Media.decodeSampledBitmap(path, width, height, context); } } return null; }
/** * Returns the attribute datatype based on the attribute code * * <p>If it cannot determine the datatype, it returns "string" as the default * * @param code * @return String */ public String getAttributeDatatype(String code) { String type = Open311.STRING; try { JSONObject a = getAttribute(code); type = a.optString(Open311.DATATYPE, Open311.STRING); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return type; }
/** * Returns the attribute description based on the attribute code * * <p>Returns an empty string if it cannot find the requested attribute * * @param code * @return String */ public String getAttributeDescription(String code) { String description = ""; try { JSONObject a = getAttribute(code); description = a.optString(Open311.DESCRIPTION); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return description; }
/** * @param code * @throws JSONException * @return JSONObject */ public JSONObject getAttribute(String code) throws JSONException { JSONObject attribute = null; JSONArray attributes = service_definition.optJSONArray(Open311.ATTRIBUTES); int len = attributes.length(); for (int i = 0; i < len; i++) { JSONObject a = attributes.getJSONObject(i); if (a.optString(Open311.CODE).equals(code)) { attribute = a; break; } } return attribute; }
/** * Returns the URL for getting a service_request_id from a token * * @param token * @return String * @throws JSONException */ public String getServiceRequestIdFromTokenUrl(String token) throws JSONException { String baseUrl = endpoint.getString(Open311.URL); String jurisdiction = endpoint.optString(Open311.JURISDICTION); return String.format( "%s/tokens/%s.json?%s=%s", baseUrl, token, Open311.JURISDICTION, jurisdiction); }
/** * Returns the URL for getting fresh information from the endpoint * * @param request_id * @return String * @throws JSONException */ public String getServiceRequestUrl(String request_id) throws JSONException { String baseUrl = endpoint.getString(Open311.URL); String jurisdiction = endpoint.optString(Open311.JURISDICTION); return String.format( "%s/requests/%s.json?%s=%s", baseUrl, request_id, Open311.JURISDICTION, jurisdiction); }