void searchModeOff() { if (mTopBarIsSearch) { mTopBarIsSearch = false; hideKeyboard(); mTopBarSwitcher.showPrevious(); SearchTaskResult.set(null); // Make the ReaderView act on the change to mSearchTaskResult // via overridden onChildSetup method. mDocView.resetupChildren(); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAlertBuilder = new AlertDialog.Builder(this); if (core == null) { core = (MuPDFCore) getLastNonConfigurationInstance(); if (savedInstanceState != null && savedInstanceState.containsKey("FileName")) { mFileName = savedInstanceState.getString("FileName"); } } if (core == null) { Intent intent = getIntent(); if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); if (uri.toString().startsWith("content://")) { // Handle view requests from the Transformer Prime's file manager // Hopefully other file managers will use this same scheme, if not // using explicit paths. Cursor cursor = getContentResolver().query(uri, new String[] {"_data"}, null, null, null); if (cursor.moveToFirst()) { uri = Uri.parse(cursor.getString(0)); } } core = openFile(Uri.decode(uri.getEncodedPath())); SearchTaskResult.set(null); } if (core != null && core.needsPassword()) { requestPassword(savedInstanceState); return; } } if (core == null) { AlertDialog alert = mAlertBuilder.create(); alert.setTitle(R.string.open_failed); alert.setButton( AlertDialog.BUTTON_POSITIVE, "Dismiss", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); alert.show(); return; } createUI(savedInstanceState); }
void search(int direction) { hideKeyboard(); if (core == null) return; killSearch(); final int increment = direction; final int startIndex = SearchTaskResult.get() == null ? mDocView.getDisplayedViewIndex() : SearchTaskResult.get().pageNumber + increment; final ProgressDialogX progressDialog = new ProgressDialogX(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setTitle(getString(R.string.searching_)); progressDialog.setOnCancelListener( new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { killSearch(); } }); progressDialog.setMax(core.countPages()); mSearchTask = new SafeAsyncTask<Void, Integer, SearchTaskResult>() { @Override protected SearchTaskResult doInBackground(Void... params) { int index = startIndex; while (0 <= index && index < core.countPages() && !isCancelled()) { publishProgress(index); RectF searchHits[] = core.searchPage(index, mSearchText.getText().toString()); if (searchHits != null && searchHits.length > 0) return new SearchTaskResult(mSearchText.getText().toString(), index, searchHits); index += increment; } return null; } @Override protected void onPostExecute(SearchTaskResult result) { progressDialog.cancel(); if (result != null) { // Ask the ReaderView to move to the resulting page mDocView.setDisplayedViewIndex(result.pageNumber); SearchTaskResult.set(result); // Make the ReaderView act on the change to mSearchTaskResult // via overridden onChildSetup method. mDocView.resetupChildren(); } else { mAlertBuilder.setTitle( SearchTaskResult.get() == null ? R.string.text_not_found : R.string.no_further_occurences_found); AlertDialog alert = mAlertBuilder.create(); alert.setButton( AlertDialog.BUTTON_POSITIVE, "Dismiss", (DialogInterface.OnClickListener) null); alert.show(); } } @Override protected void onCancelled() { super.onCancelled(); progressDialog.cancel(); } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); progressDialog.setProgress(values[0].intValue()); } @Override protected void onPreExecute() { super.onPreExecute(); mHandler.postDelayed( new Runnable() { public void run() { if (!progressDialog.isCancelled()) { progressDialog.show(); progressDialog.setProgress(startIndex); } } }, SEARCH_PROGRESS_DELAY); } }; mSearchTask.safeExecute(); }