public void updateProgressDialog(long progress) { if (progress == 100) { progressDialog.setProgress(progressDialog.getMax()); setResult(RESULT_OK, resultIntent); progressDialog.dismiss(); finish(); } else { progressDialog.setProgress((int) progress); } }
/** * A generic function used to update a currently displayed progress dialog. * * @param currentValue The current value of the progress bar * @param maxValue The maximum value of the progress bar */ private void updateProgressDialog(int currentValue, int maxValue) { if (progDialog != null) { if (progDialog.isShowing()) { progDialog.setProgress(currentValue); } else { progDialog.setMax(maxValue); progDialog.setProgress(currentValue); progDialog.show(); } } }
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case BUSLINE_ARRIVAL: progressDialog.setProgress(0); progressThread = new OasthHTTPThread(handler, selStopArrPosition, BUSLINE_ARRIVAL); progressThread.start(); break; case BUSLINES_ARRIVAL: progressDialog.setProgress(0); progressThread = new OasthHTTPThread(handler, selStopArrPosition, BUSLINES_ARRIVAL); progressThread.start(); break; } }
@Override protected void onPreExecute() { progressBar = new ProgressDialog(activity); progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressBar.setProgress(0); progressBar.setMax(100); progressBar.setTitle("Please wait while contacting server ..."); progressBar.show(); t = new Thread( new Runnable() { int progressBarStatus = 0; public void run() { try { while (true) { Thread.sleep(100); progressBarbHandler.post( new Runnable() { public void run() { progressBar.setProgress(progressBarStatus); } }); progressBarStatus = (progressBarStatus + 5) % 100; } } catch (InterruptedException e) { } } }); t.start(); }
private void makeUpdateProgress() { progressBar = new ProgressDialog(this); progressBar.setCancelable(false); progressBar.setMessage("Downloading Updates ..."); progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressBar.setProgress(0); progressBar.show(); final Handler handler = new Handler() { public void handleMessage(Message msg) { progressBar.dismiss(); Toast.makeText(getApplicationContext(), "Update succsessful!", Toast.LENGTH_SHORT) .show(); } }; Thread startSaving = new Thread() { public void run() { updater.updateData(progressBar); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.sendEmptyMessage(0); } }; startSaving.start(); }
/** * Sets the progress dialog value. * * @param value the dialog value */ public void setProgressDialogValue(int value) { if (progressDialog != null) { progressDialog.setIndeterminate(false); progressDialog.setProgress(value); progressDialog.setMax(100); } }
@Override protected void onPreExecute() { progressDialog.setTitle(titleId); progressDialog.setMessage(activity.getString(messageId)); progressDialog.setIndeterminate(false); progressDialog.setCancelable(true); progressDialog.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { ProgressingTask.this.cancel(false); } }); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgress(0); progressDialog.setMax(100); // progressDialog.setProgressNumberFormat(null); // requires API level 11 (Android 3.0.x) progressDialog.show(); progress = new Progress() { @Override public boolean isCancelled() { return ProgressingTask.this.isCancelled(); } @Override public void publishProgress(int value) { ProgressingTask.this.publishProgress(value); } }; }
public static File downLoad(String path, String savedPath, ProgressDialog pd) throws Exception { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); int code = conn.getResponseCode(); if (code == 200) { pd.setMax(conn.getContentLength()); File file = new File(savedPath); FileOutputStream fos = new FileOutputStream(file); InputStream is = conn.getInputStream(); byte[] buffer = new byte[1024]; int len = 0; int total = 0; while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); total += len; pd.setProgress(total); } is.close(); fos.close(); return file; } else { return null; } } else { throw new IllegalAccessException("sd card is not available now"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); adView = new AdView(this, AdSize.SMART_BANNER, "a152f84b0f4f9ed"); LinearLayout adContainer = (LinearLayout) this.findViewById(R.id.adsContainer); adContainer.addView(adView); AdRequest adRequest = new AdRequest(); Set<String> keywordsSet = new HashSet<String>(); keywordsSet.add("game"); keywordsSet.add("dating"); keywordsSet.add("money"); keywordsSet.add("girl"); adRequest.addKeywords(keywordsSet); adRequest.addTestDevice("1B91DF7A13E674202332C251084C3ADA"); adView.loadAd(adRequest); imageView = (ImageView) this.findViewById(R.id.imageView1); progressDialog = new ProgressDialog(this); progressDialog.setTitle("Download Image"); progressDialog.setMessage("Downloading in progress..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgress(0); progressDialog.setButton( DialogInterface.BUTTON_NEGATIVE, "Show Image", dialogInterfaceOnClickListener); Button downloadButton = (Button) findViewById(R.id.downloadButton); downloadButton.setOnClickListener(downloadButtonOnClickListener); }
/** * Unzip an archive * * @param zipname the archive name, stored in the temp directory * @return boolean state indicating the unzip success */ private boolean UnzipLangArchive(String zipname) { ZipFile zipFile; // reset the statuses, thus we will be able to get the progress[%] status m_lMaxDownloadSz = GetZipSize(zipname); m_lCurrentDownloadSz = 0; try { zipFile = new ZipFile(zipname); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String filename = entry.getName(); Log.v(TAG, "Extracting file: " + filename); if (!CopyInputStream(zipFile.getInputStream(entry), entry.getSize(), entry.getName())) return false; m_ParentProgressDialog.setProgress(GetDownloadStatus()); } zipFile.close(); } catch (IOException ioe) { Log.v(TAG, "exception:" + ioe.toString()); return false; } return true; }
public static File getFileFromServer(String path, ProgressDialog pd) throws Exception { // 如果相等的话表示当前的sdcard挂载在手机上并且是可用的 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); // 获取到文件的大小 pd.setMax(conn.getContentLength()); InputStream is = conn.getInputStream(); File file = new File(Environment.getExternalStorageDirectory(), "updata.apk"); FileOutputStream fos = new FileOutputStream(file); BufferedInputStream bis = new BufferedInputStream(is); byte[] buffer = new byte[1024]; int len; int total = 0; while ((len = bis.read(buffer)) != -1) { fos.write(buffer, 0, len); total += len; // 获取当前下载量 pd.setProgress(total); } fos.close(); bis.close(); is.close(); return file; } else { return null; } }
public void handleMessage(Message msg) { int p = msg.getData().getInt("PERCENT"); // 當事件進度抵達100時,關掉/隱藏 progressDialog/progressBar if (p > 100) { if (which_progress.equals("progress_dialog")) { myDialog.dismiss(); // Button3 & Button4:ProgressBar. } else if (which_progress.equals("progress_bar1")) { progressbar1.setVisibility(View.GONE); text_progressbar1.setText("Button3"); } else { progressbar2.setVisibility(View.GONE); text_progressbar2.setText("Button4"); text_percent.setText("100%"); } } else { if (which_progress.equals("progress_dialog")) { myDialog.setProgress(p); // Button4:ProgressBar Horizontal. } else if (which_progress.equals("progress_bar2")) { progressbar2.setProgress(p); text_percent.setText(p + "%"); } } }
@Test public void shouldSetProgress() { assertThat(dialog.getProgress()).isEqualTo(0); dialog.setProgress(42); assertThat(dialog.getProgress()).isEqualTo(42); }
@Override public void handleMessage(Message msg) { switch (msg.what) { case IMPORT_STEP_READ_FILE: case IMPORT_STEP_READ_WPT_FILE: case IMPORT_STEP_STORE_CACHES: parseDialog.setMessage(res.getString(msg.arg1)); parseDialog.setMax(msg.arg2); parseDialog.setProgress(0); break; case IMPORT_STEP_FINISHED: parseDialog.dismiss(); fromActivity.helpDialog( res.getString(R.string.gpx_import_title_caches_imported), msg.arg1 + " " + res.getString(R.string.gpx_import_caches_imported)); closeActivity(); break; case IMPORT_STEP_FINISHED_WITH_ERROR: parseDialog.dismiss(); fromActivity.helpDialog( res.getString(R.string.gpx_import_title_caches_import_failed), res.getString(msg.arg1) + "\n\n" + msg.obj); closeActivity(); break; } }
private void getNC() { List<NameValuePair> targVar = new ArrayList<NameValuePair>(); targVar.add( Wenku8Interface.getNovelContent(currentAid, currentCid, GlobalConfig.getFetchLanguage())); final asyncNovelContentTask ast = new asyncNovelContentTask(); ast.execute(targVar); pDialog = new ProgressDialog(parentActivity); pDialog.setTitle(getResources().getString(R.string.load_status)); pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pDialog.setCancelable(true); pDialog.setOnCancelListener( new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // TODO Auto-generated method stub ast.cancel(true); pDialog.dismiss(); pDialog = null; } }); pDialog.setMessage(getResources().getString(R.string.load_loading)); pDialog.setProgress(0); pDialog.setMax(1); pDialog.show(); return; }
@SuppressLint("DefaultLocale") private void loadApps(ProgressDialog dialog) { appList.clear(); permUsage.clear(); sharedUsers.clear(); pkgSharedUsers.clear(); PackageManager pm = getPackageManager(); List<PackageInfo> pkgs = getPackageManager().getInstalledPackages(PackageManager.GET_PERMISSIONS); dialog.setMax(pkgs.size()); int i = 1; for (PackageInfo pkgInfo : pkgs) { dialog.setProgress(i++); ApplicationInfo appInfo = pkgInfo.applicationInfo; if (appInfo == null) continue; appInfo.name = appInfo.loadLabel(pm).toString(); appList.add(appInfo); String[] perms = pkgInfo.requestedPermissions; if (perms != null) for (String perm : perms) { Set<String> permUsers = permUsage.get(perm); if (permUsers == null) { permUsers = new TreeSet<String>(); permUsage.put(perm, permUsers); } permUsers.add(pkgInfo.packageName); } if (pkgInfo.sharedUserId != null) { Set<String> sharedUserPackages = sharedUsers.get(pkgInfo.sharedUserId); if (sharedUserPackages == null) { sharedUserPackages = new TreeSet<String>(); sharedUsers.put(pkgInfo.sharedUserId, sharedUserPackages); } sharedUserPackages.add(pkgInfo.packageName); pkgSharedUsers.put(pkgInfo.packageName, pkgInfo.sharedUserId); } } Collections.sort( appList, new Comparator<ApplicationInfo>() { @Override public int compare(ApplicationInfo lhs, ApplicationInfo rhs) { if (lhs.name == null) { return -1; } else if (rhs.name == null) { return 1; } else { return lhs.name.toUpperCase().compareTo(rhs.name.toUpperCase()); } } }); }
@Override public void handleMessage(Message msg) { if (mError == true) { return; } int max = msg.getData().getInt("max"); int total = msg.getData().getInt("counter"); int message = msg.getData().getInt("message"); if (max > 0) { mProgressDialog.setMax(max); // mLogHelper.deleteTableLog(); // fillData(); return; } if (message == 1) { mProgressDialog.setMessage(getResources().getString(R.string.downloading)); } else if (message == 2) { mProgressDialog.setMessage(getResources().getString(R.string.extracting)); } mProgressDialog.setProgress(total); if (total == -2) { // ERROR downloading template mProgressDialog.dismiss(); mError = true; showErrorDownloadMessage(); } else if (total == -1) { mProgressDialog.dismiss(); finalizeGetIndexingTemplate(); } }
public void exportProgress(int progress) { mPd = new ProgressDialog(this); mPd.setTitle("Uploading..."); mPd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mPd.setProgress(progress); mPd.setCancelable(false); mPd.show(); }
@Override protected void onPreExecute() { progressDialog = new ProgressDialog(context); progressDialog.setProgress(ProgressDialog.STYLE_SPINNER); progressDialog.setCancelable(false); progressDialog.setMessage(getString(R.string.deleting)); progressDialog.show(); }
@Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(context); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setProgress(0); progressDialog.show(); }
@Override public void handleMessage(Message msg) { switch (msg.what) { case UPDATE: mProgressDialog.setProgress((int) (mCount / 1000)); break; } }
@Override protected void onProgressUpdate(Integer... values) { float totalBytesRead = values[0]; float fileSize = values[1]; float percentageDownloaded = (totalBytesRead / fileSize) * 100f; downloadDialog.setProgress((int) percentageDownloaded); }
@Override protected void onProgressUpdate(Integer... progress) { super.onProgressUpdate(progress); // if we get here, length is known, now set indeterminate to false mProgressDialog.setIndeterminate(false); mProgressDialog.setMax(100); mProgressDialog.setProgress(progress[0]); }
protected void onPreExecute() { bar1 = new ProgressDialog(context); bar1.setTitle("Download in progress ..."); bar1.setMax(10); bar1.setProgress(0); bar1.setProgressStyle(ProgressDialog.STYLE_SPINNER); bar1.show(); }
@Override protected void onProgressUpdate(Integer... stillLeftToUpload) { int alreadyUploaded = totalAmountBytesToUpload - stillLeftToUpload[0]; int onePercent = totalAmountBytesToUpload / 100; int percentUploaded = alreadyUploaded / onePercent; progressDialog.setProgress(percentUploaded); }
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case PROGRESS_DIALOG: progressDialog.setProgress(0); progressThread = new ProgressThread(handler); progressThread.start(); } }
@Override public void update(int total, int len, int threadid) { if (flag) { mProgressDialog.setMax(total); flag = false; } progressValue += len; mProgressDialog.setProgress(progressValue); }
public void zipProgress(int progress) { mPd = new ProgressDialog(this); mPd.setTitle("Packaging files to export."); mPd.setMessage("Please wait..."); mPd.setProgress(progress); mPd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mPd.setCancelable(false); mPd.show(); }
public void exportTasks( final Context context, final ExportType exportType, DialogBuilder dialogBuilder) { this.context = context; this.exportCount = 0; this.backupDirectory = preferences.getBackupDirectory(); this.latestSetVersionName = null; handler = exportType == ExportType.EXPORT_TYPE_MANUAL ? new Handler() : null; if (exportType == ExportType.EXPORT_TYPE_MANUAL) { progressDialog = dialogBuilder.newProgressDialog(); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgress(0); progressDialog.setCancelable(false); progressDialog.setIndeterminate(false); progressDialog.show(); if (context instanceof Activity) { progressDialog.setOwnerActivity((Activity) context); } } else { progressDialog = new ProgressDialog(context); } new Thread( new Runnable() { @Override public void run() { try { String output = setupFile(backupDirectory, exportType); int tasks = taskService.countTasks(); if (tasks > 0) { doTasksExport(output); } preferences.setLong(PREF_BACKUP_LAST_DATE, DateUtilities.now()); if (exportType == ExportType.EXPORT_TYPE_MANUAL) { onFinishExport(output); } } catch (IOException e) { Timber.e(e, e.getMessage()); } finally { post( new Runnable() { @Override public void run() { if (progressDialog.isShowing() && context instanceof Activity) { DialogUtilities.dismissDialog((Activity) context, progressDialog); ((Activity) context).finish(); } } }); } } }) .start(); }
@Override public void handleMessage(Message msg) { int total = msg.arg1; progressDialog.setProgress(total); if (total >= 100) { dismissDialog(PROGRESS_DIALOG); progressThread.setState(ProgressThread.STATE_DONE); } }