Android Open Source - inbox-android Inbox App Task Queue






From Project

Back to project page inbox-android.

License

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.

Java Source Code

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

    }
}




Java Source Code List

com.inboxapp.androidapplication.MainActivity.java
com.inboxapp.androidsdk.apis.InboxAppClient.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTaskCallback.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTaskQueue.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxTaskID.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.CreateCustomTagTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.CreateDraftWithBodyTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.SendDraftWithBodyTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.SendDraftWithIDTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.UpdateThreadTagsTask.java
com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTasks.base.InboxAppTask.java
com.inboxapp.androidsdk.json_objects.collection_objects.ContactList.java
com.inboxapp.androidsdk.json_objects.collection_objects.DraftList.java
com.inboxapp.androidsdk.json_objects.collection_objects.FileList.java
com.inboxapp.androidsdk.json_objects.collection_objects.MessageList.java
com.inboxapp.androidsdk.json_objects.collection_objects.NameSpaceList.java
com.inboxapp.androidsdk.json_objects.collection_objects.ParticipantList.java
com.inboxapp.androidsdk.json_objects.collection_objects.TagList.java
com.inboxapp.androidsdk.json_objects.collection_objects.ThreadList.java
com.inboxapp.androidsdk.json_objects.single_objects.Contact.java
com.inboxapp.androidsdk.json_objects.single_objects.Draft.java
com.inboxapp.androidsdk.json_objects.single_objects.File.java
com.inboxapp.androidsdk.json_objects.single_objects.Message.java
com.inboxapp.androidsdk.json_objects.single_objects.Namespace.java
com.inboxapp.androidsdk.json_objects.single_objects.Participant.java
com.inboxapp.androidsdk.json_objects.single_objects.Tag.java
com.inboxapp.androidsdk.json_objects.single_objects.Thread.java
com.inboxapp.androidsdk.json_objects.single_objects.base.InboxAppSingleObject.java
com.inboxapp.androidsdk.json_objects.single_objects.body_objects.DraftID.java
com.inboxapp.androidsdk.json_objects.single_objects.body_objects.TagEdit.java
com.inboxapp.androidsdk.json_objects.single_objects.body_objects.TagName.java
com.inboxapp.androidsdk.sample_application.SampleArrayAdapter.java
com.inboxapp.androidsdk.sample_application.SampleDetailsActivity.java
com.inboxapp.androidsdk.sample_application.SampleMenuActivity.java
com.inboxapp.androidsdk.scratchpad.Scratchpad_MainActivity.java
com.inboxapp.androidsdk.scratchpad.scratchpad_apis.JacksonContributor.java
com.inboxapp.androidsdk.scratchpad.scratchpad_apis.TestApi.java
com.inboxapp.androidsdk.utils.InboxAppStringUtils.java