123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package com.example.meinwald.ui.area;
-
- import android.graphics.Bitmap;
- import android.location.Location;
- import android.util.Log;
-
- import com.example.meinwald.BuildConfig;
- import com.google.android.gms.maps.model.LatLng;
-
- import org.json.JSONException;
- import org.json.JSONObject;
-
- import java.sql.Time;
- import java.util.Date;
- import java.util.List;
-
- public class OwnArea {
-
- private String title;
- private String notice;
- private List<LatLng> locations;
- private Bitmap image;
- private String pathImage;
- private String pathLocations;
- private String id;
- private Date time;
-
- public void setImage(Bitmap image) {
- this.image = image;
- }
-
- public void setTitle(String title) {
- this.title = title;
- this.id = generateAreaID(title);
- }
-
- public void setNotice(String notice) {
- this.notice = notice;
- }
-
- public void setLocations(List<LatLng> locations) {
- this.locations = locations;
- }
-
- public void setPathImage(String pathImage) {
- this.pathImage = pathImage;
- }
-
- public void setPathLocations(String pathLocations) {
- this.pathLocations = pathLocations;
- }
-
- public String getNotice() {
- return notice;
- }
-
- public String getTitle() {
- return title;
- }
-
- public Bitmap getImage() {
- return image;
- }
-
- public List<LatLng> getLocations() {
- return locations;
- }
-
- public String getId() {
- return id;
- }
-
- public String getPathImage() {
- return pathImage;
- }
-
- public String getPathLocations() {
- return pathLocations;
- }
-
- public OwnArea()
- {
-
- }
-
- public OwnArea(String jsonString){
- try {
- JSONObject areaObject = new JSONObject(jsonString);
- this.title = areaObject.getString("title");
- this.notice = areaObject.getString("description");
- this.id = areaObject.getString("id");
- this.time = new Date(areaObject.getString("time"));
-
- } catch (JSONException e) {
- if (BuildConfig.DEBUG) {
- Log.e(this.getClass().getSimpleName(), "earthquakeJSON " + jsonString);
- e.printStackTrace();
- }
- }
- }
-
- private String generateAreaID(String title)
- {
- String id = title.replaceAll(" ", "_") + "_" + new Date().getTime();
-
- if (BuildConfig.DEBUG)
- {
- Log.d(getClass().getSimpleName(), "new ID: " + id);
- }
- return id;
- }
-
-
- /**
- * Returns OwnArea as JSONObject.
- *
- * @return the mapped object or null, if parsing fails
- */
- public JSONObject toJSONObject() {
- JSONObject object = new JSONObject();
- try {
- object.put("title",this.title);
- object.put("description",this.notice);
- object.put("id",this.id);
-
- if (this.time != null)
- {
- object.put("time", this.time);
- }
- else
- {
- object.put("time", new Date().getTime());
- }
-
-
- JSONObject locations = new JSONObject();
- Long count = Long.valueOf(0);
-
- //convert all locations
- for (LatLng location: this.locations)
- {
- JSONObject locationObject = new JSONObject();
- locationObject.put("Lat", location.latitude);
- locationObject.put("Lng", location.longitude);
- locations.put("location"+count, locationObject.toString());
- }
- object.put("locations", locations.toString());
-
- return object;
-
- } catch (JSONException e) {
- if (BuildConfig.DEBUG) {
- Log.e(this.getClass().getSimpleName(),
- String.format("Error while parsing epiColorDto to JSONObject. Values of epiColorDto: %s", this.toString()));
- }
- return null;
- }
- }
-
- @Override
- public String toString() {
- return "OwnArea{" +
- "title='" + title + '\'' +
- ", notice='" + notice + '\'' +
- ", pathImage='" + pathImage + '\'' +
- ", pathLocations='" + pathLocations + '\'' +
- ", id='" + id + '\'' +
- '}';
- }
- }
|