Android Open Source - iLitIt_Android Cig Annotation Writer






From Project

Back to project page iLitIt_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project iLitIt_Android 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 de.unifreiburg.es.iLitIt;
//  w  w w  .j a va2s.  c o m
import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
/**
 * Created by phil on 11/28/14.
 */
public class CigAnnotationWriter extends  DelayedObserver<CigaretteEvent> {
    private static final String TAG = CigAnnotationWriter.class.getSimpleName();
    private final Context mContext;
    public static final String FILENAME = "cigarettes.csv";

    private final Runnable rWriteFile = new Runnable() {
        @Override
        public void run() {
            try {
                FileOutputStream fos = mContext.openFileOutput(FILENAME, mContext.MODE_PRIVATE);

                for (CigaretteEvent ev : mList) {
                    fos.write(ev.toString().getBytes("utf-8"));
                    fos.write("\n".getBytes("utf-8"));
                }

                fos.close();
            } catch (Exception e) {
                Log.e(TAG, "unable to write ", e);
            }

            Log.i(TAG, "succesfully written cigs to " + FILENAME);
        }
    };

    CigAnnotationWriter(Context c) {
        super(DelayedObserver.DEFAULT_DELAY, null);
        mContext = c;
        mAction = rWriteFile;
    }

    public static ObservableLinkedList<CigaretteEvent> readCigaretteList(Context c) {
        ObservableLinkedList<CigaretteEvent> cigList = new ObservableLinkedList<CigaretteEvent>();

        try {
            FileInputStream fis = c.openFileInput(FILENAME);
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            String line;

            while ((line = br.readLine()) != null)
                cigList.add(CigaretteEvent.fromString(line));

        } catch (Exception e) {
            Log.e(TAG, "file load failed", e);
        }

        return cigList;
    }
}




Java Source Code List

de.unifreiburg.es.iLitIt.CigAnnotationWriter.java
de.unifreiburg.es.iLitIt.CigIntentBroadcaster.java
de.unifreiburg.es.iLitIt.CigaretteEvent.java
de.unifreiburg.es.iLitIt.DelayedObserver.java
de.unifreiburg.es.iLitIt.HeatMapFragment.java
de.unifreiburg.es.iLitIt.HomescreenFragment.java
de.unifreiburg.es.iLitIt.JournalFragment.java
de.unifreiburg.es.iLitIt.LighterBluetoothService.java
de.unifreiburg.es.iLitIt.MainActivity.java
de.unifreiburg.es.iLitIt.ObservableLinkedList.java
de.unifreiburg.es.iLitIt.SettingsFragment.java
de.unifreiburg.es.iLitIt.StatsHelper.java