Java Code Examples for android.widget.ProgressBar#setTag()

The following examples show how to use android.widget.ProgressBar#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProgressUtil.java    From okdownload with Apache License 2.0 6 votes vote down vote up
public static void calcProgressToViewAndMark(ProgressBar bar, long offset, long total,
                                             boolean anim) {
    final int contentLengthOnInt = reducePrecision(total);
    final int shrinkRate = contentLengthOnInt == 0
            ? 1 : (int) (total / contentLengthOnInt);
    bar.setTag(shrinkRate);
    final int progress = (int) (offset / shrinkRate);


    bar.setMax(contentLengthOnInt);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        bar.setProgress(progress, anim);
    } else {
        bar.setProgress(progress);
    }
}
 
Example 2
Source File: ProgressLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressLayout);
    int backgroundColor = a.getColor(R.styleable.ProgressLayout_progressLayoutProgressBackground, Color.TRANSPARENT);
    boolean startFromProgress = a.getBoolean(R.styleable.ProgressLayout_progressLayoutProgress, false);
    a.recycle();

    LayoutParams layoutParams;

    // if progressBackground color == Color.TRANSPARENT just add progress bar
    if (backgroundColor == Color.TRANSPARENT) {
        mProgressView = new ProgressBar(getContext());

        layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(CENTER_IN_PARENT);
    } else { // else wrap progress bar in LinearLayout and set background color to LinearLayout
        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setGravity(Gravity.CENTER);
        linearLayout.setBackgroundColor(backgroundColor);

        layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        ProgressBar progressBar = new ProgressBar(getContext());
        linearLayout.addView(progressBar);

        mProgressView = linearLayout;
    }

    mProgressView.setTag(TAG_PROGRESS);
    if (!startFromProgress) {
        mProgressView.setVisibility(View.GONE);
    }
    addView(mProgressView, layoutParams);
}
 
Example 3
Source File: VideoListActivity.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void prepare(View view, Param param, int immediatePassHint) {
	super.prepare(view, param, immediatePassHint);
	
	Cursor cursor = (Cursor) mAdapter.getItem(param.cursorPosition);
	
	if (!prepared) {
		titleColumn = cursor.getColumnIndex("title");
		watchedColumn = cursor.getColumnIndex("seconds_watched");
		completedColumn = cursor.getColumnIndex("completed");
		prepared = true;
	}
	
	String title = cursor.getString(titleColumn);
	
	TextView titleView = (TextView) view.findViewById(R.id.list_video_title);
	ImageView iconView = (ImageView) view.findViewById(R.id.complete_icon);
	ProgressBar bar = (ProgressBar) view.findViewById(R.id.list_video_dl_progress);
	String youtubeId = param.youtubeId;
	bar.setTag(youtubeId);
	updateBar(bar);
	
	// User view completion icon.
	int watched = 0;
	boolean complete = false;
	try {
		watched = cursor.getInt(watchedColumn);
		complete = cursor.getInt(completedColumn) != 0;
	} catch (Exception e) {
		// Swallow. This will be due to null values not making their way through getInt in some implementations.
	}
	int resId = complete
			? R.drawable.video_indicator_complete
			: watched > 0
			? R.drawable.video_indicator_started
			: R.drawable.empty_icon;
			
	iconView.setImageResource(resId);
	titleView.setText(title);
}
 
Example 4
Source File: ManageDownloadsActivity.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void prepare(View view, Param param, int immediatePassHint) {
	super.prepare(view, param, immediatePassHint);
	
	Cursor cursor = (Cursor) mAdapter.getItem(param.cursorPosition);
	
	if (!prepared) {
		titleColumn = cursor.getColumnIndex("title");
		watchedColumn = cursor.getColumnIndex("seconds_watched");
		completedColumn = cursor.getColumnIndex("completed");
		prepared = true;
	}
	
	String title = cursor.getString(titleColumn);
	
	TextView titleView = (TextView) view.findViewById(R.id.list_video_title);
	ImageView iconView = (ImageView) view.findViewById(R.id.complete_icon);
	ProgressBar bar = (ProgressBar) view.findViewById(R.id.list_video_dl_progress);
	bar.setTag(param.youtubeId);
	updateBar(bar);
	
	// User view completion icon.
	int watched = 0;
	boolean complete = false;
	try {
		watched = cursor.getInt(watchedColumn);
		complete = cursor.getInt(completedColumn) != 0;
	} catch (Exception e) {
		// Swallow. This will be due to null values not making their way through getInt in some implementations.
	}
	int resId = complete
			? R.drawable.video_indicator_complete
			: watched > 0
			? R.drawable.video_indicator_started
			: R.drawable.empty_icon;
			
	iconView.setImageResource(resId);
	titleView.setText(title);
}