setMax ( )源码实例Demo

android.widget.ProgressBar#setMax ( )源码实例Demo

下面列出了android.widget.ProgressBar#setMax ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sensors-samples   文件: Card.java
/**
 * Build the progress view into the given ViewGroup.
 *
 * @param inflater
 * @param actionArea
 */
private void initializeProgressView(LayoutInflater inflater, ViewGroup actionArea) {

    // Only inflate progress layout if a progress type other than NO_PROGRESS was set.
    if (mCard.mCardProgress != null) {
        //Setup progress card.
        View progressView = inflater.inflate(R.layout.card_progress, actionArea, false);
        ProgressBar progressBar = 
                (ProgressBar) progressView.findViewById(R.id.card_progress);
        ((TextView) progressView.findViewById(R.id.card_progress_text))
                .setText(mCard.mCardProgress.label);
        progressBar.setMax(mCard.mCardProgress.maxValue);
        progressBar.setProgress(0);
        mCard.mCardProgress.progressView = progressView;
        mCard.mCardProgress.setProgressType(mCard.getProgressType());
        actionArea.addView(progressView);
    }
}
 
源代码2 项目: YalpStore   文件: DetailsProgressListener.java
@Override
public void onProgress(long bytesDownloaded, long bytesTotal) {
    if (null == activityRef.get()) {
        return;
    }
    activityRef.get().findViewById(R.id.download_progress_container).setVisibility(View.VISIBLE);
    ((TextView) activityRef.get().findViewById(R.id.download_progress_size)).setText(activityRef.get().getString(
        R.string.notification_download_progress,
        Formatter.formatShortFileSize(activityRef.get(), bytesDownloaded),
        Formatter.formatShortFileSize(activityRef.get(), bytesTotal)
    ));
    activityRef.get().findViewById(R.id.download).setVisibility(View.GONE);
    ProgressBar progressBar = activityRef.get().findViewById(R.id.download_progress);
    progressBar.setIndeterminate(false);
    progressBar.setProgress((int) bytesDownloaded);
    progressBar.setMax((int) bytesTotal);
}
 
源代码3 项目: HaoReader   文件: CacheManagerActivity.java
private void setProgress(int max, int progress) {
    ProgressBar progressBar = progressDialog.findViewById(R.id.progress_bar);
    TextView tvPercent = progressDialog.findViewById(R.id.tv_progress_percent);
    TextView tvProgress = progressDialog.findViewById(R.id.tv_progress);
    if (progressBar != null) {
        progressBar.setMax(max);
        progressBar.setProgress(progress);
    }

    if (tvPercent != null) {
        if (max != 0) {
            tvPercent.setText(String.format(Locale.getDefault(), "%d%%", NumberUtil.getPercent(progress, max)));
        } else {
            tvPercent.setText("0%");
        }
    }

    if (tvProgress != null) {
        tvProgress.setText(String.format(Locale.getDefault(), "%d/%d", progress, max));
    }
}
 
源代码4 项目: budget-watch   文件: BudgetActivity.java
private void setupTotalEntry(final List<Budget> budgets, final Budget blankBudget)
{
    final TextView budgetName = (TextView)findViewById(R.id.budgetName);
    final TextView budgetValue = (TextView)findViewById(R.id.budgetValue);
    final ProgressBar budgetBar = (ProgressBar)findViewById(R.id.budgetBar);

    budgetName.setText(R.string.totalBudgetTitle);

    int max = 0;
    int current = 0;

    for(Budget budget : budgets)
    {
        max += budget.max;
        current += budget.current;
    }

    current += blankBudget.current;

    budgetBar.setMax(max);
    budgetBar.setProgress(current);

    String fraction = String.format(getResources().getString(R.string.fraction), current, max);
    budgetValue.setText(fraction);
}
 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.step_display, container, false);
    mNumSteps = (TextView) rootView.findViewById(R.id.num_steps_taken);
    mMinutesPerMile = (TextView) rootView.findViewById(R.id.minutes_per_mile);
    mTimeExercised = (TextView) rootView.findViewById(R.id.time_exercised);
    mWeaponChargedPercentage = (TextView) rootView.findViewById(R.id.percent_weapon_charged);

    mProgressBar = (ProgressBar) rootView.findViewById(R.id.circular_progress_bar);
    mProgressBar.setMax(100);
    mProgressBar.setProgress(0);

    return rootView;
}
 
