Example #1
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;
   }
 }
Example #2
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;
  }