Back to project page inbox-android.
The source code is released under:
MIT License
If you think the Android project inbox-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.
package com.inboxapp.androidsdk.apis.taskmanagement; // w w w . j a va 2 s . c o m import android.os.Environment; import android.util.Log; import com.inboxapp.androidsdk.apis.InboxAppClient; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.CreateCustomTagTask; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.CreateDraftWithBodyTask; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.SendDraftWithBodyTask; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.SendDraftWithIDTask; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.UpdateThreadTagsTask; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.base.InboxAppTask; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayDeque; /** * Created by sylvianguessan on 8/13/14. */ public class InboxAppTaskQueue extends ArrayDeque<InboxAppTask> { String mFileName = "InboxAppTask6.txt"; InboxAppClient mInboxAppClient; public void processTask(InboxAppTask inboxAppTask) { saveTaskOnDisk(inboxAppTask); InboxAppTask iatask = getTasksFromDisk(); iatask.executeWithClient(mInboxAppClient, new InboxAppTaskCallback(iatask, this)); } @Override public boolean add(InboxAppTask inboxAppTask) { return super.add(inboxAppTask); } public void setInboxAppClient(InboxAppClient inboxAppClient) { mInboxAppClient = inboxAppClient; } public void executeNextTask() { while (!isEmpty()) { if (mInboxAppClient != null) { InboxAppTask inboxAppTask = this.removeFirst(); inboxAppTask.executeWithClient(mInboxAppClient, new InboxAppTaskCallback(inboxAppTask, this)); } else { Log.e("executeAllTasks()", "mInboxAppClient is NULL. Task will not be executed."); } } } public InboxAppTask getTasksFromDisk() { try { File root = Environment.getExternalStorageDirectory(); String sdcardPath = root.getPath(); File file = new File(sdcardPath + "/"+mFileName); FileInputStream fin = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fin); InboxAppTask task = (InboxAppTask) ois.readObject(); Log.w("InboxAppTask retrieval success", "\nDisk Fetch Successful"); return task; } catch(Exception e) { Log.e("InboxAppTask retrieval problem", "\nDisk Fetch Error:"+e.getMessage()); return null; } } public void saveTaskOnDisk(InboxAppTask inboxAppTask) { FileOutputStream fos = null; ObjectOutputStream out = null; try { File root = Environment.getExternalStorageDirectory(); String sdcardPath = root.getPath(); File file = new File(sdcardPath + "/"+mFileName); file.createNewFile(); fos = new FileOutputStream(file); out = new ObjectOutputStream(fos); out.writeObject(inboxAppTask); out.close(); Log.w("InboxAppTask store", "\nDisk Store Successful/ path:"+sdcardPath); } catch(IOException e) { Log.e("InboxAppTask store problem", "\nDisk Store Error/ cause:" + e.getMessage()); } } }