Android Open Source - Mamytas Wunderlist Service






From Project

Back to project page Mamytas.

License

The source code is released under:

GNU General Public License

If you think the Android project Mamytas 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 mn.aug.restfulandroid.service;
//from w  ww.j av  a2s .  c  o m
import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.ResultReceiver;

public class WunderlistService extends IntentService {

  public static final String METHOD_EXTRA = "wunderlist.METHOD_EXTRA";

  public static final String METHOD_GET = "GET";
    public static final String METHOD_PUT = "PUT";
    public static final String METHOD_POST = "POST";
    public static final String METHOD_DELETE = "DELETE";

  public static final String RESOURCE_TYPE_EXTRA = "wunderlist.RESOURCE_TYPE_EXTRA";

    public static final String RESOURCE_EXTRA = "wunderlist.RESOURCE_EXTRA";

    public static final String BODY_EXTRA = "wunderlist.BODY_EXTRA";

    public static final String INFO_EXTRA = "wunderlist.INFO_EXTRA";
    public static final String INFO_EXTRA_2 = "wunderlist.INFO_EXTRA_2";


  public static final int RESOURCE_TYPE_TASKS = 1;
    public static final int RESOURCE_TYPE_LOGIN = 2;
    public static final int RESOURCE_TYPE_TASK= 3;
    public static final int RESOURCE_TYPE_TIMERS= 4;
    public static final int RESOURCE_TYPE_LISTS = 5;
    public static final int RESOURCE_TYPE_LIST = 6;
    public static final int RESOURCE_TYPE_SHARE = 7;

  public static final String SERVICE_CALLBACK = "wunderlist.SERVICE_CALLBACK";

  public static final String ORIGINAL_INTENT_EXTRA = "wunderlist.ORIGINAL_INTENT_EXTRA";

  private static final int REQUEST_INVALID = -1;



    private ResultReceiver mCallback;

  private Intent mOriginalRequestIntent;

  public WunderlistService() {
    super("WunderlistService");
  }

  @Override
  protected void onHandleIntent(Intent requestIntent) {

    mOriginalRequestIntent = requestIntent;

    // Get request data from Intent
        byte[] body= requestIntent.getByteArrayExtra(WunderlistService.BODY_EXTRA);
    String method = requestIntent.getStringExtra(WunderlistService.METHOD_EXTRA);
    int resourceType = requestIntent.getIntExtra(WunderlistService.RESOURCE_TYPE_EXTRA, -1);
        //Resource resource= (Resource) requestIntent.getParcelableExtra(WunderlistService.RESOURCE_EXTRA);
    mCallback = requestIntent.getParcelableExtra(WunderlistService.SERVICE_CALLBACK);

    switch (resourceType) {

            case RESOURCE_TYPE_TASKS:

                if (method.equalsIgnoreCase(METHOD_GET) ) {
                    long list_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);
                    TasksProcessor processor = new TasksProcessor(getApplicationContext());
                    processor.getTasks(makeProcessorCallback(),list_id);
                }else if (method.equalsIgnoreCase(METHOD_POST) ) {

                    long task_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);

                    TasksProcessor processor = new TasksProcessor(getApplicationContext());
                    processor.postTask(makeProcessorCallback(),task_id,body);
                }else{
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;

            case RESOURCE_TYPE_TASK:

                if (method.equalsIgnoreCase(METHOD_DELETE) ) {
                    long task_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);

                    TaskProcessor processor = new TaskProcessor(getApplicationContext());
                    processor.deleteTask(makeProcessorCallback(), task_id);
                }else if (method.equalsIgnoreCase(METHOD_PUT) ) {

                    long task_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);

