Example #1
0
  @Override
  protected View initView() {
    View view = View.inflate(UIUtils.getContext(), R.layout.item_app_info, null);

    // View注入
    ViewUtils.inject(this, view);

    // 设置点击事件
    mPcvProgress.setOnClickListener(this);

    mDownloadManager = DownloadManager.getInstance(); // 初始化

    return view;
  }
Example #2
0
  /** 刷新UI */
  protected void refreshView(DownloadBean data) {
    // 根据状态来显示
    // 1. 未下载 -----> 用户提示: 下载
    // 2. 等待状态----> 用户提示: 等待中...
    // 3. 下载中 -----> 用户提示: 显示进度
    // 4. 暂停 ------> 用户提示: 继续下载
    // 5. 下载成功----> 用户提示: 安装
    // 6. 下载失败----> 用户提示: 重试
    // 7. 已经安装 ---> 用户提示: 打开
    int downloadState = data.downloadState;

    mPcvProgress.setProgressEnable(false); // 设置默认不可见
    switch (downloadState) {
      case DownloadManager.STATE_DOWNLOADING:
        // 下载中 -----> 用户提示: 显示进度--->0-100
        mPcvProgress.setProgressEnable(true);
        int progress = (int) (data.currenDownloadLength * 100f / data.size + 0.5f);
        mPcvProgress.setTipText(progress + "%");
        mPcvProgress.setProgress(progress);
        mPcvProgress.setTipIcon(R.drawable.ic_pause);
        break;
      case DownloadManager.STATE_INSTALLED:
        // 已经安装 ---> 用户提示: 打开
        mPcvProgress.setTipText("打开");
        mPcvProgress.setTipIcon(R.drawable.ic_install);
        break;
      case DownloadManager.STATE_NONE:
        // 未下载 -----> 用户提示: 下载
        mPcvProgress.setTipText("下载");
        mPcvProgress.setTipIcon(R.drawable.ic_download);
        break;
      case DownloadManager.STATE_FAILED:
        // 下载失败----> 用户提示: 重试
        mPcvProgress.setTipText("重试");
        mPcvProgress.setTipIcon(R.drawable.ic_redownload);
        break;
      case DownloadManager.STATE_PAUSE:
        // 暂停 ------> 用户提示: 继续下载
        mPcvProgress.setTipText("继续下载");
        mPcvProgress.setTipIcon(R.drawable.ic_resume);
        break;
      case DownloadManager.STATE_SUCCESS:
        // 下载成功----> 用户提示: 安装
        mPcvProgress.setTipText("安装");
        mPcvProgress.setTipIcon(R.drawable.ic_install);
        break;
      case DownloadManager.STATE_WAITING:
        // 等待状态----> 用户提示: 等待中...
        mPcvProgress.setTipText("等待中...");
        mPcvProgress.setTipIcon(R.drawable.ic_pause);
        break;
      default:
        break;
    }
  }