コード例 #1
0
  @Override
  public void onDownloadProgressChange(final DownloadInfo downloadInfo) {
    //        Observable.create(new Observable.OnSubscribe<DownloadInfo>() {
    //            @Override
    //            public void call(Subscriber<? super DownloadInfo> subscriber) {
    //                subscriber.onNext(downloadInfo);
    //            }
    //        })
    //        Observable.just(downloadInfo)
    //                .observeOn(AndroidSchedulers.mainThread())
    //                .filter(new Func1<DownloadInfo, Boolean>() {
    //                    @Override
    //                    public Boolean call(DownloadInfo downloadInfo) {
    //                        return appInfo.getId() == downloadInfo.getId();
    //                    }
    //                })
    //                .subscribe(new Action1<DownloadInfo>() {
    //                    @Override
    //                    public void call(DownloadInfo downloadInfo) {
    //                        refreshUI(downloadInfo.getCurrentState(),downloadInfo.getProgress());
    //                    }
    //                });

    // 状态发生切换的时候,UI的具体的变化过程
    if (downloadInfo.getId() == appInfo.getId()) {
      UIUtil.runInMainThread(
          new Runnable() {
            @Override
            public void run() {
              // 根据不同的状态和进度条百分比更新UI操作
              refreshUI(downloadInfo.getCurrentState(), downloadInfo.getProgress());
            }
          });
    }
  }
コード例 #2
0
 private void refreshUI(@DownloadInfo.DownloadState int state, float progress) {
   this.currentState = state;
   this.progress = progress;
   switch (state) {
     case DownloadManager.STATE_NONE:
       btnDownload.setVisibility(View.VISIBLE);
       btnDownload.setText(UIUtil.getString(R.string.app_state_download));
       progressHorizontal.setVisibility(View.GONE);
       break;
     case DownloadManager.STATE_DOWNLOADING:
       btnDownload.setVisibility(View.GONE);
       progressHorizontal.setVisibility(View.VISIBLE);
       progressHorizontal.setProgress(progress);
       progressHorizontal.setCenterText("");
       break;
     case DownloadManager.STATE_PAUSE:
       btnDownload.setVisibility(View.GONE);
       progressHorizontal.setVisibility(View.VISIBLE);
       progressHorizontal.setProgress(progress);
       progressHorizontal.setCenterText(UIUtil.getString(R.string.app_state_paused));
       break;
     case DownloadManager.STATE_ERROR:
       btnDownload.setVisibility(View.VISIBLE);
       btnDownload.setText(UIUtil.getString(R.string.app_state_error));
       progressHorizontal.setVisibility(View.GONE);
       break;
     case DownloadManager.STATE_WAITING:
       btnDownload.setVisibility(View.VISIBLE);
       btnDownload.setText(UIUtil.getString(R.string.app_state_waiting));
       progressHorizontal.setVisibility(View.GONE);
       break;
     case DownloadManager.STATE_DOWNLOADED:
       btnDownload.setVisibility(View.VISIBLE);
       btnDownload.setText(UIUtil.getString(R.string.app_state_downloaded));
       progressHorizontal.setVisibility(View.GONE);
       break;
     default:
       break;
   }
 }
コード例 #3
0
  @Override
  protected View initView() {
    View root = UIUtil.inflate(R.layout.layout_bottom_bar);
    ButterKnife.bind(this, root);

    progressHorizontal = new ProgressHorizontal(UIUtil.getContext());
    // 让百分比的文字可以显示方法
    progressHorizontal.setProgressTextVisible(true);
    // 百分比的文字需要定义成白色
    progressHorizontal.setProgressTextColor(Color.WHITE);
    // 百分比的文字显示大小
    progressHorizontal.setProgressTextSize(UIUtil.dp2px(18));
    // 定义自定义控件的蓝色前景图片
    progressHorizontal.setProgressResource(R.drawable.progress_normal);
    // 定义其灰色背景图片
    progressHorizontal.setProgressBackgroundResource(R.drawable.progress_bg);
    // 将自定义的进度条放置在帧布局上显示
    FrameLayout.LayoutParams layoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    flProgress.addView(progressHorizontal, layoutParams);

    return root;
  }