                    TaskProcessor processor = new TaskProcessor(getApplicationContext());
                    processor.putTask(makeProcessorCallback(), task_id, body);
                }else{
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;

            case RESOURCE_TYPE_LISTS:

                if (method.equalsIgnoreCase(METHOD_GET) ) {
                    ListsProcessor processor = new ListsProcessor(getApplicationContext());
                    processor.getLists(makeProcessorCallback());
                }else if (method.equalsIgnoreCase(METHOD_POST) ) {

                    long list_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);

                    ListsProcessor processor = new ListsProcessor(getApplicationContext());
                    processor.postList(makeProcessorCallback(),list_id, body);
                }else{
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;

            case RESOURCE_TYPE_LIST:

                if (method.equalsIgnoreCase(METHOD_DELETE) ) {
                    long list_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);

                    ListProcessor processor = new ListProcessor(getApplicationContext());
                    processor.deleteList(makeProcessorCallback(),list_id);
                }else if (method.equalsIgnoreCase(METHOD_PUT) ) {

                    long list_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);

                    ListProcessor processor = new ListProcessor(getApplicationContext());
                    processor.putList(makeProcessorCallback(), list_id, body);
                }else{
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;


            case RESOURCE_TYPE_LOGIN:


                if (method.equalsIgnoreCase(METHOD_POST)) {
                    LoginProcessor processor = new LoginProcessor(getApplicationContext());
                    processor.getToken(makeProcessorCallback(),body);
                } else {
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;

            case RESOURCE_TYPE_TIMERS:

                if (method.equalsIgnoreCase(METHOD_GET) ) {
                    long task_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);
                    TimersProcessor processor = new TimersProcessor(getApplicationContext());
                    processor.getTimers(makeProcessorCallback(),task_id);
                }else if (method.equalsIgnoreCase(METHOD_POST) ) {

                    long task_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);
                    long timer_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA_2,0);

                    TimersProcessor processor = new TimersProcessor(getApplicationContext());
                    processor.postTimer(makeProcessorCallback(),task_id, body,timer_id);
                }else if (method.equalsIgnoreCase(METHOD_PUT) ) {

                    long task_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA,0);
                    long timer_id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA_2,0);
                    TimersProcessor processor = new TimersProcessor(getApplicationContext());
                    processor.putTimer(makeProcessorCallback(), task_id, body,timer_id);
                }else {
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;
            case RESOURCE_TYPE_SHARE:
                if (method.equalsIgnoreCase(METHOD_POST) ) {

                    long id = requestIntent.getLongExtra(WunderlistService.INFO_EXTRA, 0);

                    ShareProcessor processor = new ShareProcessor(getApplicationContext());
                    processor.shareList(makeProcessorCallback(), id, body);
                }else {
                    mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
                }
                break;
    default:
      mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
      break;
    }

  }


  private ProcessorCallback makeProcessorCallback() {
    ProcessorCallback callback = new ProcessorCallback() {

      @Override
      public void send(int resultCode) {
        if (mCallback != null) {
                    mCallback.send(resultCode, getOriginalIntentBundle());
                }
      }

            @Override
            public void send(int resultCode, Parcelable resource) {
                if (mCallback != null) {
                    mCallback.send(resultCode, getOriginalIntentBundleWithResource(resource));
                }
            }
        };
    return callback;
  }


  protected Bundle getOriginalIntentBundle() {
    Bundle originalRequest = new Bundle();
    originalRequest.putParcelable(ORIGINAL_INTENT_EXTRA, mOriginalRequestIntent);
    return originalRequest;
  }

    protected Bundle getOriginalIntentBundleWithResource(Parcelable resource) {
        Bundle originalRequest = new Bundle();
        mOriginalRequestIntent.putExtra(RESOURCE_EXTRA,resource);
        originalRequest.putParcelable(ORIGINAL_INTENT_EXTRA, mOriginalRequestIntent);
        return originalRequest;
    }
}




Java Source Code List

