Example usage for android.widget ProgressBar setProgress

List of usage examples for android.widget ProgressBar setProgress

Introduction

In this page you can find the example usage for android.widget ProgressBar setProgress.

Prototype

@android.view.RemotableViewMethod
public synchronized void setProgress(int progress) 

Source Link

Document

Sets the current progress to the specified value.

Usage

From source file:com.frostwire.android.gui.adapters.TransferListAdapter.java

private static void setProgress(ProgressBar v, int progress) {
    int old = v.getProgress();
    if (old != progress) {
        v.setProgress(progress);
    }/*from ww w  .j  a v  a 2 s  .  c  o  m*/
}

From source file:com.ae.apps.messagecounter.fragments.SentCountFragment.java

/**
 * Sets the progress value to a progressbar, with animation if the OS supports it
 * /*from  www  .ja v a  2  s .  co  m*/
 * @param progressBar
 * @param progress
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void setProgressWithAnimation(ProgressBar progressBar, int progress, long animDelay) {
    // We try to add animation for newer APIs here
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.animation.ObjectAnimator animation = android.animation.ObjectAnimator.ofInt(progressBar,
                PROGRESS_VALUE, 0, progress);
        animation.setDuration(100);
        animation.setStartDelay(animDelay);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.start();
    } else {
        progressBar.setProgress(progress);
    }
}

From source file:com.alibaba.akita.io.HttpInvoker.java

/**
 * Vversion 2 remoteimageview download impl, use byte[] to decode.
 * Note: Recommanded to use this method instead of version 1.
 * NUM_RETRIES retry./*from   w w w. j av  a 2 s.c  o m*/
 * @param imgUrl
 * @param httpReferer http Referer
 * @return
 * @throws AkServerStatusException
 * @throws AkInvokeException
 */
public static Bitmap getBitmapFromUrl(String imgUrl, String httpReferer, ProgressBar progressBar)
        throws AkServerStatusException, AkInvokeException {
    imgUrl = imgUrl.trim();
    Log.v(TAG, "getBitmapFromUrl:" + imgUrl);

    int timesTried = 1;

    while (timesTried <= NUM_RETRIES) {
        timesTried++;
        try {
            if (progressBar != null) {
                progressBar.setProgress(0);
            }
            HttpGet request = new HttpGet(imgUrl);
            if (httpReferer != null)
                request.addHeader("Referer", httpReferer);
            HttpResponse response = client.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED
                    || statusCode == HttpStatus.SC_ACCEPTED) {
                HttpEntity resEntity = response.getEntity();
                InputStream inputStream = resEntity.getContent();

                byte[] imgBytes = retrieveImageData(inputStream, (int) (resEntity.getContentLength()),
                        progressBar);
                if (imgBytes == null) {
                    SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME);
                    continue;
                }

                Bitmap bm = null;
                try {
                    bm = ImageUtil.decodeSampledBitmapFromByteArray(imgBytes, 0, imgBytes.length, 682, 682);
                } catch (OutOfMemoryError ooe) {
                    Log.e(TAG, ooe.toString(), ooe);
                    return null; // if oom, no need to retry.
                }
                if (bm == null) {
                    SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME);
                    continue;
                }
                return bm;
            } else {
                HttpEntity resEntity = response.getEntity();
                throw new AkServerStatusException(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(resEntity, CHARSET));
            }
        } catch (ClientProtocolException cpe) {
            Log.e(TAG, cpe.toString(), cpe);
            throw new AkInvokeException(AkInvokeException.CODE_HTTP_PROTOCOL_ERROR, cpe.toString(), cpe);
        } catch (IOException ioe) {
            Log.e(TAG, ioe.toString(), ioe);
            throw new AkInvokeException(AkInvokeException.CODE_CONNECTION_ERROR, ioe.toString(), ioe);
        } catch (IllegalStateException ise) {
            Log.e(TAG, ise.toString(), ise);
            throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, ise.toString(), ise);
        } catch (IllegalArgumentException iae) {
            throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, iae.toString(), iae);
        } catch (Exception e) {
            throw new AkInvokeException(AkInvokeException.CODE_UNKOWN_ERROR, e.toString(), e);
        }

    }

    return null;
}

From source file:de.uni_weimar.m18.anatomiederstadt.DownloadProgressFragment.java

public void setProgress(int percent) {
    //Log.v(LOG_TAG, "setting progress in DownloadProgressFragment");
    ProgressBar progressBar = (ProgressBar) getActivity().findViewById(R.id.progressBar);
    progressBar.setProgress(percent * progressBar.getMax() / 100);
    TextView textPercentage = (TextView) getActivity().findViewById(R.id.textPercentage);
    textPercentage.setText(Integer.toString(percent) + "%");
}

