List of usage examples for android.app ProgressDialog setProgress
public void setProgress(int value)
From source file:com.aujur.ebookreader.activity.ReadingFragment.java
@Override public void performSearch(String query) { LOG.debug("Starting search for: " + query); final ProgressDialog searchProgress = new ProgressDialog(context); searchProgress.setOwnerActivity(getActivity()); searchProgress.setCancelable(true);/*w w w . ja v a 2 s . c om*/ searchProgress.setMax(100); searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); final SearchTextTask task = new SearchTextTask(bookView.getBook()) { int i = 0; @Override protected void onPreExecute() { super.onPreExecute(); searchProgress.setMessage(getString(R.string.search_wait)); searchProgress.show(); // Hide on-screen keyboard if it is showing InputMethodManager imm = (InputMethodManager) context .getSystemService(Activity.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } @Override protected void onProgressUpdate(SearchResult... values) { if (!isAdded()) { return; } super.onProgressUpdate(values); LOG.debug("Found match at index=" + values[0].getIndex() + ", offset=" + values[0].getStart() + " with context " + values[0].getDisplay()); SearchResult res = values[0]; if (res.getDisplay() != null) { i++; String update = String.format(getString(R.string.search_hits), i); searchProgress.setMessage(update); } searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart())); } @Override protected void onCancelled() { if (isAdded()) { Toast.makeText(context, R.string.search_cancelled, Toast.LENGTH_LONG).show(); } } protected void onPostExecute(java.util.List<SearchResult> result) { searchProgress.dismiss(); if (!isCancelled() && isAdded()) { if (result.size() > 0) { searchResults = result; searchResultWraper.setSearchResult(searchResults); // showSearchResultDialog(result); Intent intent = new Intent(getActivity(), ReadingOptionsActivity.class); Bundle bundle = new Bundle(); bundle.putInt("SELECTED_TAB", 4); intent.putExtras(bundle); startActivity(intent); } else { Toast.makeText(context, R.string.search_no_matches, Toast.LENGTH_LONG).show(); } } }; }; searchProgress.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { task.cancel(true); } }); task.execute(query); }