From ee46d71962a7c79aeca01f8db4a00fec3410a540 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Tue, 20 Mar 2012 16:22:08 +0000 Subject: Android app: delay the appearance of the search progress dialog --- android/src/com/artifex/mupdf/MuPDFActivity.java | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/android/src/com/artifex/mupdf/MuPDFActivity.java b/android/src/com/artifex/mupdf/MuPDFActivity.java index 416c1834..9ec38dd7 100644 --- a/android/src/com/artifex/mupdf/MuPDFActivity.java +++ b/android/src/com/artifex/mupdf/MuPDFActivity.java @@ -12,6 +12,7 @@ import android.graphics.RectF; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Handler; import android.text.Editable; import android.text.TextWatcher; import android.text.method.PasswordTransformationMethod; @@ -39,11 +40,30 @@ class SearchTaskResult { searchBoxes = _searchBoxes; } } + +class ProgressDialogX extends ProgressDialog { + public ProgressDialogX(Context context) { + super(context); + } + + private boolean mCancelled = false; + + public boolean isCancelled() { + return mCancelled; + } + + @Override + public void cancel() { + mCancelled = true; + super.cancel(); + } +} public class MuPDFActivity extends Activity { /* The core rendering instance */ private enum LinkState {DEFAULT, HIGHLIGHT, INHIBIT}; private final int TAP_PAGE_MARGIN = 5; + private final int SEARCH_PROGRESS_DELAY = 200; private MuPDFCore core; private String mFileName; private ReaderView mDocView; @@ -66,6 +86,7 @@ public class MuPDFActivity extends Activity private SearchTaskResult mSearchTaskResult; private AlertDialog.Builder mAlertBuilder; private LinkState mLinkState = LinkState.DEFAULT; + private final Handler mHandler = new Handler(); private MuPDFCore openFile(String path) { @@ -587,7 +608,7 @@ public class MuPDFActivity extends Activity void search(int direction) { killSearch(); - final ProgressDialog progressDialog = new ProgressDialog(this); + final ProgressDialogX progressDialog = new ProgressDialogX(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setTitle(getString(R.string.searching_)); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @@ -652,7 +673,12 @@ public class MuPDFActivity extends Activity @Override protected void onPreExecute() { super.onPreExecute(); - progressDialog.show(); + mHandler.postDelayed(new Runnable() { + public void run() { + if (!progressDialog.isCancelled()) + progressDialog.show(); + } + }, SEARCH_PROGRESS_DELAY); } }; -- cgit v1.2.3