Android Open Source - CriminalIntent Crime Lab






From Project

Back to project page CriminalIntent.

License

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.

Java Source Code

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);
  }

}




Java Source Code List

com.ambergleam.criminalintent.controller.CrimeFragment.java
com.ambergleam.criminalintent.controller.CrimeListActivity.java
com.ambergleam.criminalintent.controller.CrimeListFragment.java
com.ambergleam.criminalintent.controller.CrimePagerActivity.java
com.ambergleam.criminalintent.controller.DatePickerFragment.java
com.ambergleam.criminalintent.helper.CriminalIntentJSONSerializer.java
com.ambergleam.criminalintent.helper.SingleFragmentActivity.java
com.ambergleam.criminalintent.model.CrimeLab.java
com.ambergleam.criminalintent.model.Crime.java