Android Open Source - myToDo To Do Options Dialog






From Project

Back to project page myToDo.

License

The source code is released under:

Apache License

If you think the Android project myToDo 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.gutspot.apps.android.mytodo.dialog;
//from  ww w  .j a  v  a  2  s  .c o m
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;

import com.gutspot.apps.android.mytodo.MainActivity;
import com.gutspot.apps.android.mytodo.ToDoActivity;
import com.gutspot.apps.android.mytodo.dao.MemoDAO;
import com.gutspot.apps.android.mytodo.dao.ToDoDAO;
import com.gutspot.apps.android.mytodo.utils.AlertUtil;

public class ToDoOptionsDialog extends DialogFragment implements OnClickListener {
    private static final String[] options = new String[] { "??", "??" };

    private Context context;
    private long toDoId;

    public static ToDoOptionsDialog newInstance(Context context, long toDoId) {
        ToDoOptionsDialog dialog = new ToDoOptionsDialog();
        dialog.context = context;
        dialog.toDoId = toDoId;
        return dialog;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("????");
        builder.setItems(options, this);
        return builder.create();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
        case 0:
            viewToDo();
            break;

        case 1:
            deleteToDo();
            break;

        default:

        }
    }

    private void viewToDo() {
        Intent intent = new Intent(context, ToDoActivity.class);
        intent.putExtra("todo_id", toDoId);
        context.startActivity(intent);
    }

    private void deleteToDo() {
        String message = "??????ToDo?";

        String yesLabel = "?";
        DialogInterface.OnClickListener yesListener = new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ToDoDAO toDoDAO = new ToDoDAO(context);
                toDoDAO.remove(toDoId);
                MemoDAO memoDAO = new MemoDAO(context);
                memoDAO.removeByToDoId(toDoId);
                // TODO: Remove all related notice
                ((MainActivity) context).updateToDoListView();
            }
        };

        String noLabel = "???";
        DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        };

        AlertUtil.show(context, message, yesLabel, yesListener, noLabel, noListener);
    }
}




Java Source Code List

com.gutspot.apps.android.mytodo.MainActivity.java
com.gutspot.apps.android.mytodo.MemoActivity.java
com.gutspot.apps.android.mytodo.ToDoActivity.java
com.gutspot.apps.android.mytodo.adapter.MemoAdapter.java
com.gutspot.apps.android.mytodo.adapter.ToDoAdapter.java
com.gutspot.apps.android.mytodo.dao.AbstractDAO.java
com.gutspot.apps.android.mytodo.dao.MemoDAO.java
com.gutspot.apps.android.mytodo.dao.NoticeDAO.java
com.gutspot.apps.android.mytodo.dao.ToDoDAO.java
com.gutspot.apps.android.mytodo.dialog.DateTimeDialog.java
com.gutspot.apps.android.mytodo.dialog.MemoOptionsDialog.java
com.gutspot.apps.android.mytodo.dialog.ToDoOptionsDialog.java
com.gutspot.apps.android.mytodo.model.AbstractEntity.java
com.gutspot.apps.android.mytodo.model.Memo.java
com.gutspot.apps.android.mytodo.model.Notice.java
com.gutspot.apps.android.mytodo.model.ToDo.java
com.gutspot.apps.android.mytodo.utils.AlertUtil.java
com.gutspot.apps.android.mytodo.utils.DBOpenHelper.java
com.gutspot.apps.android.mytodo.utils.DateTimeUtil.java