Example usage for android.widget ProgressBar setSecondaryProgress

List of usage examples for android.widget ProgressBar setSecondaryProgress

Introduction

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

Prototype

@android.view.RemotableViewMethod
public synchronized void setSecondaryProgress(int secondaryProgress) 

Source Link

Document

Set the current secondary progress to the specified value.

Usage

From source file:com.restswitch.controlpanel.MainActivity.java

public void setProgressBars(String pb1Text, int pb1Pos, String pb2Text, int pb2Pos) {
    ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar);
    pb.setProgress(pb1Pos);/*w w w.j ava  2s.c  o m*/
    pb.setSecondaryProgress(pb2Pos);

    TextView tv1 = (TextView) findViewById(R.id.progressBarText);
    tv1.setText(pb1Text);

    TextView tv2 = (TextView) findViewById(R.id.secondaryProgressBarText);
    tv2.setText(pb2Text);

    int pbwTot = pb.getWidth();
    int pbw1 = ((pbwTot * pb1Pos) / 100);
    tv1.setWidth(pbw1);

    pbw1 += 96;
    int pbw2 = (pbwTot - pbw1);
    ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) tv2.getLayoutParams();
    mlp.setMargins(pbw1, 2, 0, 0);
    tv2.setWidth(pbw2);
}

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

public void processResults(final DataPackage b) {
    if (!running)
        return;/*from w w  w  . j  a  va  2  s .c  o m*/
    if (getResources() == null)
        return;
    if (b != null) {
        int id = b.getId();
        final Integer id1 = new Integer(id);
        if (!CancelledCopyIds.contains(id1)) {
            if (CopyIds.contains(id1)) {
                boolean completed = b.isCompleted();
                View process = rootView.findViewWithTag("copy" + id);
                if (completed) {
                    try {
                        rootView.removeViewInLayout(process);
                        CopyIds.remove(CopyIds.indexOf(id1));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    String name = b.getName();
                    int p1 = b.getP1();
                    int p2 = b.getP2();
                    long total = b.getTotal();
                    long done = b.getDone();
                    boolean move = b.isMove();
                    String text = utils.getString(getActivity(), R.string.copying) + "\n" + name + "\n"
                            + utils.readableFileSize(done) + "/" + utils.readableFileSize(total) + "\n" + p1
                            + "%";
                    if (move) {
                        text = utils.getString(getActivity(), R.string.moving) + "\n" + name + "\n"
                                + utils.readableFileSize(done) + "/" + utils.readableFileSize(total) + "\n" + p1
                                + "%";
                    }
                    ((TextView) process.findViewById(R.id.progressText)).setText(text);
                    ProgressBar p = (ProgressBar) process.findViewById(R.id.progressBar1);
                    p.setProgress(p1);
                    p.setSecondaryProgress(p2);
                }
            } else {
                CardView root = (android.support.v7.widget.CardView) getActivity().getLayoutInflater()
                        .inflate(R.layout.processrow, null);
                root.setTag("copy" + id);

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

                Drawable icon = icons.getCopyDrawable();
                boolean move = b.isMove();
                if (move) {
                    icon = icons.getCutDrawable();
                }
                if (mainActivity.theme1 == 1) {

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

                    icon.setColorFilter(Color.parseColor("#666666"), PorterDuff.Mode.SRC_ATOP);
                    progressText.setTextColor(Color.BLACK);
                }

                ((ImageView) root.findViewById(R.id.progressImage)).setImageDrawable(icon);
                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("copycancel");
                        i.putExtra("id", id1);
                        getActivity().sendBroadcast(i);
                        rootView.removeView(rootView.findViewWithTag("copy" + id1));

                        CopyIds.remove(CopyIds.indexOf(id1));
                        CancelledCopyIds.add(id1);
                        // TODO: Implement this method
                    }
                });

                String name = b.getName();
                int p1 = b.getP1();
                int p2 = b.getP2();

                String text = utils.getString(getActivity(), R.string.copying) + "\n" + name;
                if (move) {
                    text = utils.getString(getActivity(), R.string.moving) + "\n" + name;
                }
                progressText.setText(text);
                ProgressBar p = (ProgressBar) root.findViewById(R.id.progressBar1);
                p.setProgress(p1);
                p.setSecondaryProgress(p2);
                CopyIds.add(id1);
                rootView.addView(root);
            }
        }
    }
}

