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.owncloud.android.ui.activity.ExternalSiteWebView.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreate() start");

    Bundle extras = getIntent().getExtras();
    String title = extras.getString(EXTRA_TITLE);
    String url = extras.getString(EXTRA_URL);
    menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID);
    showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR);

    // show progress
    getWindow().requestFeature(Window.FEATURE_PROGRESS);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.externalsite_webview);

    WebView webview = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webview.getSettings();

    webview.setFocusable(true);/*www  .  ja v  a  2s .c om*/
    webview.setFocusableInTouchMode(true);
    webview.setClickable(true);

    // setup toolbar
    setupToolbar();

    // setup drawer
    setupDrawer(menuItemId);

    if (!showSidebar) {
        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }

    getSupportActionBar().setTitle(title);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // enable zoom
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    // Non-responsive webs are zoomed out when loaded
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    // user agent
    webSettings.setUserAgentString(MainApp.getUserAgent());

    // no private data storing
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);

    // disable local file access
    webSettings.setAllowFileAccess(false);

    // enable javascript
    webview.getSettings().setJavaScriptEnabled(true);

    final Activity activity = this;
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(progress * 1000);
        }
    });

    webview.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT)
                    .show();
        }
    });

    webview.loadUrl(url);
}

From source file:de.zell.android.util.fragments.WebviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_webview, container, false);
    if (url != null && !url.isEmpty()) {
        content = ((WebView) rootView.findViewById(R.id.webview));
        //WebViewClient is enabled in order to force all links to load within the webview and also
        // in order to enable JavaScript
        content.setWebViewClient(new HelloWebViewClient());
        WebSettings webSettings = content.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);

        final ProgressBar progressBar = ((MainNavigationActivity) getActivity()).getProgressBar();
        content.setWebChromeClient(new WebChromeClient() {
            @Override//from w  w w  . j ava  2 s .  com
            public void onProgressChanged(WebView view, int newProgress) {
                progressBar.setProgress(newProgress);
                if (newProgress == 100)
                    progressBar.setVisibility(View.GONE);
            }
        });

        progressBar.setIndeterminate(true);
        progressBar.setVisibility(View.VISIBLE);
        content.loadUrl(url);
    }

    getActivity().setTitle(title);
    return rootView;
}

From source file:com.brewcrewfoo.performance.fragments.TimeInState.java

private View generateStateRow(CpuState state, ViewGroup parent) {

    LayoutInflater inflater = LayoutInflater.from(context);
    LinearLayout view = (LinearLayout) inflater.inflate(R.layout.state_row, parent, false);

    float per = (float) state.duration * 100 / monitor.getTotalStateTime();
    String sPer = (int) per + "%";

    String sFreq;/*from   w  w  w. j a va  2  s. c  om*/
    if (state.freq == 0) {
        sFreq = getString(R.string.deep_sleep);
    } else {
        sFreq = state.freq / 1000 + " MHz";
    }

    long tSec = state.duration / 100;
    String sDur = toString(tSec);

    TextView freqText = (TextView) view.findViewById(R.id.ui_freq_text);
    TextView durText = (TextView) view.findViewById(R.id.ui_duration_text);
    TextView perText = (TextView) view.findViewById(R.id.ui_percentage_text);
    ProgressBar bar = (ProgressBar) view.findViewById(R.id.ui_bar);

    freqText.setText(sFreq);
    perText.setText(sPer);
    durText.setText(sDur);
    bar.setProgress((int) per);

    parent.addView(view);
    return view;
}

From source file:com.sentaroh.android.Utilities.Dialog.ProgressBarDialogFragment.java

public void updateProgress(final int progress) {
    if (mUiHandler != null) {
        mUiHandler.post(new Runnable() {
            @Override/*from  w w  w.jav  a  2  s  .  co  m*/
            public void run() {
                mDialogProgress = progress;
                ProgressBar pb = (ProgressBar) mDialog
                        .findViewById(R.id.progress_bar_dlg_fragment_progress_bar);
                pb.setProgress(mDialogProgress);
            }
        });
    }
}

