예제 #1
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();
  }
예제 #2
0
  @Override
  protected void onPreExecute() {
    Button btnAuthorize = (Button) context.findViewById(R.id.btnAuthorize);
    btnAuthorize.setEnabled(false);

    progressDialog =
        ProgressDialog.show(
            context, "", context.getString(R.string.msg_retrieving_authorized_token), true, false);
    progressDialog.setOwnerActivity(context);
  }
예제 #3
0
  private TasksXmlExporter(
      final Context context,
      final boolean isService,
      final Runnable runAfterExport,
      File backupDirectoryOverride) {
    this.context = context;
    this.exportCount = 0;
    this.backupDirectory =
        backupDirectoryOverride == null
            ? BackupConstants.defaultExportDirectory()
            : backupDirectoryOverride;

    handler = new Handler();
    progressDialog = new ProgressDialog(context);
    if (!isService) {
      progressDialog.setIcon(android.R.drawable.ic_dialog_info);
      progressDialog.setTitle(R.string.export_progress_title);
      progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
      progressDialog.setProgress(0);
      progressDialog.setCancelable(false);
      progressDialog.setIndeterminate(false);
      progressDialog.show();
      if (context instanceof Activity) progressDialog.setOwnerActivity((Activity) context);
    }

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

                  if (tasks > 0) doTasksExport(output);

                  Preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, DateUtilities.now());
                  Preferences.setString(BackupPreferences.PREF_BACKUP_LAST_ERROR, null);

                  if (!isService) onFinishExport(output);
                } catch (IOException e) {
                  if (!isService)
                    exceptionService.displayAndReportError(
                        context, context.getString(R.string.backup_TXI_error), e);
                  else {
                    exceptionService.reportError("background-backup", e); // $NON-NLS-1$
                    Preferences.setString(BackupPreferences.PREF_BACKUP_LAST_ERROR, e.toString());
                  }
                } finally {
                  if (runAfterExport != null) runAfterExport.run();
                }
              }
            })
        .start();
  }
예제 #4
0
  @Override
  protected void onPreExecute() {
    super.onPreExecute();

    if (isShowDialog) {
      dialog =
          ProgressDialog.show(
              context, null, context.getString(R.string.msg_profile_photo_uploading));
      dialog.setCancelable(true);
      dialog.setOnCancelListener(onCancelListener);
      dialog.setOwnerActivity((Activity) context);
    }
  }