Back to project page CriminalIntent.
The source code is released under:
MIT License
If you think the Android project 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.ambergleam.criminalintent.model; //from w ww. j a va2 s . c o m import java.util.ArrayList; import java.util.UUID; import com.ambergleam.criminalintent.helper.CriminalIntentJSONSerializer; import android.content.Context; import android.util.Log; public class CrimeLab { private static final String TAG = "CrimeLab"; private static final String FILENAME = "cimes.json"; private ArrayList<Crime> mCrimes; private CriminalIntentJSONSerializer mSerializer; private static CrimeLab sCrimeLab; private Context mAppContext; private CrimeLab(Context appContext) { mAppContext = appContext; mSerializer = new CriminalIntentJSONSerializer(mAppContext, FILENAME); try { mCrimes = mSerializer.loadCrimes(); } catch (Exception e) { mCrimes = new ArrayList<Crime>(); Log.e(TAG, "Error loading crimes: ", e); } } public static CrimeLab get(Context c) { if (sCrimeLab == null) { sCrimeLab = new CrimeLab(c.getApplicationContext()); } return sCrimeLab; } public boolean saveCrimes() { try { mSerializer.saveCrimes(mCrimes); Log.i(TAG, "crimes saved to file"); return true; } catch (Exception e) { Log.e(TAG, "Error saving crimes: ", e); return false; } } public void deleteCrime(Crime c) { mCrimes.remove(c); } public ArrayList<Crime> getCrimes() { return mCrimes; } public Crime getCrime(UUID id) { for (Crime c : mCrimes) { if (c.getId().equals(id)) { return c; } } return null; } public void addCrime(Crime c) { mCrimes.add(c); } }