Example usage for android.widget ProgressBar getMax

List of usage examples for android.widget ProgressBar getMax

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "progress")
public synchronized int getMax() 

Source Link

Document

Return the upper limit of this progress bar's range.

Usage

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}/*from   w w w . j  a v  a  2  s .  c  o  m*/
 */
@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:com.gsma.rcs.ri.sharing.geoloc.InitiateGeolocSharing.java

private void initialize() {
    mGeolocSharingService = getGeolocSharingApi();

    mSpinner = (Spinner) findViewById(R.id.contact);
    ContactListAdapter adapter = ContactListAdapter.createRcsContactListAdapter(this);
    mSpinner.setAdapter(adapter);/*from  w  w  w  .  j a va 2s  .  c om*/

    OnClickListener btnInviteListener = new OnClickListener() {
        public void onClick(View v) {
            // Check if the service is available
            try {
                if (!mGeolocSharingService.isServiceRegistered()) {
                    showMessage(R.string.error_not_registered);
                    return;
                }
                // get selected phone number
                ContactListAdapter adapter = (ContactListAdapter) mSpinner.getAdapter();
                String phoneNumber = adapter.getSelectedNumber(mSpinner.getSelectedView());
                ContactId contact = ContactUtil.formatContact(phoneNumber);
                if (LogUtils.isActive) {
                    Log.d(LOGTAG, "share geoloc=" + mGeoloc + " contact=" + contact);
                }
                mGeolocSharing = mGeolocSharingService.shareGeoloc(contact, mGeoloc);
                mSharingId = mGeolocSharing.getSharingId();
                mSpinner.setEnabled(false);
                mInviteBtn.setVisibility(View.INVISIBLE);
                mSelectBtn.setVisibility(View.INVISIBLE);
                mDialBtn.setVisibility(View.INVISIBLE);

            } catch (RcsServiceNotAvailableException e) {
                showMessage(R.string.label_service_not_available);

            } catch (RcsServiceException e) {
                showExceptionThenExit(e);
            }
        }
    };
    mInviteBtn = (Button) findViewById(R.id.invite_btn);
    mInviteBtn.setOnClickListener(btnInviteListener);
    mInviteBtn.setEnabled(false);

    OnClickListener btnSelectListener = new OnClickListener() {
        public void onClick(View v) {
            // Start a new activity to send a geolocation
            startActivityForResult(new Intent(InitiateGeolocSharing.this, EditGeoloc.class),
                    SELECT_GEOLOCATION);
        }
    };
    mSelectBtn = (Button) findViewById(R.id.select_btn);
    mSelectBtn.setOnClickListener(btnSelectListener);
    mSelectBtn.setEnabled(false);

    OnClickListener btnDialListener = new OnClickListener() {
        public void onClick(View v) {
            // get selected phone number
            ContactListAdapter adapter = (ContactListAdapter) mSpinner.getAdapter();
            String phoneNumber = adapter.getSelectedNumber(mSpinner.getSelectedView());

            // Initiate a GSM call before to be able to share content
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:".concat(phoneNumber)));
            if (ActivityCompat.checkSelfPermission(InitiateGeolocSharing.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            startActivity(intent);
        }
    };
    mDialBtn = (Button) findViewById(R.id.dial_btn);
    mDialBtn.setOnClickListener(btnDialListener);
    mDialBtn.setEnabled(false);

    mStatusView = (TextView) findViewById(R.id.progress_status);
    mPositionView = (TextView) findViewById(R.id.position);
    mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
    updateProgressBar(0, 0);
    mPositionView.setText("");

    if (adapter == null || adapter.getCount() != 0) {
        mDialBtn.setEnabled(true);
        mSelectBtn.setEnabled(true);
    }
    mListener = new GeolocSharingListener() {

        @Override
        public void onProgressUpdate(ContactId contact, String sharingId, final long currentSize,
                final long totalSize) {
            /* Discard event if not for current sharingId */
            if (InitiateGeolocSharing.this.mSharingId == null
                    || !InitiateGeolocSharing.this.mSharingId.equals(sharingId)) {
                return;
            }
            mHandler.post(new Runnable() {
                public void run() {
                    updateProgressBar(currentSize, totalSize);
                }
            });
        }

        @Override
        public void onStateChanged(final ContactId contact, String sharingId, final GeolocSharing.State state,
                GeolocSharing.ReasonCode reasonCode) {
            if (LogUtils.isActive) {
                Log.d(LOGTAG, "onStateChanged contact=" + contact + " sharingId=" + sharingId + " state="
                        + state + " reason=" + reasonCode);
            }
            /* Discard event if not for current sharingId */
            if (InitiateGeolocSharing.this.mSharingId == null
                    || !InitiateGeolocSharing.this.mSharingId.equals(sharingId)) {
                return;
            }
            final String _state = RiApplication.sGeolocSharingStates[state.toInt()];
            final String _reasonCode = RiApplication.sGeolocReasonCodes[reasonCode.toInt()];
            mHandler.post(new Runnable() {
                public void run() {
                    TextView statusView = (TextView) findViewById(R.id.progress_status);
                    switch (state) {
                    case STARTED:
                        // Display session status
                        statusView.setText(_state);
                        break;

                    case ABORTED:
                        showMessageThenExit(getString(R.string.label_sharing_aborted, _reasonCode));
                        break;

                    case REJECTED:
                        showMessageThenExit(getString(R.string.label_sharing_rejected, _reasonCode));
                        break;

                    case FAILED:
                        showMessageThenExit(getString(R.string.label_sharing_failed, _reasonCode));
                        break;

                    case TRANSFERRED:
                        /* Display transfer progress */
                        statusView.setText(_state);
                        /* Make sure progress bar is at the end */
                        ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
                        progressBar.setProgress(progressBar.getMax());

                        ShowGeoloc.ShowGeolocForContact(InitiateGeolocSharing.this, contact, mGeoloc);
                        break;

                    default:
                        statusView.setText(getString(R.string.label_gsh_state_changed, _state, _reasonCode));
                    }
                }
            });
        }

        @Override
        public void onDeleted(ContactId contact, Set<String> sharingIds) {
            if (LogUtils.isActive) {
                Log.w(LOGTAG, "onDeleted contact=" + contact + " sharingIds=" + sharingIds);
            }
        }

    };
}