@@ -360,7 +360,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
360360 _menuSearchViewForViewMode .setQueryHint (getString (R .string .search ));
361361 _menuSearchViewForViewMode .setOnQueryTextListener (new SearchView .OnQueryTextListener () {
362362 private String searchText = "" ;
363- private final Runnable findTask = new Runnable () {
363+ private final Runnable searchTask = new Runnable () {
364364 @ Override
365365 public void run () {
366366 _webView .findAllAsync (searchText );
@@ -371,9 +371,9 @@ public void run() {
371371 @ Override
372372 public boolean onQueryTextChange (String text ) {
373373 Handler handler = _webView .getHandler ();
374- handler .removeCallbacks (findTask );
374+ handler .removeCallbacks (searchTask );
375375 searchText = text ;
376- handler .postDelayed (findTask , 500 );
376+ handler .postDelayed (searchTask , 500 );
377377 return true ;
378378 }
379379
@@ -387,59 +387,60 @@ public boolean onQueryTextSubmit(String query) {
387387 }
388388 });
389389
390+ ViewGroup mSearchPlate = null ;
390391 try {
391392 Field mSearchPlateField = SearchView .class .getDeclaredField ("mSearchPlate" );
392393 mSearchPlateField .setAccessible (true );
393- ViewGroup mSearchPlate = (ViewGroup ) mSearchPlateField .get (_menuSearchViewForViewMode );
394- if (mSearchPlate == null ) {
395- _menuSearchViewForViewMode .setSubmitButtonEnabled (true );
396- return ;
397- }
398-
399- Context searchViewContext = _menuSearchViewForViewMode .getContext ();
400- LinearLayout linearLayout = new LinearLayout (searchViewContext );
401-
402- // Add search result TextView
403- TextView resultTextView = new TextView (searchViewContext );
404- resultTextView .setGravity (Gravity .CENTER );
405- LinearLayout .LayoutParams layoutParams = new LinearLayout .LayoutParams (
406- LinearLayout .LayoutParams .WRAP_CONTENT ,
407- LinearLayout .LayoutParams .MATCH_PARENT
408- );
409- layoutParams .setMarginEnd (14 );
410- resultTextView .setLayoutParams (layoutParams );
411- linearLayout .addView (resultTextView );
412-
413- // Add previous match Button
414- ImageButton previousButton = new ImageButton (searchViewContext );
415- previousButton .setImageResource (R .drawable .ic_baseline_keyboard_arrow_up_24 );
416- linearLayout .addView (previousButton );
417-
418- // Add next match Button
419- ImageButton nextButton = new ImageButton (searchViewContext );
420- nextButton .setImageResource (R .drawable .ic_baseline_keyboard_arrow_down_24 );
421- linearLayout .addView (nextButton );
422-
423- // Apply to SearchView
424- mSearchPlate .addView (linearLayout , 1 );
425-
426- // Set listeners
427- previousButton .setOnClickListener (v -> _webView .findNext (false ));
428- nextButton .setOnClickListener (v -> _webView .findNext (true ));
429- _webView .setFindListener ((activeMatchOrdinal , numberOfMatches , isDoneCounting ) -> {
430- if (isDoneCounting ) {
431- String searchResult = "" ;
432- if (numberOfMatches > 0 ) {
433- searchResult = (activeMatchOrdinal + 1 ) + "/" + numberOfMatches ;
434- }
435- resultTextView .setText (searchResult );
436- }
437- });
394+ mSearchPlate = (ViewGroup ) mSearchPlateField .get (_menuSearchViewForViewMode );
438395 } catch (NoSuchFieldException e ) {
439396 Log .e (DocumentEditAndViewFragment .class .getName (), e .getMessage () == null ? "" : e .getMessage ());
440397 } catch (IllegalAccessException e ) {
441398 throw new RuntimeException (e );
442399 }
400+ if (mSearchPlate == null ) {
401+ _menuSearchViewForViewMode .setSubmitButtonEnabled (true );
402+ return ;
403+ }
404+
405+ Context searchViewContext = _menuSearchViewForViewMode .getContext ();
406+ LinearLayout linearLayout = new LinearLayout (searchViewContext );
407+
408+ // Add search result TextView
409+ TextView resultTextView = new TextView (searchViewContext );
410+ resultTextView .setGravity (Gravity .CENTER );
411+ LinearLayout .LayoutParams layoutParams = new LinearLayout .LayoutParams (
412+ LinearLayout .LayoutParams .WRAP_CONTENT ,
413+ LinearLayout .LayoutParams .MATCH_PARENT
414+ );
415+ layoutParams .setMarginEnd (14 );
416+ resultTextView .setLayoutParams (layoutParams );
417+ linearLayout .addView (resultTextView );
418+
419+ // Add previous match Button
420+ ImageButton previousButton = new ImageButton (searchViewContext );
421+ previousButton .setImageResource (R .drawable .ic_baseline_keyboard_arrow_up_24 );
422+ linearLayout .addView (previousButton );
423+
424+ // Add next match Button
425+ ImageButton nextButton = new ImageButton (searchViewContext );
426+ nextButton .setImageResource (R .drawable .ic_baseline_keyboard_arrow_down_24 );
427+ linearLayout .addView (nextButton );
428+
429+ // Apply to SearchView
430+ mSearchPlate .addView (linearLayout , 1 );
431+
432+ // Set listeners
433+ previousButton .setOnClickListener (v -> _webView .findNext (false ));
434+ nextButton .setOnClickListener (v -> _webView .findNext (true ));
435+ _webView .setFindListener ((activeMatchOrdinal , numberOfMatches , isDoneCounting ) -> {
436+ if (isDoneCounting ) {
437+ String searchResult = "" ;
438+ if (numberOfMatches > 0 ) {
439+ searchResult = (activeMatchOrdinal + 1 ) + "/" + numberOfMatches ;
440+ }
441+ resultTextView .setText (searchResult );
442+ }
443+ });
443444 }
444445
445446 // Set various initial states
0 commit comments