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.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java

/**
 * Make sure that selection-event elimination does not get rid of progress bar VIEW_SELECTED
 * events./*from  ww w . ja  v  a 2 s  . c om*/
 */
@MediumTest
public void testProgressBarSelectedEvents() {
    final ProgressBar progressBar = (ProgressBar) getViewForId(R.id.progress_bar);
    final AccessibilityNodeInfoCompat progressBarNode = getNodeForView(progressBar);

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_SELECTED;
    mMatchNode = AccessibilityNodeInfoCompat.obtain(progressBarNode);

    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            progressBar.requestFocus();
            progressBar.setProgress(25);
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    assertTrue(mMatched);
}

From source file:mx.klozz.xperience.tweaker.fragments.DiskInfo.java

public Boolean set_part_info(String part, String titlu, TextView t1, TextView t2, TextView t3, TextView t4,
        ProgressBar b, RelativeLayout l) {
    if (new File(part).exists()) {
        final long v1 = Totalbytes(new File(part));
        if (v1 > 0) {
            t1.setText(titlu);/*from w w  w. ja  va 2 s .  c  om*/
            t2.setText(Helpers.ReadableByteCount(v1));

            final long v2 = Freebytes(new File(part));
            t4.setText(getString(R.string.free, Helpers.ReadableByteCount(v2)));
            t3.setText(getString(R.string.used, Helpers.ReadableByteCount(v1 - v2)));
            b.setProgress(Math.round(((v1 - v2) * 100) / v1));

            l.setVisibility(RelativeLayout.VISIBLE);
            return true;
        } else {
            l.setVisibility(RelativeLayout.GONE);
            return false;
        }
    } else {
        l.setVisibility(RelativeLayout.GONE);
        return false;
    }
}

From source file:com.textuality.lifesaver.Restorer.java

private int restore(BufferedReader file, HashMap<String, Boolean> logged, Columns r, Uri uri,
        ProgressBar progress, String zeroField, int total) throws Exception {
    int added = 0;
    ContentResolver cr = getContentResolver();
    int count = 0;
    String line;//www  .  j a v  a2  s .co  m
    float denominator = ((float) total) / 100.0F;
    while ((line = file.readLine()) != null) {
        JSONObject json = new JSONObject(line);
        String key = r.jsonToKey(json);
        if (logged.get(key) == null) {
            ContentValues cv = r.jsonToContentValues(json);
            if (zeroField != null)
                cv.put(zeroField, 0);
            cr.insert(uri, cv);
            added++;
        }
        count += 1;
        progress.setProgress((int) (count / denominator));
    }
    file.close();
    return added;
}

From source file:org.kegbot.app.HomeActivity.java

@Subscribe
public void onVisibleTapListUpdate(VisibleTapsChangedEvent event) {
    assert (Looper.myLooper() == Looper.getMainLooper());
    Log.d(LOG_TAG, "Got tap list change event: " + event + " taps=" + event.getTaps().size());

    final List<KegTap> newTapList = event.getTaps();
    synchronized (mTapsLock) {
        if (newTapList.equals(mTaps)) {
            Log.d(LOG_TAG, "Tap list unchanged.");
            return;
        }// w  w w  .j ava 2s .  c  o  m

        mTaps.clear();
        mTaps.addAll(newTapList);
        mTapStatusAdapter.notifyDataSetChanged();
    }

    //for progress bar
    if (mTaps.size() > 0) {
        final KegTap tap = mTaps.get(mTapStatusPager.getCurrentItem());
        if (tap.hasCurrentKeg()) {
            final Models.Keg keg = tap.getCurrentKeg();
            double remainml = keg.getRemainingVolumeMl();
            double totalml = keg.getFullVolumeMl();
            double percent = (remainml) / (totalml) * 100;

            final ProgressBar mTapProgress = (ProgressBar) findViewById(R.id.tapProgress);
            mTapProgress.setMax((int) totalml);
            mTapProgress.setProgress((int) remainml);

            final TextView mTapPercentage = (TextView) findViewById(R.id.tapPercentage);
            mTapPercentage.setText(String.format("%.2f", percent) + "%");
        }
    }

    maybeShowTapWarnings();
}

From source file:io.github.hidroh.materialistic.OfflineWebActivity.java