源代码6 项目: QSVideoPlayer   文件: QSVideoViewHelp.java
protected void initHelpView(Context context) {
    myOnClickListener = new MyOnClickListener();
    mHandler = new Handler(Looper.getMainLooper());
    handleTouchEvent = new HandleTouchEvent(this);
    audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);

    controlContainer = (ViewGroup) View.inflate(context, getLayoutId(), null);
    videoView.addView(controlContainer, new LayoutParams(-1, -1));
    videoView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return handleTouchEvent.handleEvent(v, event);
        }
    });

    titleTextView = (TextView) findViewById(R.id.help_title);
    startButton = (ImageView) findViewById(R.id.help_start);
    startButton2 = (ImageView) findViewById(R.id.help_start2);
    fullscreenButton = (ImageView) findViewById(R.id.help_fullscreen);
    seekBar = (SeekBar) findViewById(R.id.help_seekbar);
    progressBar = (ProgressBar) findViewById(R.id.help_progress);
    currentTimeTextView = (TextView) findViewById(R.id.help_current);
    totalTimeTextView = (TextView) findViewById(R.id.help_total);
    backView = findViewById(R.id.help_back);
    floatCloseView = findViewById(R.id.help_float_close);
    floatBackView = findViewById(R.id.help_float_goback);
    definitionTextView = findViewById(R.id.help_definition);
    if (seekBar != null) {
        seekBar.setOnSeekBarChangeListener(this);
        seekBar.setMax(progressMax);
    }
    if (progressBar != null)
        progressBar.setMax(progressMax);
    setClick(videoView, startButton, startButton2, fullscreenButton, backView, floatCloseView, floatBackView, definitionTextView);

}
 
源代码7 项目: likequanmintv   文件: ViewHolder.java
public ViewHolder setProgress(int viewId, int progress, int max)
{
    ProgressBar view = getView(viewId);
    view.setMax(max);
    view.setProgress(progress);
    return this;
}
 
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_vector_layer_cache, container, false);
    if (mVectorLayer == null)
        return v;

    final ProgressBar rebuildCacheProgress = v.findViewById(R.id.rebuildCacheProgressBar);
    final Button buildCacheButton = v.findViewById(R.id.rebuild_cache);
    buildCacheButton.setOnClickListener((View.OnClickListener) getActivity());
    final ImageButton cancelBuildCacheButton = v.findViewById(R.id.cancelBuildCacheButton);
    cancelBuildCacheButton.setOnClickListener((View.OnClickListener) getActivity());
    final View progressView = v.findViewById(R.id.rebuild_progress);

    mRebuildCacheReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            int max = intent.getIntExtra(RebuildCacheService.KEY_MAX, 0);
            int progress = intent.getIntExtra(RebuildCacheService.KEY_PROGRESS, 0);
            int layer = intent.getIntExtra(ConstantsUI.KEY_LAYER_ID, NOT_FOUND);

            if (layer == mVectorLayer.getId()) {
                rebuildCacheProgress.setMax(max);
                rebuildCacheProgress.setProgress(progress);
            }

            if (progress == 0) {
                buildCacheButton.setEnabled(true);
                progressView.setVisibility(View.GONE);
            } else {
                buildCacheButton.setEnabled(false);
                progressView.setVisibility(View.VISIBLE);
            }

            mActivity.onFeaturesCountChanged();
        }
    };

    return v;
}
 
源代码9 项目: MultiMediaSample   文件: TakeVideoActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    //全屏
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);   //应用运行时,保持屏幕高亮,不锁屏
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_take_video);

    //获取控件
    surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
    recordButton = (Button) findViewById(R.id.btn_start_record);
    unRecordButton = (Button) findViewById(R.id.btn_stop_record);
    previewButton = (Button) findViewById(R.id.btn_preview);
    recordButton.setOnClickListener(this);
    unRecordButton.setOnClickListener(this);
    previewButton.setOnClickListener(this);

    timeSecondView = (TextView) findViewById(R.id.time);
    curTimeView = (TextView) findViewById(R.id.tv_time);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressBar.setMax(MaxDuring);

    SurfaceHolder holder = surfaceView.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    startTime();

    //获取支持480p视频
    initSupportProfile();
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    //保持预览和视频长宽比一致,不拉伸压缩失真
    surfaceView.setLayoutParams(new FrameLayout.LayoutParams(-1, mVideoHeiht * dm.widthPixels / mVideoWidth, Gravity.TOP));

    fileCachePath = getIntent().getStringExtra("fileCachePath");
}
 