From source file:com.bonsai.btcreceive.MainActivity.java

@Override
protected void onWalletStateChanged() {
    if (mWalletService == null)
        return;/*from  w  w w  .j a v a  2 s  . c  o  m*/

    switch (mWalletService.getState()) {
    case SETUP:
    case WALLET_SETUP:
    case KEYS_ADD:
    case PEERING:
        // All of these states use a progress dialog.
        if (mStateProgressDialog != null)
            updateStateMessage(mWalletService.getStateString());
        else
            showStateProgressDialog(mWalletService.getStateString());
        break;
    case SYNCING:
        if (mStateProgressDialog != null) {
            mStateProgressDialog.dismissAllowingStateLoss();
            mStateProgressDialog = null;
        }

        if (mSyncProgressDialog == null)
            showSyncProgressDialog();

        int pctdone = (int) mWalletService.getPercentDone();

        String timeLeft = formatTimeLeft(mWalletService.getMsecsLeft());

        updateSyncStats(String.format("%d%%", pctdone), String.format("%d", mWalletService.getBlocksToGo()),
                mDateFormatter.format(mWalletService.getScanDate()), timeLeft);

        if (mSyncDialogView != null) {
            ProgressBar pb = (ProgressBar) mSyncDialogView.findViewById(R.id.progress_bar);
            pb.setProgress(pctdone);
        }
        break;
    case READY:
        if (mStateProgressDialog != null) {
            mStateProgressDialog.dismissAllowingStateLoss();
            mStateProgressDialog = null;
            mStateDialogView = null;
        }

        if (mSyncProgressDialog != null) {
            mSyncProgressDialog.dismissAllowingStateLoss();
            mSyncProgressDialog = null;
            mSyncDialogView = null;
        }
        break;
    case SHUTDOWN:
        break;
    case ERROR:
        break;
    }
}

From source file:com.google.sample.beaconservice.MainActivityFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    final ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
    progressBar.setProgress(0);
    progressBar.getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);

    scanButton = (Button) rootView.findViewById(R.id.scanButton);
    scanButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w w. j a va 2 s .  com
        public void onClick(View v) {
            Utils.setEnabledViews(false, scanButton);
            arrayAdapter.clear();
            scanner.startScan(SCAN_FILTERS, SCAN_SETTINGS, scanCallback);
            Log.i(TAG, "starting scan");
            client = new ProximityBeaconImpl(getActivity(), accountNameView.getText().toString());
            CountDownTimer countDownTimer = new CountDownTimer(SCAN_TIME_MILLIS, 100) {
                @Override
                public void onTick(long millisUntilFinished) {
                    double i = (1 - millisUntilFinished / (double) SCAN_TIME_MILLIS) * 100;
                    progressBar.setProgress((int) i);
                }

                @Override
                public void onFinish() {
                    progressBar.setProgress(100);
                }
            };
            countDownTimer.start();

            Runnable stopScanning = new Runnable() {
                @Override
                public void run() {
                    scanner.stopScan(scanCallback);
                    Log.i(TAG, "stopped scan");
                    Utils.setEnabledViews(true, scanButton);
                }
            };
            handler.postDelayed(stopScanning, SCAN_TIME_MILLIS);
        }
    });

    accountNameView = (TextView) rootView.findViewById(R.id.accountName);
    accountNameView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pickUserAccount();
        }
    });

    // Set the account name from the shared prefs if we ever set it before.
    String accountName = sharedPreferences.getString("accountName", "");
    if (!accountName.isEmpty()) {
        accountNameView.setText(accountName);
    } else {
        pickUserAccount();
    }

    ListView listView = (ListView) rootView.findViewById(R.id.listView);
    listView.setAdapter(arrayAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Beacon beacon = arrayAdapter.getItem(position);
            if (beacon.status.equals(Beacon.NOT_AUTHORIZED)) {
                new AlertDialog.Builder(getActivity()).setTitle("Not Authorized")
                        .setMessage("You don't have permission to view the details of this beacon")
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).show();
                return;
            }
            if (beacon.status.equals(Beacon.STATUS_UNSPECIFIED)) {
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putString("accountName", accountNameView.getText().toString());
            bundle.putParcelable("beacon", arrayAdapter.getItem(position));
            ManageBeaconFragment fragment = new ManageBeaconFragment();
            fragment.setArguments(bundle);
            getFragmentManager().beginTransaction().replace(R.id.container, fragment).addToBackStack(TAG)
                    .commit();
        }
    });
    return rootView;
}