@SuppressWarnings("ConstantConditions")
@Override//from   w w w .j a v a2 s.c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String url = getIntent().getStringExtra(EXTRA_URL);
    if (TextUtils.isEmpty(url)) {
        finish();
        return;
    }
    setTitle(url);
    setContentView(R.layout.activity_offline_web);
    final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.nested_scroll_view);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setOnClickListener(v -> scrollView.smoothScrollTo(0, 0));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setSubtitle(R.string.offline);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
    final WebView webView = (WebView) findViewById(R.id.web_view);
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(this)) {
        @Override
        public void onPageFinished(WebView view, String url) {
            setTitle(view.getTitle());
        }
    });
    webView.setWebChromeClient(new CacheableWebView.ArchiveClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
                webView.setBackgroundColor(Color.WHITE);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    AppUtils.toggleWebViewZoom(webView.getSettings(), true);
    webView.loadUrl(url);
}

From source file:in.ac.dtu.subtlenews.InstapaperViewer.java

@SuppressLint("NewApi")
@Override//w w w .  ja va  2 s.  c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setImmersive(true);
    }
    setTheme(R.style.AppTheme_NoActionBar);

    setContentView(R.layout.activity_instapaper_viewer);
    //setupActionBar();

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        urlId = extras.getInt("URLID");
        urlList = extras.getStringArrayList("URLList");

    }
    final WebView instapaperView = (WebView) findViewById(R.id.instapaper_viewer);
    final Activity activity = this;
    final ProgressBar progressBar;
    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    instapaperView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if (progress < 100 && progressBar.getVisibility() == ProgressBar.GONE) {
                progressBar.setVisibility(ProgressBar.VISIBLE);
                //txtview.setVisibility(View.VISIBLE);
            }
            progressBar.setProgress(progress);
            if (progress == 100) {
                progressBar.setVisibility(ProgressBar.GONE);
                //txtview.setVisibility(View.GONE);
            }
        }
    });

    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    final View contentView = findViewById(R.id.instapaper_viewer);

    final Button prevButton = (Button) findViewById(R.id.summary_prev_button);
    final Button nextButton = (Button) findViewById(R.id.summary_next_button);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
        // Cached values.
        int mControlsHeight;
        int mShortAnimTime;

        @Override
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
        public void onVisibilityChange(boolean visible) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                // If the ViewPropertyAnimator API is available
                // (Honeycomb MR2 and later), use it to animate the
                // in-layout UI controls at the bottom of the
                // screen.
                if (mControlsHeight == 0) {
                    mControlsHeight = controlsView.getHeight();
                }
                if (mShortAnimTime == 0) {
                    mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
                }
                controlsView.animate().translationY(visible ? 0 : mControlsHeight).setDuration(mShortAnimTime);
            } else {
                // If the ViewPropertyAnimator APIs aren't
                // available, simply show or hide the in-layout UI
                // controls.
                controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
            }

            if (visible && AUTO_HIDE) {
                // Schedule a hide().
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }

        }
    });

    // Set up the user interaction to manually show or hide the system UI.
    contentView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TOGGLE_ON_CLICK) {
                mSystemUiHider.toggle();
            } else {
                mSystemUiHider.show();
            }
        }
    });

    // Upon interacting with UI controls, delay any scheduled hide()
    // operations to prevent the jarring behavior of controls going away
    // while interacting with the UI.
    prevButton.setOnTouchListener(mDelayHideTouchListener);
    nextButton.setOnTouchListener(mDelayHideTouchListener);

    try {
        summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(urlId);
    } catch (Exception e) {
        e.printStackTrace();
    }

    instapaperView.loadUrl(summaryUrl);
    prevButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(--urlId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            instapaperView.loadUrl(summaryUrl);
        }
    });
    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(++urlId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            instapaperView.loadUrl(summaryUrl);
        }
    });

}

From source file:com.amaze.filemanager.fragments.ProcessViewer.java