源代码10 项目: OpenEyes   文件: ViewHolder.java
/**
 * 设置进度条
 * @param viewId
 * @param progress
 * @param max
 * @return
 */
public ViewHolder setProgress(int viewId, int progress, int max)
{
    ProgressBar view = getView(viewId);
    view.setMax(max);
    view.setProgress(progress);
    return this;
}
 
@Override
protected View realGetView(int position, View convertView, ViewGroup parent)
{
	if (convertView == null)
	{
		convertView = getLayoutInflater().inflate(R.layout.wrapper_user_grade_list_item, parent, false);
	}

	ImageView iv_level_icon = ViewUtils.get(convertView, R.id.iv_level_icon);
	TextView tv_grade_name = ViewUtils.get(convertView, R.id.tv_grade_name);
	TextView tv_point_range = ViewUtils.get(convertView, R.id.tv_point_range);
	ProgressBar pb_exp = ViewUtils.get(convertView, R.id.pb_exp);

	Grade grade = realGetItem(position);
	String range_string = getString(R.string.grade_exp_range, grade.getOffset(), grade.getEnd());
	int level_icon = getResources().getIdentifier("level_" + (++position), "drawable", this.getPackageName());
	iv_level_icon.setImageResource(level_icon);

	tv_grade_name.setText(grade.getGradeName());
	tv_point_range.setText(range_string);

	if (mCurrentExp >= grade.getOffset() && mCurrentExp <= grade.getEnd())
	{
		pb_exp.setVisibility(View.VISIBLE);
		pb_exp.setMax(grade.getEnd() - grade.getOffset());
		pb_exp.setProgress(mCurrentExp - grade.getOffset());

		tv_grade_name.getPaint().setFakeBoldText(true);
	}
	else
	{
		pb_exp.setVisibility(View.GONE);

		tv_grade_name.getPaint().setFakeBoldText(false);
	}
		
	
	// ImageView iv_selected_flag = ViewUtils.get(convertView, R.id.iv_selected_flag);
	// if (grade.getGradeName().equalsIgnoreCase(mCurrentGrade))
	// {
	// iv_selected_flag.setVisibility(View.VISIBLE);
	// }
	// else
	// {
	// iv_selected_flag.setVisibility(View.GONE);
	// }

	return convertView;
}
 
@Nullable
@Override
public View onCreateView(
    LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.dialog_export_options, container, false);
  relativeTime = (CheckBox) view.findViewById(R.id.export_relative_time);
  progressBar = (ProgressBar) view.findViewById(R.id.progress);
  progressBar.setMax(100);
  view.findViewById(R.id.action_cancel)
      .setOnClickListener(
          v -> {
            // TODO: could cancel the export action here: requires saving references in
            // ExportService.
            dismiss();
          });
  AppAccount appAccount =
      WhistlePunkApplication.getAccount(getContext(), getArguments(), KEY_ACCOUNT_KEY);
  final String experimentId = getArguments().getString(KEY_EXPERIMENT_ID);
  // onCreateView is called before onStart so we need to grab these values for onCreateView
  final String trialId = getArguments().getString(KEY_TRIAL_ID);
  final boolean saveLocally = getArguments().getBoolean(KEY_SAVE_LOCALLY);
  DataService.bind(getActivity())
      .map(
          appSingleton -> {
            return appSingleton.getDataController(appAccount);
          })
      .flatMap(dc -> RxDataController.getExperimentById(dc, experimentId))
      .subscribe(
          experiment -> {
            Trial trial = experiment.getTrial(trialId);
            sensorIds = trial.getSensorIds();
            // TODO: fill in UI with these sensors.
          },
          error -> {
            if (Log.isLoggable(TAG, Log.ERROR)) {
              Log.e(TAG, "Unable to bind DataService in ExportOptionsDialogFragment", error);
            }
            throw new IllegalStateException(
                "Unable to bind DataService in ExportOptionsDialogFragment", error);
          });
  exportButton = (Button) view.findViewById(R.id.action_export);
  if (saveLocally) {
    TextView title = (TextView) view.findViewById(R.id.export_title);
    title.setText(R.string.download_options_title);
    exportButton.setText(R.string.download_copy_action);
  }
  exportButton.setOnClickListener(
      v -> {
        ExportService.exportTrial(
            getActivity(),
            appAccount,
            experimentId,
            trialId,
            relativeTime.isChecked(),
            saveLocally,
            sensorIds.toArray(new String[] {}));
      });

  return view;
}
 
