Android Open Source - tracks-android Project Editor Activity






From Project

Back to project page tracks-android.

License

The source code is released under:

Copyright (c) 2010 Adam Wolfe Gordon <awg@xvx.ca> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to...

If you think the Android project tracks-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 ca.xvx.tracks;
/*from   w  w w . j a  va  2  s . c  o  m*/
import android.util.Log;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;

public class ProjectEditorActivity extends Activity {
  private static final String TAG = "ProjectEditorActivity";
  
  private EditText _name;
  private EditText _description;

  private Project _project;
  private Handler _commHandler;

  public static final int SAVED = 0;
  public static final int CANCELED = 1;

  @Override
  protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    setContentView(R.layout.projecteditor_activity);

    Button saveButt;
    Button cancelButt;

    final java.text.DateFormat dform = DateFormat.getDateFormat(this);

    Intent intent = getIntent();
    _name = (EditText)findViewById(R.id.PEA_name);
    _description = (EditText)findViewById(R.id.PEA_description);
    saveButt = (Button)findViewById(R.id.PEA_save);
    cancelButt = (Button)findViewById(R.id.PEA_cancel);

    _commHandler = TracksCommunicator.getHandler();
    int pno = intent.getIntExtra("project", -1);
    if(pno >= 0) {
      _project = Project.getProject(pno);
      
      _name.setText(_project.getName());
      _description.setText(_project.getDescription());
    }

    saveButt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Log.v(TAG, "Edit saved");
          save();
        }
      });

    cancelButt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Log.v(TAG, "Edit cancelled");
          setResult(CANCELED);
          finish();
        }
      });
  }

  private void save() {
    final String oldName;
    final String oldDescription;
    final Context context = this;

    Log.d(TAG, "Saving project!");
    
    // Must have a name
    if(_name.length() <= 0) {
      Log.w(TAG, "Attempted to save with no name");
      Toast.makeText(context, R.string.ERR_saveproject_baddata, Toast.LENGTH_LONG).show();
      return;
    }

    if(_project == null) {
      Log.d(TAG, "Creating a new project");
      _project = new Project(_name.getText().toString(), _description.getText().toString(), 0,
                   Project.ProjectState.ACTIVE, null);
      oldName = _project.getName();
      oldDescription = _project.getDescription();
    } else {
      Log.d(TAG, "Updating an existing project");
      oldName = _project.setName(_name.getText().toString());
      oldDescription = _project.setDescription(_description.getText().toString());
    }

    final ProgressDialog p = ProgressDialog.show(context, "", getString(R.string.MSG_saving), true);
    TracksAction a = new TracksAction(TracksAction.ActionType.UPDATE_PROJECT, _project, new Handler() {
        @Override
        public void handleMessage(Message msg) {
          switch(msg.what) {
          case TracksCommunicator.SUCCESS_CODE:
            Log.d(TAG, "Saved successfully");
            p.dismiss();
            setResult(SAVED);
            finish();
            break;
          case TracksCommunicator.UPDATE_FAIL_CODE:
            Log.w(TAG, "Save failed");
            p.dismiss();
            Toast.makeText(context, R.string.ERR_saveproject_general, Toast.LENGTH_LONG).show();
            // Reset task data to stay synced with server.
            _project.setName(oldName);
            _project.setDescription(oldDescription);
            break;
          }
        }
      });
    _commHandler.obtainMessage(0, a).sendToTarget();
  }
}




Java Source Code List

ca.xvx.tracks.ContextEditorActivity.java
ca.xvx.tracks.ContextXmlHandler.java
ca.xvx.tracks.DuplicateContextException.java
ca.xvx.tracks.DuplicateProjectException.java
ca.xvx.tracks.DuplicateTaskException.java
ca.xvx.tracks.ProjectEditorActivity.java
ca.xvx.tracks.ProjectXmlHandler.java
ca.xvx.tracks.Project.java
ca.xvx.tracks.SettingsActivity.java
ca.xvx.tracks.TaskEditorActivity.java
ca.xvx.tracks.TaskListActivity.java
ca.xvx.tracks.TaskListAdapter.java
ca.xvx.tracks.TaskListItem.java
ca.xvx.tracks.TaskXmlHandler.java
ca.xvx.tracks.Task.java
ca.xvx.tracks.TodoContext.java
ca.xvx.tracks.TracksAction.java
ca.xvx.tracks.TracksCommunicator.java
ca.xvx.tracks.preferences.PreferenceConstants.java
ca.xvx.tracks.preferences.PreferenceUtils.java
ca.xvx.tracks.util.HttpConnection.java