List of usage examples for android.widget ProgressBar setMax
@android.view.RemotableViewMethod public synchronized void setMax(int max)
Set the upper range of the progress bar max.
From source file:com.money.manager.ex.home.HomeFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { switch (loader.getId()) { case LOADER_ACCOUNT_BILLS: try {/*w w w .j a v a 2 s. com*/ renderAccountsList(data); } catch (Exception e) { Timber.e(e, "rendering account list"); } // set total for accounts in the main Drawer. EventBus.getDefault().post(new AccountsTotalLoadedEvent(txtTotalAccounts.getText().toString())); break; case LOADER_INCOME_EXPENSES: double income = 0, expenses = 0; if (data != null) { while (data.moveToNext()) { expenses = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses)); income = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income)); } } TextView txtIncome = (TextView) getActivity().findViewById(R.id.textViewIncome); TextView txtExpenses = (TextView) getActivity().findViewById(R.id.textViewExpenses); TextView txtDifference = (TextView) getActivity().findViewById(R.id.textViewDifference); // set value if (txtIncome != null) txtIncome.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income))); if (txtExpenses != null) txtExpenses.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(Math.abs(expenses)))); if (txtDifference != null) txtDifference.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income - Math.abs(expenses)))); // manage progressbar final ProgressBar barIncome = (ProgressBar) getActivity().findViewById(R.id.progressBarIncome); final ProgressBar barExpenses = (ProgressBar) getActivity().findViewById(R.id.progressBarExpenses); if (barIncome != null && barExpenses != null) { barIncome.setMax((int) (Math.abs(income) + Math.abs(expenses))); barExpenses.setMax((int) (Math.abs(income) + Math.abs(expenses))); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { ObjectAnimator animationIncome = ObjectAnimator.ofInt(barIncome, "progress", (int) Math.abs(income)); animationIncome.setDuration(1000); // 0.5 second animationIncome.setInterpolator(new DecelerateInterpolator()); animationIncome.start(); ObjectAnimator animationExpenses = ObjectAnimator.ofInt(barExpenses, "progress", (int) Math.abs(expenses)); animationExpenses.setDuration(1000); // 0.5 second animationExpenses.setInterpolator(new DecelerateInterpolator()); animationExpenses.start(); } else { barIncome.setProgress((int) Math.abs(income)); barExpenses.setProgress((int) Math.abs(expenses)); } } break; } // Close the cursor. MmxDatabaseUtils.closeCursor(data); }
From source file:org.alfresco.mobile.android.application.fragments.node.browser.ProgressNodeAdapter.java
@Override protected void updateTopText(TwoLinesProgressViewHolder vh, Node item) { ProgressBar progressView = vh.progress; if (item instanceof NodePlaceHolder) { vh.topText.setText(item.getName()); vh.topText.setEnabled(false);/* ww w . j a v a2s. c om*/ long totalSize = ((NodePlaceHolder) item).getLength(); if ((Integer) item.getPropertyValue(PublicAPIPropertyIds.REQUEST_STATUS) == Operation.STATUS_PAUSED || (Integer) item .getPropertyValue(PublicAPIPropertyIds.REQUEST_STATUS) == Operation.STATUS_PENDING) { progressView.setVisibility(View.GONE); } else { progressView.setVisibility(View.VISIBLE); progressView.setIndeterminate(false); if (totalSize == -1) { progressView.setMax(MAX_PROGRESS); progressView.setProgress(0); } else { long progress = ((NodePlaceHolder) item).getProgress(); float value = (((float) progress / ((float) totalSize)) * MAX_PROGRESS); int percentage = Math.round(value); if (percentage == MAX_PROGRESS) { if ((Integer) item .getPropertyValue(PublicAPIPropertyIds.REQUEST_TYPE) == DownloadRequest.TYPE_ID) { progressView.setVisibility(View.GONE); super.updateTopText(vh, item); vh.bottomText.setVisibility(View.VISIBLE); super.updateBottomText(vh, item); super.updateIcon(vh, item); } else { progressView.setIndeterminate(true); } } else { progressView.setIndeterminate(false); progressView.setMax(MAX_PROGRESS); progressView.setProgress(percentage); } } } } else { progressView.setVisibility(View.GONE); super.updateTopText(vh, item); } }
From source file:com.ternup.caddisfly.activity.VideoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar); File sdDir = this.getExternalFilesDir(null); final File videoFile = new File(sdDir, "training.mp4"); if (videoFile.exists()) { playVideo(videoFile);// ww w. ja v a2s . co m } else { if (NetworkUtils.checkInternetConnection(this)) { progressBar.setVisibility(View.VISIBLE); downloading = true; AsyncHttpClient client = new AsyncHttpClient(); client.get("http://caddisfly.ternup.com/akvoapp/caddisfly-training.mp4", new FileAsyncHttpResponseHandler(videoFile) { @Override public void onFailure(int i, Header[] headers, Throwable throwable, File file) { progressBar.setVisibility(View.GONE); } @Override public void onSuccess(int statusCode, Header[] headers, File response) { playVideo(response); progressBar.setVisibility(View.GONE); } @Override public void onProgress(int bytesWritten, int totalSize) { //int progressPercentage = (int)100*bytesWritten/totalSize; progressBar.setMax(totalSize); progressBar.setProgress(bytesWritten); } @Override public void onFinish() { super.onFinish(); progressBar.setVisibility(View.GONE); downloading = false; } }); } } }
From source file:org.camlistore.CamliActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);// ww w . j av a 2 s. 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); } }); } }; }
From source file:com.nextgis.maplibui.activity.ModifyAttributesActivity.java
protected void createLocationPanelView(final IGISApplication app) { if (null == mGeometry && mFeatureId == NOT_FOUND) { mLatView = (TextView) findViewById(R.id.latitude_view); mLongView = (TextView) findViewById(R.id.longitude_view); mAltView = (TextView) findViewById(R.id.altitude_view); mAccView = (TextView) findViewById(R.id.accuracy_view); final ImageButton refreshLocation = (ImageButton) findViewById(R.id.refresh); mAccurateLocation = (SwitchCompat) findViewById(R.id.accurate_location); mAccurateLocation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from w w w . ja va 2s.c om public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (mAccurateLocation.getTag() == null) { refreshLocation.performClick(); mAccurateLocation.setTag(new Object()); } } }); mAccuracyCE = (AppCompatSpinner) findViewById(R.id.accurate_ce); refreshLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(500); rotateAnimation.setRepeatCount(1); refreshLocation.startAnimation(rotateAnimation); if (mAccurateLocation.isChecked()) { AlertDialog.Builder builder = new AlertDialog.Builder(ModifyAttributesActivity.this); View layout = View.inflate(ModifyAttributesActivity.this, R.layout.dialog_progress_accurate_location, null); TextView message = (TextView) layout.findViewById(R.id.message); final ProgressBar progress = (ProgressBar) layout.findViewById(R.id.progress); final TextView progressPercent = (TextView) layout.findViewById(R.id.progress_percent); final TextView progressNumber = (TextView) layout.findViewById(R.id.progress_number); final CheckBox finishBeep = (CheckBox) layout.findViewById(R.id.finish_beep); builder.setView(layout); builder.setTitle(R.string.accurate_location); final AccurateLocationTaker accurateLocation = new AccurateLocationTaker(view.getContext(), 100f, mMaxTakeCount, MAX_TAKE_TIME, PROGRESS_DELAY, (String) mAccuracyCE.getSelectedItem()); progress.setIndeterminate(true); message.setText(R.string.accurate_taking); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { accurateLocation.cancelTaking(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { accurateLocation.cancelTaking(); } }); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { ControlHelper.unlockScreenOrientation(ModifyAttributesActivity.this); } }); final AlertDialog dialog = builder.create(); accurateLocation .setOnProgressUpdateListener(new AccurateLocationTaker.OnProgressUpdateListener() { @SuppressLint("SetTextI18n") @Override public void onProgressUpdate(Long... values) { int value = values[0].intValue(); if (value == 1) { progress.setIndeterminate(false); progress.setMax(mMaxTakeCount); } if (value > 0) progress.setProgress(value); progressPercent.setText(value * 100 / mMaxTakeCount + " %"); progressNumber.setText(value + " / " + mMaxTakeCount); } }); accurateLocation.setOnGetAccurateLocationListener( new AccurateLocationTaker.OnGetAccurateLocationListener() { @Override public void onGetAccurateLocation(Location accurateLocation, Long... values) { dialog.dismiss(); if (finishBeep.isChecked()) playBeep(); setLocationText(accurateLocation); } }); ControlHelper.lockScreenOrientation(ModifyAttributesActivity.this); dialog.setCanceledOnTouchOutside(false); dialog.show(); accurateLocation.startTaking(); } else if (null != app) { GpsEventSource gpsEventSource = app.getGpsEventSource(); Location location = gpsEventSource.getLastKnownLocation(); setLocationText(location); } } }); } else { //hide location panel ViewGroup rootView = (ViewGroup) findViewById(R.id.controls_list); rootView.removeView(findViewById(R.id.location_panel)); } }
From source file:org.anurag.compress.ExtractTarFile.java
public ExtractTarFile(final Context ctx, final Item zFile, final int width, String extractDir, final File file, final int mode) { // TODO Auto-generated constructor stub running = false;/*from w w w . ja v a2s .c om*/ errors = false; prog = 0; read = 0; final Dialog dialog = new Dialog(ctx, Constants.DIALOG_STYLE); dialog.setCancelable(true); dialog.setContentView(R.layout.extract_file); dialog.getWindow().getAttributes().width = width; DEST = extractDir; final ProgressBar progress = (ProgressBar) dialog.findViewById(R.id.zipProgressBar); final TextView to = (TextView) dialog.findViewById(R.id.zipFileName); final TextView from = (TextView) dialog.findViewById(R.id.zipLoc); final TextView cfile = (TextView) dialog.findViewById(R.id.zipSize); final TextView zsize = (TextView) dialog.findViewById(R.id.zipNoOfFiles); final TextView status = (TextView) dialog.findViewById(R.id.zipFileLocation); if (extractDir == null) to.setText(ctx.getString(R.string.extractingto) + " Cache directory"); else to.setText(ctx.getString(R.string.extractingto) + " " + DEST); from.setText(ctx.getString(R.string.extractingfrom) + " " + file.getName()); if (mode == 2) { //TAR ENTRY HAS TO BE SHARED VIA BLUETOOTH,ETC... TextView t = null;//= (TextView)dialog.findViewById(R.id.preparing); t.setText(ctx.getString(R.string.preparingtoshare)); } try { if (file.getName().endsWith(".tar.gz")) tar = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(file))); else tar = new TarArchiveInputStream(new BufferedInputStream(new FileInputStream(file))); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); tar = null; } final Handler handle = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: progress.setProgress(0); cfile.setText(ctx.getString(R.string.extractingfile) + " " + name); break; case 1: status.setText(name); progress.setProgress((int) prog); break; case 2: try { tar.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (running) { dialog.dismiss(); if (mode == 0) { //after extracting file ,it has to be opened.... new OpenFileDialog(ctx, Uri.parse(dest)); } else if (mode == 2) { //FILE HAS TO BE SHARED.... new BluetoothChooser(ctx, new File(dest).getAbsolutePath(), null); } else { if (errors) Toast.makeText(ctx, ctx.getString(R.string.errorinext), Toast.LENGTH_SHORT).show(); Toast.makeText(ctx, ctx.getString(R.string.fileextracted), Toast.LENGTH_SHORT).show(); } } break; case 3: zsize.setText(size); progress.setMax((int) max); break; case 4: status.setText(ctx.getString(R.string.preparing)); break; case 5: running = false; Toast.makeText(ctx, ctx.getString(R.string.extaborted), Toast.LENGTH_SHORT).show(); } } }; final Thread thread = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub if (running) { if (DEST == null) { DEST = Environment.getExternalStorageDirectory() + "/Android/data/org.anurag.file.quest"; new File(DEST).mkdirs(); } TarArchiveEntry ze; try { while ((ze = tar.getNextTarEntry()) != null) { if (ze.isDirectory()) continue; handle.sendEmptyMessage(4); if (!zFile.isDirectory()) { //EXTRACTING A SINGLE FILE FROM AN ARCHIVE.... if (ze.getName().equalsIgnoreCase(zFile.t_getEntryName())) { try { //SENDING CURRENT FILE NAME.... try { name = zFile.getName(); } catch (Exception e) { name = zFile.t_getEntryName(); } handle.sendEmptyMessage(0); dest = DEST; dest = dest + "/" + name; FileOutputStream out = new FileOutputStream((dest)); max = ze.getSize(); size = AppBackup.size(max, ctx); handle.sendEmptyMessage(3); InputStream fin = tar; while ((read = fin.read(data)) != -1 && running) { out.write(data, 0, read); prog += read; name = AppBackup.status(prog, ctx); handle.sendEmptyMessage(1); } out.flush(); out.close(); fin.close(); break; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); //errors = true; } catch (IOException e) { errors = true; } } } else { //EXTRACTING A DIRECTORY FROM TAR ARCHIVE.... String p = zFile.getPath(); if (p.startsWith("/")) p = p.substring(1, p.length()); if (ze.getName().startsWith(p)) { prog = 0; dest = DEST; name = ze.getName(); String path = name; name = name.substring(name.lastIndexOf("/") + 1, name.length()); handle.sendEmptyMessage(0); String foname = zFile.getPath(); if (!foname.startsWith("/")) foname = "/" + foname; if (!path.startsWith("/")) path = "/" + path; path = path.substring(foname.lastIndexOf("/"), path.lastIndexOf("/")); if (!path.startsWith("/")) path = "/" + path; dest = dest + path; new File(dest).mkdirs(); dest = dest + "/" + name; FileOutputStream out; try { max = ze.getSize(); out = new FileOutputStream((dest)); size = AppBackup.size(max, ctx); handle.sendEmptyMessage(3); // InputStream fin = tar; while ((read = tar.read(data)) != -1 && running) { out.write(data, 0, read); prog += read; name = AppBackup.status(prog, ctx); handle.sendEmptyMessage(1); } out.flush(); out.close(); //fin.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); // errors = true; } catch (IOException e) { errors = true; } catch (Exception e) { //errors = true; } } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); errors = true; } handle.sendEmptyMessage(2); } } }); /* Button cancel = (Button)dialog.findViewById(R.id.calcelButton); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub dialog.dismiss(); handle.sendEmptyMessage(5); } }); Button st = (Button)dialog.findViewById(R.id.extractButton); st.setVisibility(View.GONE);*/ dialog.show(); running = true; thread.start(); dialog.setCancelable(false); progress.setVisibility(View.VISIBLE); }
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
private void autoTimer(final ThreadCtrl threadCtl, final NotifyEvent at_ne, final String msg) { setUiDisabled();//from ww w . j av a2s. com final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() {//non UI thread ProgressBar pb = (ProgressBar) findViewById(R.id.profile_progress_bar_progress); pb.setMax(ATERM_WAIT_TIME); final TextView pm = (TextView) findViewById(R.id.profile_progress_bar_msg); for (int i = 0; i < ATERM_WAIT_TIME; i++) { try { if (threadCtl.isEnabled()) { final int ix = i; handler.post(new Runnable() { //UI thread @Override public void run() { String t_msg = String.format(msg, (ATERM_WAIT_TIME - ix)); pm.setText(t_msg); showNotificationMsg(t_msg); } }); // non UI thread pb.setProgress(i); } else { break; } Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } // dismiss progress bar dialog handler.post(new Runnable() {// UI thread @Override public void run() { LinearLayout ll_bar = (LinearLayout) findViewById(R.id.profile_progress_bar); ll_bar.setVisibility(LinearLayout.GONE); setUiEnabled(); if (mRequestAutoTimerExpired) {//Immediate process requested at_ne.notifyToListener(true, null); } else { if (threadCtl.isEnabled()) at_ne.notifyToListener(true, null); else at_ne.notifyToListener(false, null); } } }); } }).start(); }