From source file:org.tomasdavid.vehicleroutingproblem.tasks.ProgressBarTask.java

/**
 * {@inheritDoc}/*  w w  w. j  a va  2 s  .c  om*/
 */
@Override
protected Void doInBackground(Integer... params) {

    // initialize progress bar
    progress = 0;
    ProgressBar progressBar = (ProgressBar) fragment.getActivity().findViewById(R.id.progress_bar);
    progressBar.setProgress(progress);

    // while solver task is running change progress every 1 second
    while (fragment.getVrpSolverTask().isRunning() && progress < progressBar.getMax()) {
        try {
            Thread.sleep(SECOND);
        } catch (InterruptedException e) {
            Log.e(TAG, "Thread sleep error.", e);
        }

        if (fragment != null) {
            FragmentActivity activity = fragment.getActivity();
            if (activity != null) {
                progressBar = (ProgressBar) activity.findViewById(R.id.progress_bar);
                if (progressBar != null) {
                    progressBar.incrementProgressBy(1);
                }
            }
        }
        progress++;
    }

    return null;
}

From source file:net.seedboxer.seedroid.activities.fragments.StatusFragment.java

private void renderDownload(Download item) {
    TextView label = (TextView) getView().findViewById(R.id.name);
    label.setText(item.getName());/*  w ww  . j a v a  2s  . c o  m*/

    ImageView icon = (ImageView) getView().findViewById(R.id.icon);
    if (item.getName().matches("S\\d\\dE\\d\\d")) {
        icon.setImageResource(R.drawable.tvshow_icon);
    } else {
        icon.setImageResource(R.drawable.movie_icon);
    }

    double progress = calculateProgress(item);
    ProgressBar bar = (ProgressBar) getView().findViewById(R.id.progressbar);
    bar.setProgress((int) progress);

    TextView percentage = (TextView) getView().findViewById(R.id.percentage);
    percentage.setText(round(progress, 1) + "%");

    TextView total = (TextView) getView().findViewById(R.id.total);
    total.setText(item.getTransferred() + "/" + item.getSize() + " MB");

    View layout = getView().findViewById(R.id.relative_layout);
    layout.setVisibility(LinearLayout.VISIBLE);
    View layoutNoDownloads = getView().findViewById(R.id.relative_layout_no_download);
    layoutNoDownloads.setVisibility(LinearLayout.GONE);
}

From source file:org.peterbaldwin.vlcremote.widget.TvShowsAdapter.java

private View populateShow(View convertView, Show show) {
    if (convertView == null || !convertView.getTag().equals("show")) {
        convertView = mInflater.inflate(R.layout.shows_list_item, null);
    }//from www. j a v a 2s .  c o  m
    TextView tv = (TextView) convertView.findViewById(R.id.show_name);
    tv.setText(show.getTitle());

    ProgressBar pb = (ProgressBar) convertView.findViewById(R.id.show_progress);
    pb.setProgress(show.getProgress());
    pb.setMax(show.getTotal());
    convertView.setTag("show");
    return convertView;
}

From source file:org.peterbaldwin.vlcremote.widget.TvShowsAdapter.java

private View populateSeason(View convertView, Season season) {
    if (convertView == null || !convertView.getTag().equals("season")) {
        convertView = mInflater.inflate(R.layout.seasons_list_item, null);
    }//from   www.  ja va2s  .c  o m

    TextView tv = (TextView) convertView.findViewById(R.id.season_num);
    tv.setText("S" + season.getNum());

    ProgressBar pb = (ProgressBar) convertView.findViewById(R.id.season_progress);
    pb.setProgress(season.getProgress());
    pb.setMax(season.getTotal());
    convertView.setTag("season");
    return convertView;
}

From source file:org.getlantern.firetweet.util.ImageLoadingHandler.java

@Override
public void onProgressUpdate(final String imageUri, final View view, final int current, final int total) {
    if (total == 0 || view == null)
        return;//from  w  w  w  .java  2  s  . c  o  m
    final ProgressBar progress = findProgressBar(view.getParent());
    if (progress != null) {
        progress.setIndeterminate(false);
        progress.setProgress(100 * current / total);
    }
}

From source file:com.inovex.zabbixmobile.activities.fragments.BaseSeverityFilterListFragment.java

/**
 * Updates the progress of the progress bar.
 * /*  w  ww  .j a v a2  s  .c  o  m*/
 * @param progress
 *            current progress
 */
public void updateProgress(int progress) {
    if (getView() != null) {
        ProgressBar listProgress = (ProgressBar) getView().findViewById(R.id.severity_list_progress);
        listProgress.setProgress(progress);
    }
}