public RecyclerViewHolder setProgress(int viewId, int progress, int max) {
    ProgressBar view = findViewById(viewId);
    view.setMax(max);
    view.setProgress(progress);
    return this;
}
 
源代码14 项目: SmartChart   文件: ViewHolder.java
public ViewHolder setMax(int viewId, int max) {
    ProgressBar view = getView(viewId);
    view.setMax(max);
    return this;
}
 
源代码15 项目: ClockView   文件: DownloadActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_download);
    down = (TextView) findViewById(R.id.down);
    progress = (TextView) findViewById(R.id.progress);
    file_name = (TextView) findViewById(R.id.file_name);
    pb_update = (ProgressBar) findViewById(R.id.pb_update);
    down.setOnClickListener(this);
    downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    request = new DownloadManager.Request(Uri.parse(downloadUrl));

    request.setTitle("测试apk包");
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    request.setAllowedOverRoaming(false);
    request.setMimeType("application/vnd.android.package-archive");
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    //创建目录
    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdir() ;

    //设置文件存放路径
    request.setDestinationInExternalPublicDir(  Environment.DIRECTORY_DOWNLOADS  , "app-release.apk" ) ;
    pb_update.setMax(100);
   final  DownloadManager.Query query = new DownloadManager.Query();
    timer = new Timer();
    task = new TimerTask() {
        @Override
        public void run() {
            Cursor cursor = downloadManager.query(query.setFilterById(id));
            if (cursor != null && cursor.moveToFirst()) {
                if (cursor.getInt(
                        cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) {
                    pb_update.setProgress(100);
                    install(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/app-release.apk" );
                    task.cancel();
                }
                String title = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE));
                String address = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                int bytes_downloaded = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
                int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
                int pro =  (bytes_downloaded * 100) / bytes_total;
                Message msg =Message.obtain();
                Bundle bundle = new Bundle();
                bundle.putInt("pro",pro);
                bundle.putString("name",title);
                msg.setData(bundle);
                handler.sendMessage(msg);
            }
            cursor.close();
        }
    };
    timer.schedule(task, 0,1000*3);
}
 
源代码16 项目: Gallery   文件: BaseAdapterHelper.java
public BaseAdapterHelper setMax(int viewId, int max) {
    ProgressBar view = retrieveView(viewId);
    view.setMax(max);
    return this;
}
 
