Android Open Source - CMPUT-301-Assignment1 File Data Manager






From Project

Back to project page CMPUT-301-Assignment1.

License

The source code is released under:

GNU General Public License

If you think the Android project CMPUT-301-Assignment1 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 ca.ualberta.cs.jkeeling.a1todolist.data;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.util.Log;
import ca.ualberta.cs.jkeeling.a1todolist.models.TDItem;
/*from www. java2s. c om*/
// This class is the in-between for saving and loading data to the internal storage of the android system
public class FileDataManager implements IDataManager{
  private String filename;
  private Context context;
  
  public FileDataManager(Context context){
    this.context = context;
    this.filename = this.context.getFilesDir().getAbsolutePath() + "/todoItemData.sav";
  }
  
  public ArrayList<TDItem> loadItems() {
    ArrayList<TDItem> items = new ArrayList<TDItem>();
    try {
      FileInputStream fis = new FileInputStream(filename);
      ObjectInputStream ois = new ObjectInputStream(fis);
      items = (ArrayList<TDItem>) ois.readObject();
      ois.close();
    } catch (Exception e) {
      Log.i("LonelyTwitter", "Error casting");
      e.printStackTrace();
    } 
    return items;
  }  
  
  public void saveItems(List<TDItem> items) {
    FileOutputStream fos;    
    try {    
      File file = new File(filename);
      fos = new FileOutputStream(file);
      ObjectOutputStream oos = new ObjectOutputStream(fos);
      oos.writeObject(items);
      fos.close();
    } 
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}




Java Source Code List

ca.ualberta.cs.jkeeling.a1todolist.ArchiveActivity.java
ca.ualberta.cs.jkeeling.a1todolist.MainActivity.java
ca.ualberta.cs.jkeeling.a1todolist.SummaryActivity.java
ca.ualberta.cs.jkeeling.a1todolist.adapters.ItemAdapter.java
ca.ualberta.cs.jkeeling.a1todolist.data.FileDataManager.java
ca.ualberta.cs.jkeeling.a1todolist.data.IDataManager.java
ca.ualberta.cs.jkeeling.a1todolist.models.CustomTextView.java
ca.ualberta.cs.jkeeling.a1todolist.models.TDItem.java