void processCompressResults(DataPackage dataPackage) {
    final int id = dataPackage.getId();

    if (!CancelledZipIds.contains(id)) {
        if (ZipIds.contains(id)) {
            boolean completed = dataPackage.isCompleted();
            View process = rootView.findViewWithTag("zip" + id);
            if (completed) {
                rootView.removeViewInLayout(process);
                ZipIds.remove(ZipIds.indexOf(id));
            } else {
                String name = dataPackage.getName();
                int p1 = dataPackage.getP1();

                ProgressBar p = (ProgressBar) process.findViewById(R.id.progressBar1);
                if (p1 <= 100) {
                    ((TextView) process.findViewById(R.id.progressText)).setText(
                            utils.getString(getActivity(), R.string.zipping) + "\n" + name + "\n" + p1 + "%");

                    p.setProgress(p1);
                }/* w w w  . ja va  2 s. c om*/
            }
        } else {
            CardView root = (CardView) getActivity().getLayoutInflater().inflate(R.layout.processrow, null);
            root.setTag("zip" + id);

            ImageView progressImage = ((ImageView) root.findViewById(R.id.progressImage));
            ImageButton cancel = (ImageButton) root.findViewById(R.id.delete_button);
            TextView progressText = (TextView) root.findViewById(R.id.progressText);

            if (mainActivity.theme1 == 1) {

                root.setCardBackgroundColor(R.color.cardView_foreground);
                root.setCardElevation(0f);
                cancel.setImageResource(R.drawable.ic_action_cancel);
                progressText.setTextColor(Color.WHITE);
                progressImage.setImageResource(R.drawable.ic_doc_compressed);
            } else {

                // cancel has default src set for light theme
                progressText.setTextColor(Color.BLACK);
                progressImage.setImageResource(R.drawable.ic_doc_compressed_black);
            }

            cancel.setOnClickListener(new View.OnClickListener() {

                public void onClick(View p1) {
                    Toast.makeText(getActivity(), utils.getString(getActivity(), R.string.stopping),
                            Toast.LENGTH_LONG).show();
                    Intent i = new Intent("zipcancel");
                    i.putExtra("id", id);
                    getActivity().sendBroadcast(i);
                    rootView.removeView(rootView.findViewWithTag("zip" + id));

                    ZipIds.remove(ZipIds.indexOf(id));
                    CancelledZipIds.add(id);
                    // TODO: Implement this method
                }
            });

            String name = dataPackage.getName();
            int p1 = dataPackage.getP1();

            ((TextView) root.findViewById(R.id.progressText))
                    .setText(utils.getString(getActivity(), R.string.zipping) + "\n" + name);
            ProgressBar p = (ProgressBar) root.findViewById(R.id.progressBar1);
            p.setProgress(p1);

            ZipIds.add(id);
            rootView.addView(root);
        }
    }
}

From source file:io.github.carlorodriguez.morningritual.MainActivity.java

private void stopMorningRitual(final ProgressBar progressBar, final TextView title, final TextView quote,
        final MorningRitual morningRitual, final FloatingActionButton fab) {
    mAnimator.removeAllListeners();/*from w  w  w. j  a v  a 2 s.c  o m*/

    mAnimator.cancel();

    morningRitual.stop();

    title.setText(getString(R.string.gratitude_title));

    quote.setText(getString(R.string.gratitude_quote));

    progressBar.setProgress(0);

    fab.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_fab_play));
}

From source file:org.kegbot.app.HomeActivity.java

