Android Open Source - Android-CriminalIntent Crime Lab






From Project

Back to project page Android-CriminalIntent.

License

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.

Java Source Code

package com.bignerdranch.android.criminalintent;
//from   www . ja  v a  2s . c  o  m
import android.content.Context;
import android.util.Log;

import org.json.JSONException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;

/**
 * CrimeLab data model for holding an ArrayList of Crime objects
 * Created by mweekes on 12/19/13.
 */
public class CrimeLab {
    private static final String TAG = CrimeLab.class.getSimpleName();
    private static final String FILENAME = "crimes.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 void add(Crime crime) {
        mCrimes.add(crime);
    }

    public void delete(Crime crime) {
        mCrimes.remove(crime);
    }

    public boolean saveCrimes() {
        try {
            mSerializer.saveCrimes(mCrimes);
            Log.d(TAG, "crimes saved to file");
            return true;
        } catch (JSONException jse) {
            Log.e(TAG, "Error saving crimes[JSON]: " + jse);
            return false;
        } catch (IOException ioe) {
            Log.e(TAG, "Error saving crimes: " + ioe);
            return false;
        }
    }

    public static CrimeLab get(Context ctx) {
        if (sCrimeLab == null) {
            sCrimeLab = new CrimeLab(ctx.getApplicationContext());
        }
        return sCrimeLab;
    }

    public ArrayList<Crime> getCrimes() {
        return mCrimes;
    }

    public Crime getCrime(UUID crimeId) {
        for (Crime c : mCrimes) {
            if (c.getId().equals(crimeId)) {
                return c;
            }
        }
        return null;
    }
}




Java Source Code List

com.bignerdranch.android.criminalintent.CrimeCameraActivity.java
com.bignerdranch.android.criminalintent.CrimeCameraFragment.java
com.bignerdranch.android.criminalintent.CrimeFragment.java
com.bignerdranch.android.criminalintent.CrimeLab.java
com.bignerdranch.android.criminalintent.CrimeListActivity.java
com.bignerdranch.android.criminalintent.CrimeListFragment.java
com.bignerdranch.android.criminalintent.CrimePagerActivity.java
com.bignerdranch.android.criminalintent.Crime.java
com.bignerdranch.android.criminalintent.CriminalIntentJSONSerializer.java
com.bignerdranch.android.criminalintent.DatePickerFragment.java
com.bignerdranch.android.criminalintent.ImageFragment.java
com.bignerdranch.android.criminalintent.Photo.java
com.bignerdranch.android.criminalintent.PictureUtils.java
com.bignerdranch.android.criminalintent.SingleFragmentActivity.java
com.bignerdranch.android.criminalintent.dummy.DummyContent.java