Back to project page Android-CriminalIntent.
The source code is released under:
MIT License
If you think the Android project Android-CriminalIntent listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bignerdranch.android.criminalintent; /*w w w. ja v a2 s .co m*/ import org.json.JSONException; import org.json.JSONObject; import java.util.Date; import java.util.UUID; /** * Crime model object for CriminalIntent app. * * Created by mweekes on 12/15/13. */ public class Crime { private static final String JSON_ID = "id"; private static final String JSON_TITLE = "title"; private static final String JSON_SOLVED = "solved"; private static final String JSON_DATE = "date"; private static final String JSON_PHOTO = "photo"; private static final String JSON_SUSPECT = "suspect"; private static final String JSON_PHONE_NUM = "phone_num"; private UUID mId; private String mTitle; private Date mDate; private boolean mSolved; private Photo mPhoto; private String mSuspect; private String mPhoneNum; public Crime() { // Generate unique identifier mId = UUID.randomUUID(); mDate = new Date(); } public Crime(JSONObject json) throws JSONException { mId = UUID.fromString(json.getString(JSON_ID)); mTitle = json.getString(JSON_TITLE); mSolved = json.getBoolean(JSON_SOLVED); mDate = new Date(json.getLong(JSON_DATE)); if (json.has(JSON_PHOTO)) { mPhoto = new Photo(json.getJSONObject(JSON_PHOTO)); } if (json.has(JSON_SUSPECT)) { mSuspect = json.getString(JSON_SUSPECT); } if (json.has(JSON_PHONE_NUM)) { mPhoneNum = json.getString(JSON_PHONE_NUM); } } public JSONObject toJSON() throws JSONException { JSONObject json = new JSONObject(); json.put(JSON_ID, getId().toString()); json.put(JSON_TITLE, getTitle()); json.put(JSON_SOLVED, isSolved()); json.put(JSON_DATE, getDate().getTime()); if (getPhoto() != null) { json.put(JSON_PHOTO, getPhoto().toJSON()); json.put(JSON_SUSPECT, getSuspect()); json.put(JSON_PHONE_NUM, getPhoneNum()); } return json; } public UUID getId() { return mId; } public String getTitle() { return mTitle; } public void setTitle(String title) { mTitle = title; } public Date getDate() { return mDate; } public void setDate(Date date) { mDate = date; } public boolean isSolved() { return mSolved; } public void setSolved(boolean solved) { mSolved = solved; } public Photo getPhoto() { return mPhoto; } public void setPhoto(Photo photo) { mPhoto = photo; } public String getSuspect() { return mSuspect; } public void setSuspect(String suspect) { mSuspect = suspect; } public String getPhoneNum() { return mPhoneNum; } public void setPhoneNum(String phoneNum) { mPhoneNum = phoneNum; } @Override public String toString() { return mTitle; } }