From source file:org.camlistore.CamliActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/* w  ww .  j  a  v  a 2s  . c  o  m*/

    Looper.myQueue().addIdleHandler(mIdleHandler);
    final Button buttonToggle = (Button) findViewById(R.id.buttonToggle);

    final TextView textStatus = (TextView) findViewById(R.id.textStatus);
    final TextView textStats = (TextView) findViewById(R.id.textStats);
    final TextView textErrors = (TextView) findViewById(R.id.textErrors);
    final TextView textBlobsRemain = (TextView) findViewById(R.id.textBlobsRemain);
    final TextView textUploadStatus = (TextView) findViewById(R.id.textUploadStatus);
    final TextView textByteStatus = (TextView) findViewById(R.id.textByteStatus);
    final ProgressBar progressBytes = (ProgressBar) findViewById(R.id.progressByteStatus);
    final TextView textFileStatus = (TextView) findViewById(R.id.textFileStatus);
    final ProgressBar progressFile = (ProgressBar) findViewById(R.id.progressFileStatus);

    buttonToggle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View btn) {
            Log.d(TAG, "button click!  text=" + buttonToggle.getText());
            if (getString(R.string.pause).equals(buttonToggle.getText())) {
                try {
                    Log.d(TAG, "Pausing..");
                    mServiceStub.pause();
                } catch (RemoteException e) {
                }
            } else if (getString(R.string.resume).equals(buttonToggle.getText())) {
                try {
                    Log.d(TAG, "Resuming..");
                    mServiceStub.resume();
                } catch (RemoteException e) {
                }
            }
        }
    });

    mCallback = new IStatusCallback.Stub() {
        private volatile int mLastBlobsUploadRemain = 0;
        private volatile int mLastBlobsDigestRemain = 0;

        @Override
        public void logToClient(String stuff) throws RemoteException {
            // TODO Auto-generated method stub
        }

        @Override
        public void setUploading(final boolean uploading) throws RemoteException {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (uploading) {
                        buttonToggle.setText(R.string.pause);
                        textStatus.setText(R.string.uploading);
                        textErrors.setText("");
                    } else if (mLastBlobsDigestRemain > 0) {
                        buttonToggle.setText(R.string.pause);
                        textStatus.setText(R.string.digesting);
                    } else {
                        buttonToggle.setText(R.string.resume);
                        int stepsRemain = mLastBlobsUploadRemain + mLastBlobsDigestRemain;
                        textStatus.setText(stepsRemain > 0 ? "Paused." : "Idle.");
                    }
                }
            });
        }

        @Override
        public void setFileStatus(final int done, final int inFlight, final int total) throws RemoteException {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    boolean finished = (done == total && mLastBlobsDigestRemain == 0);
                    buttonToggle.setEnabled(!finished);
                    progressFile.setMax(total);
                    progressFile.setProgress(done);
                    progressFile.setSecondaryProgress(done + inFlight);
                    if (finished) {
                        buttonToggle.setText(getString(R.string.pause_resume));
                    }

                    StringBuilder filesUploaded = new StringBuilder(40);
                    if (done < 2) {
                        filesUploaded.append(done).append(" file uploaded");
                    } else {
                        filesUploaded.append(done).append(" files uploaded");
                    }
                    textFileStatus.setText(filesUploaded.toString());

                    StringBuilder sb = new StringBuilder(40);
                    sb.append("Files to upload: ").append(total - done);
                    textBlobsRemain.setText(sb.toString());
                }
            });
        }

        @Override
        public void setByteStatus(final long done, final int inFlight, final long total)
                throws RemoteException {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    // setMax takes an (signed) int, but 2GB is a totally
                    // reasonable upload size, so use units of 1KB instead.
                    progressBytes.setMax((int) (total / 1024L));
                    progressBytes.setProgress((int) (done / 1024L));
                    // TODO: renable once pk-put properly sends inflight information
                    // progressBytes.setSecondaryProgress(progressBytes.getProgress() + inFlight / 1024);

                    StringBuilder bytesUploaded = new StringBuilder(40);
                    if (done < 2) {
                        bytesUploaded.append(done).append(" byte uploaded");
                    } else {
                        bytesUploaded.append(done).append(" bytes uploaded");
                    }
                    textByteStatus.setText(bytesUploaded.toString());
                }
            });
        }

        @Override
        public void setUploadStatusText(final String text) throws RemoteException {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    textUploadStatus.setText(text);
                }
            });
        }

        @Override
        public void setUploadStatsText(final String text) throws RemoteException {
            // We were getting these status updates so quickly that the calls to TextView.setText
            // were consuming all CPU on the main thread and it was stalling the main thread
            // for seconds, sometimes even triggering device freezes. Ridiculous. So instead,
            // only update this every 30 milliseconds, otherwise wait for the looper to be idle
            // to update it.
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mStatusTextWant = text;
                    long now = System.currentTimeMillis();
                    if (mLastStatusUpdate < now - 30) {
                        mStatusTextCurrent = mStatusTextWant;
                        textStats.setText(mStatusTextWant);
                        mLastStatusUpdate = System.currentTimeMillis();
                    }
                }
            });
        }

        public void setUploadErrorsText(final String text) throws RemoteException {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    textErrors.setText(text);
                }
            });
        }
    };

}