mn.aug.restfulandroid.activity.AboutActivity.java
mn.aug.restfulandroid.activity.LoginActivity.java
mn.aug.restfulandroid.activity.ProjectEditor.java
mn.aug.restfulandroid.activity.ProjectsActivity.java
mn.aug.restfulandroid.activity.ProjectsArrayAdapter.java
mn.aug.restfulandroid.activity.TaskActivity.java
mn.aug.restfulandroid.activity.TaskEditor.java
mn.aug.restfulandroid.activity.TasksActivity.java
mn.aug.restfulandroid.activity.TasksArrayAdapter.java
mn.aug.restfulandroid.activity.TimerServiceHelper.java
mn.aug.restfulandroid.activity.TimerService.java
mn.aug.restfulandroid.activity.TimersArrayAdapter.java
mn.aug.restfulandroid.activity.base.RESTfulActivity.java
mn.aug.restfulandroid.activity.base.RESTfulListActivity.java
mn.aug.restfulandroid.activity.base.UndoBarController.java
mn.aug.restfulandroid.provider.CommentsDBAccess.java
mn.aug.restfulandroid.provider.ListsDBAccess.java
mn.aug.restfulandroid.provider.OwnershipDBAccess.java
mn.aug.restfulandroid.provider.ProviderDbHelper.java
mn.aug.restfulandroid.provider.RemindersDBAccess.java
mn.aug.restfulandroid.provider.TasksDBAccess.java
mn.aug.restfulandroid.provider.UsersDBAccess.java
mn.aug.restfulandroid.rest.AbstractRestMethod.java
mn.aug.restfulandroid.rest.DeleteListRestMethod.java
mn.aug.restfulandroid.rest.DeleteTaskRestMethod.java
mn.aug.restfulandroid.rest.GetListsRestMethod.java
mn.aug.restfulandroid.rest.GetTasksRestMethod.java
mn.aug.restfulandroid.rest.GetTimersRestMethod.java
mn.aug.restfulandroid.rest.LoginRestMethod.java
mn.aug.restfulandroid.rest.PostListRestMethod.java
mn.aug.restfulandroid.rest.PostTaskRestMethod.java
mn.aug.restfulandroid.rest.PostTimerRestMethod.java
mn.aug.restfulandroid.rest.PutListRestMethod.java
mn.aug.restfulandroid.rest.PutTaskRestMethod.java
mn.aug.restfulandroid.rest.PutTimerRestMethod.java
mn.aug.restfulandroid.rest.Request.java
mn.aug.restfulandroid.rest.Response.java
mn.aug.restfulandroid.rest.RestClient.java
mn.aug.restfulandroid.rest.RestMethodFactory.java
mn.aug.restfulandroid.rest.RestMethodResult.java
mn.aug.restfulandroid.rest.RestMethod.java
mn.aug.restfulandroid.rest.ShareListRestMethod.java
mn.aug.restfulandroid.rest.resource.Comment.java
mn.aug.restfulandroid.rest.resource.Lists.java
mn.aug.restfulandroid.rest.resource.Listw.java
mn.aug.restfulandroid.rest.resource.Login.java
mn.aug.restfulandroid.rest.resource.Reminder.java
mn.aug.restfulandroid.rest.resource.Resource.java
mn.aug.restfulandroid.rest.resource.TaskList.java
mn.aug.restfulandroid.rest.resource.Task.java
mn.aug.restfulandroid.rest.resource.Tasks.java
mn.aug.restfulandroid.rest.resource.Timer.java
mn.aug.restfulandroid.rest.resource.Timers.java
mn.aug.restfulandroid.security.AuthorizationManager.java
mn.aug.restfulandroid.security.RequestSigner.java
mn.aug.restfulandroid.service.ListProcessor.java
mn.aug.restfulandroid.service.ListsProcessor.java
mn.aug.restfulandroid.service.LoginProcessor.java
mn.aug.restfulandroid.service.ProcessorCallback.java
mn.aug.restfulandroid.service.ShareProcessor.java
mn.aug.restfulandroid.service.TaskProcessor.java
mn.aug.restfulandroid.service.TasksProcessor.java
mn.aug.restfulandroid.service.TimersProcessor.java
mn.aug.restfulandroid.service.WunderlistServiceHelper.java
mn.aug.restfulandroid.service.WunderlistService.java
mn.aug.restfulandroid.util.DateHelper.java
mn.aug.restfulandroid.util.DatePickerFragment.java
mn.aug.restfulandroid.util.Logger.java
mn.aug.restfulandroid.util.TimePickerFragment.java