/**
   * 执行下载操作
   *
   * @param downloadTask 要下载的业务信息
   */
  public void downloadTask(DownloadItem item, DownloadFileTask downloadTask) {
    /** 正在下载和暂停的都不用去管了 */
    if (null != item && item.status == DownloadItem.STATUS_DOWNLOADING) {
      return;
    }
    final File file = new File(item.filePath);
    /** 已经下载完成了的,也就不用管了 */
    if (FileHelper.isFileExist(file) && file.length() == item.fileSize
        || item.status == DownloadItem.STATUS_FINISHED) {
      return;
    }

    // 检查现在已经下载了多少
    if (FileHelper.isFileExist(file)) {
      item.breakpoint = file.length();
    }

    if ((item.isPaused()
            || item.status == DownloadItem.STATUS_WAITING
            || item.status == DownloadItem.STATUS_FAILED)
        && item.breakpoint != 0
        && item.breakpoint < item.fileSize) {
      downloadTask.setBreakPoint(item.breakpoint);
      downloadTask.setBreakPointHeader();
    }

    item.setStatus(DownloadItem.STATUS_WAITING);
    item.downloadTask = downloadTask;

    /** 下载任务 */
    addRequest(downloadTask);
  }
  /**
   * 个人资料页面下载添加任务 <功能详细描述>
   *
   * @param item [参数说明]
   * @return void [返回类型说明]
   * @exception throws [违例类型] [违例说明]
   * @see [类、类#方法、类#成员]
   */
  public void addDownloadTask(DownloadItem item, int type) {
    lstDownloadTask.add(0, item);

    DownloadFileTask downloadTask = new DownloadFileTask(item, item.downloadServer, item.filePath);

    downloadTask.setContext(item.context);
    downloadTask.handler = item.handler;
    downloadTask.requestType = type;
    // 下载任务
    downloadTask(item, downloadTask);
  }
  /**
   * <一句话功能简述> 由于消息的下载需要传请求体,且是post请求。
   *
   * @param item
   * @param reqBody [参数说明] 下载请求体
   * @return void [返回类型说明]
   * @exception throws [违例类型] [违例说明]
   * @see [类、类#方法、类#成员]
   */
  public void addDownloadMsgNoVideosTask(DownloadItem item, String reqBody) {
    byte[] data = null;
    if (null != reqBody) {
      try {
        LogX.getInstance().i(TAG, "post Data: " + reqBody);
        data = reqBody.getBytes("utf-8");
      } catch (Exception e) {
        LogX.getInstance().e(TAG, e.toString());
      }
    }
    DownloadFileTask downloadTask = new DownloadFileTask(item, item.downloadServer, item.filePath);

    downloadTask.requestType = DownloadFileTask.POST;
    downloadTask.dataBuf = data;

    downloadTask.setContext(item.context);
    downloadTask.fileModeType = item.fileModeType;

    item.downloadTask = downloadTask;
    addRequest(downloadTask);
  }
Example #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_city_cam);

    textName = (TextView) findViewById(R.id.textName);
    textCity = (TextView) findViewById(R.id.textCity);
    textRating = (TextView) findViewById(R.id.textRating);
    textViews = (TextView) findViewById(R.id.textViews);

    city = getIntent().getParcelableExtra(EXTRA_CITY);
    if (city == null) {
      Log.w(TAG, "City object not provided in extra parameter: " + EXTRA_CITY);
      finish();
    }

    camImageView = (ImageView) findViewById(R.id.cam_image);
    progressView = (ProgressBar) findViewById(R.id.progress);

    getSupportActionBar().setTitle(city.name);

    progressView.setVisibility(View.VISIBLE);

    // Здесь должен быть код, инициирующий асинхронную загрузку изображения с веб-камеры
    // в выбранном городе.
    if (savedInstanceState != null) {
      // Пытаемся получить ранее запущенный таск
      downloadTask = (DownloadFileTask) getLastCustomNonConfigurationInstance();
    }
    if (downloadTask == null) {
      downloadTask = new DownloadFileTask(this);
      downloadTask.execute();
    } else {
      downloadTask.attachActivity(this);
    }
  }
  protected void pickImage() {
    String imageUrl = mImages.get(mCurrentImage);

    // And here it is possible to download it... so on,
    // then return file path.

    // Download MP3 file
    try {
      progressDialog =
          ProgressDialog.show(
              this,
              gtxt(R.string.multimedia_editor_progress_wait_title),
              gtxt(R.string.multimedia_editor_imgs_saving_image),
              true,
              false);
      mDownloadMp3Task = new DownloadFileTask();
      mDownloadMp3Task.setActivity(this);
      mDownloadMp3Task.setAddress(imageUrl);
      mDownloadMp3Task.execute();
    } catch (Exception e) {
      progressDialog.dismiss();
      returnFailure(gtxt(R.string.multimedia_editor_something_wrong));
    }
  }