Android Open Source - Mamytas Task Editor






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.activity;
//from  w  ww .ja v a2  s  .  co  m
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.text.ParseException;

import mn.aug.restfulandroid.R;
import mn.aug.restfulandroid.provider.OwnershipDBAccess;
import mn.aug.restfulandroid.provider.TasksDBAccess;
import mn.aug.restfulandroid.rest.resource.Listw;
import mn.aug.restfulandroid.rest.resource.Task;
import mn.aug.restfulandroid.security.AuthorizationManager;
import mn.aug.restfulandroid.service.WunderlistServiceHelper;
import mn.aug.restfulandroid.util.DateHelper;
import mn.aug.restfulandroid.util.DatePickerFragment;
import mn.aug.restfulandroid.util.Logger;
import mn.aug.restfulandroid.util.TimePickerFragment;

public class TaskEditor extends Activity {


    private  Button button;
    private EditText taskName, taskDueDate, taskDueTime ;
    private String toastVerb = "Cration";
    private WunderlistServiceHelper mWunderlistServiceHelper;
    private OwnershipDBAccess ownershipDBAccess;
    private TasksDBAccess tasksDBAccess;
    private Context context;
    private Boolean edit=false;
    private Task task=null;
    private long task_id=0;
    private long list_id=0;
    private BroadcastReceiver requestReceiver;
    private int requestId=0;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_task);
        ownershipDBAccess = new OwnershipDBAccess(this);
        tasksDBAccess = new TasksDBAccess(this);
        mWunderlistServiceHelper = WunderlistServiceHelper.getInstance(this);
        this.context=this;
        Intent i = getIntent();
        task_id= i.getLongExtra(Task.TASK_ID_EXTRA,0L);
        list_id= i.getLongExtra(Listw.LIST_ID_EXTRA,0L);

        // Initialisation elem vue
        taskName = (EditText) findViewById(R.id.inputTaskName);
        taskDueDate = (EditText) findViewById(R.id.inputTaskDueDate);
        taskDueTime = (EditText) findViewById(R.id.inputTaskDueDateTime);
        button = (Button) findViewById(R.id.btnCreateTask);

        if(task_id!=0){
            tasksDBAccess.open();
            task= tasksDBAccess.retrieveTodo(task_id);
            tasksDBAccess.close();
            taskName.setText(task.getTitle());
            button.setText("Modifier la tche");
            toastVerb = "Edition";
            try {
                taskDueDate.setText(DateHelper.getDateFromDate(task.getDue_date()));
                taskDueTime.setText(DateHelper.getTimeFromDateTime(task.getDue_date()));
            } catch (ParseException e) {showToast("Mauvais format pour la due date, heureusement que vous passez par l !");}
            edit=true;
        }else{
            button.setText("Ajouter la tache");
        }


        // button click event
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String dueDate = null;
                try {
                    dueDate = DateHelper.getDateFromDate(taskDueDate.getText().toString());
                } catch (ParseException e) {showToast("Mauvais format pour la date");return;}
                try {
                    dueDate += " "+DateHelper.getTimeFromTime(taskDueTime.getText().toString());
                } catch (ParseException e) {showToast("Mauvais format pour l'heure");return;}

                Logger.debug("show", "Creating Product " + taskName.getText().toString() + " with due date: " + dueDate + " and list_id: "+list_id);
                showToast(toastVerb+" de la tche " + taskName.getText().toString() + " avec pour chance le : " + dueDate);
                if(!edit) {
                    ownershipDBAccess.open();
                    task = ownershipDBAccess.addTaskGetID(AuthorizationManager.getInstance(context).getUser(), new Task(taskName.getText().toString(), dueDate, list_id));
                    ownershipDBAccess.close();
                    mWunderlistServiceHelper.postTask(task);
                }else{
                    task.setTitle(taskName.getText().toString());
                    task.setDue_date(dueDate);
                    tasksDBAccess.open();
                    tasksDBAccess.updateTodo(task);
                    tasksDBAccess.close();
                    mWunderlistServiceHelper.putTask(task);
                }
                finish();
            }
        });



    }

    public void showDatePickerDialog(View v) {
        DatePickerFragment picker = new DatePickerFragment();
        picker.setTaskDueDate(taskDueDate);
        picker.show(getFragmentManager(), "datePicker");
    }

    public void showTimePickerDialog(View v) {
        TimePickerFragment picker = new TimePickerFragment();
        picker.setTaskDueTime(taskDueTime);
        picker.show(getFragmentManager(), "timePicker");
    }

    private void showToast(String message) {
        if (!isFinishing()) {
            Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    }
}




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