@Override
protected void onStart() {
    super.onStart();
    mCore = KegbotCore.getInstance(this);
    mConfig = mCore.getConfiguration();//w  w w  . j a va  2s  . c om
    maybeShowTapWarnings();

    //for dummy pour status
    final Pair<String, String> qty = Units.localizeWithoutScaling(mCore.getConfiguration(), 0.0);
    mPourVolumeBadge.setBadgeValue(qty.first);
    mPourVolumeBadge.setBadgeCaption("Current " + Units.capitalizeUnits(qty.second) + " Poured");

    mImageView0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ActionBar actionBar = getActionBar();
            if (actionBar.isShowing()) {
                actionBar.hide();
                mConfig.setShowActionBar(false);
            } else {
                actionBar.show();
                mConfig.setShowActionBar(true);
            }
        }
    });

    //for start button
    final Context thisContext = this;
    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mConfig.useAccounts()) {
                final Intent intent = KegtabCommon.getAuthDrinkerActivityIntent(thisContext);
                startActivityForResult(intent, REQUEST_AUTHENTICATE);
            } else {
                mCore.getFlowManager().activateUserAmbiguousTap("");
            }

        }
    });

    mNewDrinkerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Intent intent = KegtabCommon.getCreateDrinkerActivityIntent(thisContext);
            startActivityForResult(intent, REQUEST_CREATE_DRINKER);
        }
    });

    mTapStatusPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

            //for progress bar
            if (mTaps.size() > 0) {
                final KegTap tap = mTaps.get(position);
                if (tap.hasCurrentKeg()) {
                    final Models.Keg keg = tap.getCurrentKeg();
                    double remainml = keg.getRemainingVolumeMl();
                    double totalml = keg.getFullVolumeMl();
                    double percent = (remainml) / (totalml) * 100;

                    final ProgressBar mTapProgress = (ProgressBar) findViewById(R.id.tapProgress);
                    mTapProgress.setMax((int) totalml);
                    mTapProgress.setProgress((int) remainml);

                    final TextView mTapPercentage = (TextView) findViewById(R.id.tapPercentage);
                    mTapPercentage.setText(String.format("%.2f", percent) + "%");
                }
            }

            //for backgrounds
            switch (position) {
            case 0:
                mImageView0.setImageResource(R.drawable.e1);
                mImageView1.setBackgroundResource(R.drawable.e2);
                break;
            case 1:
                mImageView0.setImageResource(R.drawable.a1);
                mImageView1.setBackgroundResource(R.drawable.a2);
                break;
            case 2:
                mImageView0.setImageResource(R.drawable.b1);
                mImageView1.setBackgroundResource(R.drawable.b2);
                break;
            case 3:
                mImageView0.setImageResource(R.drawable.c1);
                mImageView1.setBackgroundResource(R.drawable.c2);
                break;
            case 4:
                mImageView0.setImageResource(R.drawable.d1);
                mImageView1.setBackgroundResource(R.drawable.d2);
                break;
            default:
                mImageView0.setImageResource(R.drawable.e1);
                mImageView1.setBackgroundResource(R.drawable.e2);
                break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
}

From source file:org.xbmc.kore.ui.sections.video.TVShowProgressFragment.java

/**
 * Display the seasons list/* w  w w .  j ava 2s .c  o m*/
 *
 * @param cursor Cursor with the data
 */
private void displaySeasonList(Cursor cursor) {
    TextView seasonsListTitle = (TextView) getActivity().findViewById(R.id.seasons_title);
    GridLayout seasonsList = (GridLayout) getActivity().findViewById(R.id.seasons_list);

    if (cursor.moveToFirst()) {
        seasonsListTitle.setVisibility(View.VISIBLE);
        seasonsList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener seasonListClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onSeasonSelected(itemId, (int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.seasonlist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.seasonlist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        // Get theme colors
        Resources.Theme theme = getActivity().getTheme();
        TypedArray styledAttributes = theme
                .obtainStyledAttributes(new int[] { R.attr.colorinProgress, R.attr.colorFinished });

        int inProgressColor = styledAttributes.getColor(styledAttributes.getIndex(0),
                resources.getColor(R.color.orange_500));
        int finishedColor = styledAttributes.getColor(styledAttributes.getIndex(1),
                resources.getColor(R.color.green_400));
        styledAttributes.recycle();

        seasonsList.removeAllViews();
        do {
            int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON);
            String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL);
            int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE);
            int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);

            View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList,
                    false);

            ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art);
            TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season);
            TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes);
            ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar);

            seasonNumberView
                    .setText(String.format(getActivity().getString(R.string.season_number), seasonNumber));
            seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes),
                    numEpisodes, numEpisodes - watchedEpisodes));
            seasonProgressBar.setMax(numEpisodes);
            seasonProgressBar.setProgress(watchedEpisodes);

            if (Utils.isLollipopOrLater()) {
                int watchedColor = (numEpisodes - watchedEpisodes == 0) ? finishedColor : inProgressColor;
                seasonProgressBar.setProgressTintList(ColorStateList.valueOf(watchedColor));
            }

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail,
                    String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight);

            seasonView.setTag(seasonNumber);
            seasonView.setOnClickListener(seasonListClickListener);
            seasonsList.addView(seasonView);
        } while (cursor.moveToNext());
    } else {
        // No seasons, hide views
        seasonsListTitle.setVisibility(View.GONE);
        seasonsList.setVisibility(View.GONE);
    }
}