From source file:com.bonsai.wallet32.MainActivity.java

@Override
protected void onWalletStateChanged() {
    if (mWalletService == null)
        return;//from ww  w.  ja  v  a  2  s . c o  m

    switch (mWalletService.getState()) {
    case SETUP:
    case WALLET_SETUP:
    case KEYS_ADD:
    case PEERING:
        // All of these states use a progress dialog.
        if (mStateProgressDialog != null)
            updateStateMessage(mWalletService.getStateString());
        else
            showStateProgressDialog(mWalletService.getStateString());
        break;
    case SYNCING:
        if (mStateProgressDialog != null) {
            mStateProgressDialog.dismissAllowingStateLoss();
            mStateProgressDialog = null;
        }

        if (mSyncProgressDialog == null)
            showSyncProgressDialog();

        int pctdone = (int) mWalletService.getPercentDone();

        String timeLeft = formatTimeLeft(mWalletService.getMsecsLeft());

        updateSyncStats(String.format("%d%%", pctdone), String.format("%d", mWalletService.getBlocksToGo()),
                mDateFormatter.format(mWalletService.getScanDate()), timeLeft);

        if (mSyncDialogView != null) {
            ProgressBar pb = (ProgressBar) mSyncDialogView.findViewById(R.id.progress_bar);
            pb.setProgress(pctdone);
        }
        break;
    case READY:
        if (mStateProgressDialog != null) {
            mStateProgressDialog.dismissAllowingStateLoss();
            mStateProgressDialog = null;
            mStateDialogView = null;
        }

        if (mSyncProgressDialog != null) {
            mSyncProgressDialog.dismissAllowingStateLoss();
            mSyncProgressDialog = null;
            mSyncDialogView = null;
        }

        // Did we have an intent uri? (Sent from another application ...)
        String intentURI = mApp.getIntentURI();
        if (intentURI != null) {
            mApp.setIntentURI(null); // Clear it ASAP.
            Intent intent = new Intent(this, SendBitcoinActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("uri", intentURI);
            intent.putExtras(bundle);
            startActivity(intent);
        }
        break;
    case SHUTDOWN:
        break;
    case ERROR:
        break;
    }

    updateBalances();
}

From source file:com.gmail.nagamatu.radiko.installer.RadikoInstallerActivity.java

private void updateProgress(final int progress) {
    runOnUiThread(new Runnable() {
        @Override/*from w ww . j  av  a2s. co m*/
        public void run() {
            final ProgressBar view = (ProgressBar) findViewById(R.id.progress);
            view.setProgress(progress);
        }
    });
}

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 ww w. j a  v a 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);
            }
        }

    };
}

From source file:com.scm.reader.resultPage.ui.ItemViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*  ww  w.j a  v  a  2  s . c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_result, container, false);

    mWebView = (WebView) v.findViewById(R.id.webView);

    // set WebViewClient
    mWebViewClient = createWebViewClient(getActivity());
    mWebView.setWebViewClient(mWebViewClient);

    final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progressBar);

    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(progress);
            }
        }
    });

    initializeWebView(mWebView);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    mWebView.loadUrl(mUrl);

    return v;
}