コード例 #1
0
  private void completeTask(TracksAction act) {
    final boolean badcert = _prefs.getBoolean(PreferenceConstants.BADCERT, false);
    final String username = _prefs.getString(PreferenceConstants.USERNAME, null);
    final String password = _prefs.getString(PreferenceConstants.PASSWORD, null);

    Task t = (Task) act.target;
    HttpResponse r;

    Log.d(TAG, "Marking task " + String.valueOf(t.getId()) + " as done");

    try {
      r =
          HttpConnection.put(
              PreferenceUtils.getUri(
                  _prefs, "todos/" + String.valueOf(t.getId()) + "/toggle_check.xml"),
              username,
              password,
              null,
              badcert);
    } catch (Exception e) {
      return;
    }

    t.remove();
    act.notify.sendEmptyMessage(0);
  }
コード例 #2
0
  private void updateProject(TracksAction act) {
    final boolean badcert = _prefs.getBoolean(PreferenceConstants.BADCERT, false);
    final String username = _prefs.getString(PreferenceConstants.USERNAME, null);
    final String password = _prefs.getString(PreferenceConstants.PASSWORD, null);

    Project p = (Project) act.target;

    Log.d(TAG, "Updating project " + String.valueOf(p.getId()));

    StringBuilder xml = new StringBuilder("<project>");
    xml.append("<name>");
    xml.append(p.getName());
    xml.append("</name>");
    xml.append("<description>");
    xml.append(p.getDescription() == null ? "" : p.getDescription());
    xml.append("</description>");
    xml.append("</project>");

    Log.v(TAG, "Sending: " + xml.toString());

    try {
      HttpResponse r;
      int resp;

      if (p.getId() < 0) {
        Log.v(TAG, "Posting to contexts.xml to create new context");
        r =
            HttpConnection.post(
                PreferenceUtils.getUri(_prefs, "projects.xml"),
                username,
                password,
                xml.toString(),
                badcert);
      } else {
        Log.v(TAG, "Putting to update existing context");
        r =
            HttpConnection.put(
                PreferenceUtils.getUri(_prefs, "projects/" + String.valueOf(p.getId()) + ".xml"),
                username,
                password,
                xml.toString(),
                badcert);
      }

      resp = r.getStatusLine().getStatusCode();

      if (resp == 200) {
        Log.d(TAG, "Successfully updated context");
        act.notify.sendEmptyMessage(SUCCESS_CODE);
      } else if (resp == 201) {
        Log.d(TAG, "Successfully created context.");
        String got = r.getFirstHeader("Location").getValue();
        got = got.substring(got.lastIndexOf('/') + 1);
        int pno = Integer.parseInt(got);
        p.setId(pno);
        Log.d(TAG, "ID of new project is: " + String.valueOf(pno));
        act.notify.sendEmptyMessage(SUCCESS_CODE);
      } else {
        Log.w(TAG, "Unexpected response from server: " + String.valueOf(resp));
        act.notify.sendEmptyMessage(UPDATE_FAIL_CODE);
      }
    } catch (Exception e) {
      Log.w(TAG, "Error updating context", e);
      act.notify.sendEmptyMessage(UPDATE_FAIL_CODE);
    }
  }
コード例 #3
0
  private void updateTask(TracksAction act) {
    final boolean badcert = _prefs.getBoolean(PreferenceConstants.BADCERT, false);
    final String username = _prefs.getString(PreferenceConstants.USERNAME, null);
    final String password = _prefs.getString(PreferenceConstants.PASSWORD, null);

    Task t = (Task) act.target;

    Log.d(TAG, "Updating task " + String.valueOf(t.getId()));

    StringBuilder xml = new StringBuilder("<todo>");
    xml.append("<description>");
    xml.append(t.getDescription());
    xml.append("</description>");
    xml.append("<notes>");
    xml.append(t.getNotes() == null ? "" : t.getNotes());
    xml.append("</notes>");
    xml.append("<context-id type=\"integer\">");
    xml.append(String.valueOf(t.getContext().getId()));
    xml.append("</context-id>");

    xml.append("<project-id type=\"integer\"");
    if (t.getProject() == null) {
      xml.append(" nil=\"true\"></project-id>");
    } else {
      xml.append(">");
      xml.append(String.valueOf(t.getProject().getId()));
      xml.append("</project-id>");
    }

    xml.append("<due type=\"datetime\"");
    if (t.getDue() == null) {
      xml.append(" nil=\"true\"></due>");
    } else {
      xml.append(">");
      xml.append(DATEFORM.format(t.getDue()));
      xml.append("</due>");
    }

    xml.append("<show-from type=\"datetime\"");
    if (t.getShowFrom() == null) {
      xml.append(" nil=\"true\"></show-from>");
    } else {
      xml.append(">");
      xml.append(DATEFORM.format(t.getShowFrom()));
      xml.append("</show-from>");
    }

    xml.append("</todo>");

    Log.v(TAG, "Sending: " + xml.toString());

    try {
      HttpResponse r;
      int resp;

      if (t.getId() < 0) {
        Log.v(TAG, "Posting to todos.xml to create new task");
        r =
            HttpConnection.post(
                PreferenceUtils.getUri(_prefs, "todos.xml"),
                username,
                password,
                xml.toString(),
                badcert);
      } else {
        Log.v(TAG, "Putting to update existing task");
        r =
            HttpConnection.put(
                PreferenceUtils.getUri(_prefs, "todos/" + String.valueOf(t.getId()) + ".xml"),
                username,
                password,
                xml.toString(),
                badcert);
      }

      resp = r.getStatusLine().getStatusCode();

      if (resp == 200) {
        Log.d(TAG, "Successfully updated task");
        act.notify.sendEmptyMessage(SUCCESS_CODE);
      } else if (resp == 201) {
        Log.d(TAG, "Successfully created task.");
        String got = r.getFirstHeader("Location").getValue();
        got = got.substring(got.lastIndexOf('/') + 1);
        int tno = Integer.parseInt(got);
        t.setId(tno);
        Log.d(TAG, "ID of new task is: " + String.valueOf(tno));
        act.notify.sendEmptyMessage(SUCCESS_CODE);
      } else {
        Log.w(TAG, "Unexpected response from server: " + String.valueOf(resp));
        act.notify.sendEmptyMessage(UPDATE_FAIL_CODE);
      }
    } catch (Exception e) {
      Log.w(TAG, "Error updating task", e);
      act.notify.sendEmptyMessage(UPDATE_FAIL_CODE);
    }
  }