@Override
 long intervalMillis() {
   try {
     return SECONDS.toMillis(
         preferences.getIntegerFromString(R.string.gtasks_GPr_interval_key, 0));
   } catch (Exception e) {
     log.error(e.getMessage(), e);
     preferences.setString(R.string.gtasks_GPr_interval_key, "0");
     return 0;
   }
 }
Exemple #2
0
  private void doTasksExport(String output) throws IOException {
    File xmlFile = new File(output);
    xmlFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(xmlFile);
    xml = Xml.newSerializer();
    xml.setOutput(fos, BackupConstants.XML_ENCODING);

    xml.startDocument(null, null);
    xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

    xml.startTag(null, BackupConstants.ASTRID_TAG);
    xml.attribute(
        null,
        BackupConstants.ASTRID_ATTR_VERSION,
        Integer.toString(preferences.getLastSetVersion()));
    xml.attribute(null, BackupConstants.ASTRID_ATTR_FORMAT, Integer.toString(FORMAT));

    serializeTasks();
    serializeTagDatas();

    xml.endTag(null, BackupConstants.ASTRID_TAG);
    xml.endDocument();
    xml.flush();
    fos.close();
  }
 void createStartAndEndDate(Task task, ContentValues values) {
   long dueDate = task.getDueDate();
   long tzCorrectedDueDate = dueDate + TimeZone.getDefault().getOffset(dueDate);
   long tzCorrectedDueDateNow =
       DateUtilities.now() + TimeZone.getDefault().getOffset(DateUtilities.now());
   // FIXME: doesnt respect timezones, see story 17443653
   if (task.hasDueDate()) {
     if (task.hasDueTime()) {
       long estimatedTime = task.getEstimatedSeconds() * 1000;
       if (estimatedTime <= 0) {
         estimatedTime = DEFAULT_CAL_TIME;
       }
       if (preferences.getBoolean(R.string.p_end_at_deadline, true)) {
         values.put("dtstart", dueDate);
         values.put("dtend", dueDate + estimatedTime);
       } else {
         values.put("dtstart", dueDate - estimatedTime);
         values.put("dtend", dueDate);
       }
       // setting a duetime to a previously timeless event requires explicitly setting allDay=0
       values.put("allDay", "0");
       values.put("eventTimezone", TimeZone.getDefault().getID());
     } else {
       values.put("dtstart", tzCorrectedDueDate);
       values.put("dtend", tzCorrectedDueDate);
       values.put("allDay", "1");
     }
   } else {
     values.put("dtstart", tzCorrectedDueDateNow);
     values.put("dtend", tzCorrectedDueDateNow);
     values.put("allDay", "1");
   }
   adjustDateForIcs(values);
 }
Exemple #4
0
  public void exportTasks(
      final Context context, final ExportType exportType, DialogBuilder dialogBuilder) {
    this.context = context;
    this.exportCount = 0;
    this.backupDirectory = preferences.getBackupDirectory();
    this.latestSetVersionName = null;

    handler = exportType == ExportType.EXPORT_TYPE_MANUAL ? new Handler() : null;
    if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
      progressDialog = dialogBuilder.newProgressDialog();
      progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
      progressDialog.setProgress(0);
      progressDialog.setCancelable(false);
      progressDialog.setIndeterminate(false);
      progressDialog.show();
      if (context instanceof Activity) {
        progressDialog.setOwnerActivity((Activity) context);
      }
    } else {
      progressDialog = new ProgressDialog(context);
    }

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  String output = setupFile(backupDirectory, exportType);
                  int tasks = taskService.countTasks();

                  if (tasks > 0) {
                    doTasksExport(output);
                  }

                  preferences.setLong(PREF_BACKUP_LAST_DATE, DateUtilities.now());

                  if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
                    onFinishExport(output);
                  }
                } catch (IOException e) {
                  Timber.e(e, e.getMessage());
                } finally {
                  post(
                      new Runnable() {
                        @Override
                        public void run() {
                          if (progressDialog.isShowing() && context instanceof Activity) {
                            DialogUtilities.dismissDialog((Activity) context, progressDialog);
                            ((Activity) context).finish();
                          }
                        }
                      });
                }
              }
            })
        .start();
  }
 private void createTaskEventIfEnabled(Task t, boolean deleteEventIfExists) {
   if (preferences.isDefaultCalendarSet()) {
     ContentResolver cr = context.getContentResolver();
     Uri calendarUri = createTaskEvent(t, cr, new ContentValues(), deleteEventIfExists);
     if (calendarUri != null) {
       t.setCalendarUri(calendarUri.toString());
     }
   }
 }
  public Uri createTaskEvent(
      Task task, ContentResolver cr, ContentValues values, boolean deleteEventIfExists) {
    String eventuri = getTaskEventUri(task);

    if (!TextUtils.isEmpty(eventuri) && deleteEventIfExists) {
      deleteTaskEvent(task);
    }

    try {
      Uri uri = getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
      values.put("title", task.getTitle());
      values.put("description", task.getNotes());
      values.put("hasAlarm", 0);
      if (preIceCreamSandwich()) {
        values.put("transparency", 0);
        values.put("visibility", 0);
      }
      boolean valuesContainCalendarId =
          (values.containsKey(CALENDAR_ID_COLUMN)
              && !TextUtils.isEmpty(values.getAsString(CALENDAR_ID_COLUMN)));
      if (!valuesContainCalendarId) {
        String calendarId = preferences.getDefaultCalendar();
        if (!TextUtils.isEmpty(calendarId)) {
          values.put("calendar_id", calendarId);
        }
      }

      createStartAndEndDate(task, values);

      Uri eventUri = cr.insert(uri, values);
      cr.notifyChange(eventUri, null);

      return eventUri;

    } catch (Exception e) {
      // won't work on emulator
      log.error(e.getMessage(), e);
    }

    return null;
  }
 @Override
 public SharedPreferences getSharedPreferences(String name, int mode) {
   return preferences.getPrefs();
 }