@Override
protected void onPostExecute(PasswordStrengthResult result) {

    if (result == null) return;

    try {
        Drawable ledGreen = ContextCompat.getDrawable(mContext, R.drawable.led_green);
        Drawable ledRed   = ContextCompat.getDrawable(mContext, R.drawable.led_red);
        TextView txtPasswordStrength = mPassStrengthLayout.findViewById(R.id.txtPasswordStrength);
        TextView txtPasswordWarning = mPassStrengthLayout.findViewById(R.id.txtPasswordWarning);
        ImageView imgUppercase = mPassStrengthLayout.findViewById(R.id.imgPasswordContainsUppercase);
        ImageView imgLowercase = mPassStrengthLayout.findViewById(R.id.imgPasswordContainsLowercase);
        ImageView imgDigits = mPassStrengthLayout.findViewById(R.id.imgPasswordContainsDigits);
        ImageView imgSymbols = mPassStrengthLayout.findViewById(R.id.imgSymbols);
        ProgressBar progressPwStrength = mPassStrengthLayout.findViewById(R.id.progressPasswordStrength);

        progressPwStrength.setMax(STRENGTH_POINTS_MIN_GOOD);
        progressPwStrength.setProgress(result.strengthPoints);

        if (result.rating == PasswordRating.POOR) {
            txtPasswordStrength.setText(mContext.getText(R.string.password_strength_poor));
            txtPasswordStrength.setBackgroundColor(
                    ContextCompat.getColor(mContext, R.color.password_strength_poor));
        } else if (result.rating == PasswordRating.MEDIUM) {
            txtPasswordStrength.setText(mContext.getText(R.string.password_strength_medium));
            txtPasswordStrength.setBackgroundColor(
                    ContextCompat.getColor(mContext, R.color.password_strength_medium));
        } else if (result.rating == PasswordRating.GOOD) {
            txtPasswordStrength.setText(mContext.getText(R.string.password_strength_good));
            txtPasswordStrength.setBackgroundColor(
                    ContextCompat.getColor(mContext, R.color.password_strength_good));
        }

        imgLowercase.setImageDrawable(result.lowercaseUsed ? ledGreen : ledRed);
        imgUppercase.setImageDrawable(result.uppercaseUsed ? ledGreen : ledRed);
        imgDigits.setImageDrawable(result.digitsUsed ? ledGreen : ledRed);
        imgSymbols.setImageDrawable(result.symbolsUsed ? ledGreen : ledRed);

        if (result.passwordLength > 0 && result.passwordLength < PW_MIN_LENGTH) {
            txtPasswordWarning.setText(R.string.short_password_warning);
            txtPasswordWarning.setVisibility(View.VISIBLE);
        } else {
            txtPasswordWarning.setVisibility(View.GONE);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码18 项目: commcare-android   文件: FormNavigationUI.java
/**
 * Update progress bar's max and value, and the various buttons and navigation cues
 * associated with navigation
 */
public static void updateNavigationCues(CommCareActivity activity,
                                        FormController formController,
                                        QuestionsView view) {
    if (view == null) {
        return;
    }

    updateFloatingLabels(activity, view);

    FormNavigationController.NavigationDetails details;
    try {
        details = FormNavigationController.calculateNavigationStatus(formController, view);
    } catch (XPathException e) {
        UserfacingErrorHandling.logErrorAndShowDialog(activity, e, true);
        return;
    }

    ProgressBar progressBar = activity.findViewById(R.id.nav_prog_bar);

    ImageButton nextButton = activity.findViewById(R.id.nav_btn_next);
    ImageButton prevButton = activity.findViewById(R.id.nav_btn_prev);

    ClippingFrame finishButton = activity.
            findViewById(R.id.nav_btn_finish);

    if (!details.relevantBeforeCurrentScreen) {
        prevButton.setImageResource(R.drawable.icon_close_darkwarm);
        prevButton.setTag(FormEntryConstants.NAV_STATE_QUIT);
    } else {
        prevButton.setImageResource(R.drawable.icon_chevron_left_brand);
        prevButton.setTag(FormEntryConstants.NAV_STATE_BACK);
    }

    //Apparently in Android 2.3 setting the drawable resource for the progress bar
    //causes it to lose it bounds. It's a bit cheaper to keep them around than it
    //is to invalidate the view, though.
    Rect bounds = progressBar.getProgressDrawable().getBounds(); //Save the drawable bound

    Log.i("Questions", "Total questions: " + details.totalQuestions + " | Completed questions: " + details.completedQuestions);

    progressBar.setMax(details.totalQuestions);

    if (details.isFormDone()) {
        setDoneState(nextButton, activity, finishButton, details, progressBar);
    } else {
        setMoreQuestionsState(nextButton, activity, finishButton, details, progressBar);
    }

    progressBar.getProgressDrawable().setBounds(bounds);  //Set the bounds to the saved value
}
 
/**
 * Sets the progress and max of a ProgressBar.
 *
 * @param viewId   The view id.
 * @param progress The progress.
 * @param max      The max value of a ProgressBar.
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setProgress(int viewId, int progress, int max) {
    ProgressBar view = retrieveView(viewId);
    view.setMax(max);
    view.setProgress(progress);
    return this;
}
 
源代码20 项目: AndroidBase   文件: BaseAdapterHelper.java
/**
 * Sets the range of a ProgressBar to 0...max.
 *
 * @param viewId
 *            The view id.
 * @param max
 *            The max value of a ProgressBar.
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setMax(int viewId, int max) {
    ProgressBar view = retrieveView(viewId);
    view.setMax(max);
    return this;
}