Android Open Source - mint Task






From Project

Back to project page mint.

License

The source code is released under:

GNU General Public License

If you think the Android project mint 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.gmail.altakey.mint.model;
/*from  w  w w  . ja  va  2s  .c om*/
import android.database.Cursor;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;

import android.util.Log;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.apache.commons.codec.binary.Hex;

public class Task {
    public static final int COLUMNS = 11;

    public long _id;
    public String _cookie;
    public long id;
    public String title;
    public String note;
    public long modified;
    public long completed;
    public long folder;
    public long context;
    public long priority;
    public long star;
    public long duedate;
    public long duetime;
    public String status;
    public Resolved resolved = new Resolved();
    public boolean grayedout;

    public class Resolved {
        public TaskFolder folder;
        public TaskContext context;
    };

    public void markAsDone() {
        markAsDone(new Date().getTime());
    }

    public void markAsDone(long at) {
        completed = at / 1000;
    }

    public String getContentKey() {
        try {
            final MessageDigest md = MessageDigest.getInstance("MD5");
            final String base = String.format("%s.%s.%s.%s", String.valueOf(context), String.valueOf(folder), String.valueOf(status == null ? 0 : status), title);
            final byte[] bytes = base.getBytes();
            md.update(bytes, 0, bytes.length);
            final String ret =  Hex.encodeHexString(md.digest());
            Log.d("Task", String.format("content key: %s (<- %s)", ret, base));
            return ret;
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    public static Task fromCursor(Cursor c, int offset) {
        final Task task = new Task();
        task._id = c.getLong(offset++);
        task._cookie = c.getString(offset++);
        task.id = c.getLong(offset++);
        task.title = c.getString(offset++);
        task.note = c.getString(offset++);
        task.modified = c.getLong(offset++);
        task.completed = c.getLong(offset++);
        task.priority = c.getLong(offset++);
        task.star = c.getLong(offset++);
        task.duedate = c.getLong(offset++);
        task.duetime = c.getLong(offset++);
        task.status = c.getString(offset++);
        if (c.getColumnCount() > offset) {
            task.resolved.folder = TaskFolder.fromCursor(c, offset);
            offset += TaskFolder.COLUMNS;
            if (c.getColumnCount() > offset) {
                task.resolved.context = TaskContext.fromCursor(c, offset);
            }
        }
        return task;
    }

    public static class JsonAdapter extends TypeAdapter<Task> {
        @Override
        public Task read(JsonReader reader) throws IOException {
            final Task task = new Task();
            reader.beginObject();
            while (reader.hasNext()) {
                final String name = reader.nextName();
                final String value = reader.nextString();
                if ("id".equals(name)) {
                    task.id = Long.valueOf(value);
                } else if ("title".equals(name)) {
                    task.title = value;
                } else if ("note".equals(name)) {
                    task.note = value;
                } else if ("modified".equals(name)) {
                    task.modified = Long.valueOf(value);
                } else if ("completed".equals(name)) {
                    task.completed = Long.valueOf(value);
                } else if ("folder".equals(name)) {
                    task.folder = Long.valueOf(value);
                } else if ("context".equals(name)) {
                    task.context = Long.valueOf(value);
                } else if ("priority".equals(name)) {
                    task.priority = Long.valueOf(value);
                } else if ("star".equals(name)) {
                    task.star = Long.valueOf(value);
                } else if ("duedate".equals(name)) {
                    task.duedate = Long.valueOf(value);
                } else if ("duetime".equals(name)) {
                    task.duetime = Long.valueOf(value);
                } else if ("status".equals(name)) {
                    task.status = value;
                }
            }
            reader.endObject();
            return task;
        }

        @Override
        public void write(JsonWriter writer, Task value) throws IOException {
            final Task task = value;
            writer
                .beginObject()
                .name("id").value(task.id)
                .name("title").value(task.title)
                .name("note").value(task.note)
                .name("modified").value(task.modified)
                .name("completed").value(task.completed)
                .name("folder").value(task.folder)
                .name("context").value(task.context)
                .name("priority").value(task.priority)
                .name("star").value(task.star)
                .name("duedate").value(task.duedate)
                .name("duetime").value(task.duetime)
                .name("status").value(task.status)
                .endObject();
        }
    }
}




Java Source Code List

com.gmail.altakey.mint.activity.ConfigActivity.java
com.gmail.altakey.mint.activity.MainActivity.java
com.gmail.altakey.mint.activity.TaskEditActivity.java
com.gmail.altakey.mint.activity.TaskListActivity.java
com.gmail.altakey.mint.activity.WelcomeActivity.java
com.gmail.altakey.mint.fragment.NavigationFragment.java
com.gmail.altakey.mint.fragment.TaskEditFragment.java
com.gmail.altakey.mint.fragment.TaskGroupListFragment.java
com.gmail.altakey.mint.fragment.TaskListFragment.java
com.gmail.altakey.mint.fragment.TaskPostFragment.java
com.gmail.altakey.mint.fragment.TaskStatusListFragment.java
com.gmail.altakey.mint.fragment.WelcomeFragment.java
com.gmail.altakey.mint.konst.ConfigKey.java
com.gmail.altakey.mint.model.Schema.java
com.gmail.altakey.mint.model.TaskContext.java
com.gmail.altakey.mint.model.TaskFolder.java
com.gmail.altakey.mint.model.TaskStatus.java
com.gmail.altakey.mint.model.Task.java
com.gmail.altakey.mint.provider.BaseProvider.java
com.gmail.altakey.mint.provider.ProviderMap.java
com.gmail.altakey.mint.provider.TaskContextProvider.java
com.gmail.altakey.mint.provider.TaskCountProvider.java
com.gmail.altakey.mint.provider.TaskFolderProvider.java
com.gmail.altakey.mint.provider.TaskProvider.java
com.gmail.altakey.mint.service.ToodledoClientService.java
com.gmail.altakey.mint.service.ToodledoClient.java
com.gmail.altakey.mint.util.Authenticator.java
com.gmail.altakey.mint.util.FilterType.java
com.gmail.altakey.mint.util.Joiner.java
com.gmail.altakey.mint.util.LoaderUtil.java
com.gmail.altakey.mint.util.Notifier.java
com.gmail.altakey.mint.util.ProviderUtils.java
com.gmail.altakey.mint.util.SyncPoker.java
com.gmail.altakey.mint.util.VolatileDialog.java
com.slidingmenu.example.AttachExample.java
com.slidingmenu.example.BaseActivity.java
com.slidingmenu.example.ExampleListActivity.java
com.slidingmenu.example.LeftAndRightActivity.java
com.slidingmenu.example.PropertiesActivity.java
com.slidingmenu.example.SampleListFragment.java
com.slidingmenu.example.SlidingContent.java
com.slidingmenu.example.SlidingTitleBar.java
com.slidingmenu.example.Util.java
com.slidingmenu.example.ViewPagerActivity.java
com.slidingmenu.example.anim.CustomAnimation.java
com.slidingmenu.example.anim.CustomScaleAnimation.java
com.slidingmenu.example.anim.CustomSlideAnimation.java
com.slidingmenu.example.anim.CustomZoomAnimation.java
com.slidingmenu.example.fragments.BirdActivity.java
com.slidingmenu.example.fragments.BirdGridFragment.java
com.slidingmenu.example.fragments.BirdMenuFragment.java
com.slidingmenu.example.fragments.ColorFragment.java
com.slidingmenu.example.fragments.ColorMenuFragment.java
com.slidingmenu.example.fragments.FragmentChangeActivity.java
com.slidingmenu.example.fragments.ResponsiveUIActivity.java
com.slidingmenu.lib.CanvasTransformerBuilder.java
com.slidingmenu.lib.CustomViewAbove.java
com.slidingmenu.lib.CustomViewBehind.java
com.slidingmenu.lib.MenuInterface.java
com.slidingmenu.lib.SlidingMenu.java
com.slidingmenu.lib.app.SlidingActivityBase.java
com.slidingmenu.lib.app.SlidingActivityHelper.java
com.slidingmenu.lib.app.SlidingActivity.java
com.slidingmenu.lib.app.SlidingFragmentActivity.java
com.slidingmenu.lib.app.SlidingListActivity.java
com.slidingmenu.lib.app.SlidingMapActivity.java
com.slidingmenu.lib.app.SlidingPreferenceActivity.java