private <P> void execute(BasicProgressAsyncTask<P, ?, ?> task, P... indexItems) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
     // TODO check
     task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, indexItems);
   } else {
     task.execute(indexItems);
   }
 }
Example #2
0
  @Override
  public void updateProgress(boolean updateOnlyProgress) {
    BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
        DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
    // needed when rotation is performed and progress can be null
    if (progressView == null) {
      return;
    }
    if (updateOnlyProgress) {
      if (!basicProgressAsyncTask.isIndeterminate()) {
        progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
        determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
      }
    } else {
      boolean visible =
          basicProgressAsyncTask != null
              && basicProgressAsyncTask.getStatus() != AsyncTask.Status.FINISHED;
      progressView.setVisibility(visible ? View.VISIBLE : View.GONE);
      if (visible) {
        boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
        indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
        determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
        cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
        progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE);

        progressMessage.setText(basicProgressAsyncTask.getDescription());
        if (!indeterminate) {
          progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
          determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
        }
      }
      updateDownloadButton(false);
    }
  }
  public void updateProgress(boolean updateOnlyProgress) {
    BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
        downloadListIndexThread.getCurrentRunningTask();
    if (updateOnlyProgress) {
      if (!basicProgressAsyncTask.isIndeterminate()) {
        progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
        determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
      }
    } else {
      boolean visible =
          basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != Status.FINISHED;
      progressView.setVisibility(visible ? View.VISIBLE : View.GONE);
      if (visible) {
        boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
        indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
        determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
        cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
        progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE);

        progressMessage.setText(basicProgressAsyncTask.getDescription());
        if (!indeterminate) {
          progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
          determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
        }
      }
      updateDownloadButton(false);
    }
  }
 @Override
 public void setInterrupted(boolean interrupted) {
   super.setInterrupted(interrupted);
   if (interrupted) {
     downloadFileHelper.setInterruptDownloading(true);
   }
 }
 @Override
 protected void onPreExecute() {
   currentRunningTask.add(this);
   super.onPreExecute();
   if (uiActivity != null) {
     downloadFileHelper.setInterruptDownloading(false);
     View mainView = uiActivity.findViewById(R.id.MainLayout);
     if (mainView != null) {
       mainView.setKeepScreenOn(true);
     }
     startTask(ctx.getString(R.string.downloading), -1);
   }
 }
 @Override
 protected void onProgressUpdate(Object... values) {
   for (Object o : values) {
     if (o instanceof DownloadEntry) {
       if (uiActivity != null) {
         ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter())
             .notifyDataSetInvalidated();
         uiActivity.updateDownloadButton(false);
       }
     } else if (o instanceof IndexItem) {
       entriesToDownload.remove(o);
       if (uiActivity != null) {
         ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter())
             .notifyDataSetInvalidated();
         uiActivity.updateDownloadButton(false);
       }
     } else if (o instanceof String) {
       AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
     }
   }
   super.onProgressUpdate(values);
 }