@@ -152,14 +152,13 @@ public class MainActivity extends AppCompatActivity implements FileDialog.OnFile
152152 private Menu menu ;
153153 private final BinaryStatusHandler binaryStatus = new BinaryStatusHandler (this );
154154 private BinarySearch binarySearch ;
155- private SearchParameters searchParameters = null ;
156155 private View searchStatusPanel ;
157156 private Runnable postSaveAsAction = null ;
158157 private boolean keyboardShown = false ;
159158 private boolean dataInspectorShown = true ;
160159 private long lastBackKeyPressTime = -1 ;
161160 private long lastReleaseBackKeyPressTime = -1 ;
162- private BasicValuesPositionColorModifier basicValuesPositionColorModifier = new BasicValuesPositionColorModifier ();
161+ private final BasicValuesPositionColorModifier basicValuesPositionColorModifier = new BasicValuesPositionColorModifier ();
163162 private FallbackFileType fallbackFileType = FallbackFileType .FILE ;
164163
165164 private final BinarySearchService .SearchStatusListener searchStatusListener = new BinarySearchService .SearchStatusListener () {
@@ -189,6 +188,12 @@ public void clearStatus() {
189188// editorModificationListener.modified();
190189// }
191190 updateCurrentDocumentSize ();
191+ ApplicationContext application = (ApplicationContext ) getApplication ();
192+ if (application .isSearchActive ()) {
193+ binarySearch .cancelSearch ();
194+ binarySearch .clearSearch ();
195+ hideSearchStatusPanel ();
196+ }
192197 };
193198 private final SelectionChangedListener codeAreaSelectionChangedListener = () -> {
194199 binaryStatus .setSelectionRange (codeArea .getSelection ());
@@ -289,6 +294,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
289294 basicValuesInspector .registerFocusPainter (basicValuesPositionColorModifier );
290295
291296 basicValuesInspectorView .setNextFocusUpId (R .id .toolbar );
297+ if (application .isSearchActive ()) {
298+ showSearchStatusPanel ();
299+ SearchCodeAreaColorAssessor searchAssessor = CodeAreaAndroidUtils .findColorAssessor ((ColorAssessorPainterCapable ) codeArea .getPainter (), SearchCodeAreaColorAssessor .class );
300+ updateSearchStatusPanel (searchAssessor .getCurrentMatchIndex (), searchAssessor .getMatches ().size ());
301+ }
292302
293303 applySettings ();
294304
@@ -432,6 +442,8 @@ private void showSearchStatusPanel() {
432442 searchStatus .setText (resources .getString (R .string .search_in_progress ));
433443
434444 mainView .addView (searchStatusPanel , 2 );
445+ ApplicationContext application = (ApplicationContext ) getApplication ();
446+ application .setSearchActive (true );
435447 }
436448 }
437449
@@ -440,6 +452,8 @@ private void hideSearchStatusPanel() {
440452 int searchStatusPanelIndex = mainView .indexOfChild (searchStatusPanel );
441453 if (searchStatusPanelIndex >= 0 ) {
442454 mainView .removeViewAt (searchStatusPanelIndex );
455+ ApplicationContext application = (ApplicationContext ) getApplication ();
456+ application .setSearchActive (false );
443457 }
444458 }
445459
@@ -462,8 +476,6 @@ private void updateSearchStatusPanel(int matchPosition, int matchesCount) {
462476
463477 @ Override
464478 protected void onDestroy () {
465- super .onDestroy ();
466-
467479 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
468480 codeArea .removeOnUnhandledKeyEventListener ((View .OnUnhandledKeyEventListener ) codeAreaOnUnhandledKeyListener );
469481 }
@@ -475,6 +487,8 @@ protected void onDestroy() {
475487 fileHandler .getUndoRedo ().removeChangeListener (codeAreaChangeListener );
476488 BinEdCodeAreaAssessor codeAreaAssessor = fileHandler .getCodeAreaAssessor ();
477489 codeAreaAssessor .removeColorModifier (basicValuesPositionColorModifier );
490+
491+ super .onDestroy ();
478492 }
479493
480494 private void processIntent (Intent intent ) {
@@ -931,16 +945,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
931945 return true ;
932946 } else if (id == R .id .action_search ) {
933947 SearchDialog searchDialog = new SearchDialog ();
934- searchDialog .setBinarySearch (binarySearch );
935- searchDialog .setSearchParameters (searchParameters );
936- searchDialog .setTemplateCodeArea (codeArea );
937- searchDialog .setSearchStatusListener (searchStatusListener );
938- searchDialog .setOnCloseListener (() -> {
939- SearchParameters usedSearchParameters = searchDialog .getSearchParameters ();
940- if (usedSearchParameters != null ) {
941- searchParameters = usedSearchParameters ;
942- }
943- });
944948 searchDialog .show (getSupportFragmentManager (), "searchDialog" );
945949 return true ;
946950 } else if (id == R .id .action_delete ) {
@@ -1456,12 +1460,16 @@ public void buttonActionPreviousMatch(View view) {
14561460 SearchCodeAreaColorAssessor searchAssessor = CodeAreaAndroidUtils .findColorAssessor ((ColorAssessorPainterCapable ) codeArea .getPainter (), SearchCodeAreaColorAssessor .class );
14571461 searchAssessor .setCurrentMatchIndex (searchAssessor .getCurrentMatchIndex () - 1 );
14581462 updateSearchStatusPanel (searchAssessor .getCurrentMatchIndex (), searchAssessor .getMatches ().size ());
1463+ codeArea .revealPosition (searchAssessor .getCurrentMatch ().getPosition (), 0 , codeArea .getActiveSection ());
1464+ codeArea .repaint ();
14591465 }
14601466
14611467 public void buttonActionNextMatch (View view ) {
14621468 SearchCodeAreaColorAssessor searchAssessor = CodeAreaAndroidUtils .findColorAssessor ((ColorAssessorPainterCapable ) codeArea .getPainter (), SearchCodeAreaColorAssessor .class );
14631469 searchAssessor .setCurrentMatchIndex (searchAssessor .getCurrentMatchIndex () + 1 );
14641470 updateSearchStatusPanel (searchAssessor .getCurrentMatchIndex (), searchAssessor .getMatches ().size ());
1471+ codeArea .revealPosition (searchAssessor .getCurrentMatch ().getPosition (), 0 , codeArea .getActiveSection ());
1472+ codeArea .repaint ();
14651473 }
14661474
14671475 public void buttonActionHideSearchPanel (View view ) {
@@ -1470,6 +1478,32 @@ public void buttonActionHideSearchPanel(View view) {
14701478 hideSearchStatusPanel ();
14711479 }
14721480
1481+ @ Nullable
1482+ public BinarySearch getBinarySearch () {
1483+ return binarySearch ;
1484+ }
1485+
1486+ @ Nullable
1487+ public SearchParameters getSearchParameters () {
1488+ ApplicationContext application = (ApplicationContext ) getApplication ();
1489+ return application .getSearchParameters ();
1490+ }
1491+
1492+ public void setSearchParameters (SearchParameters searchParameters ) {
1493+ ApplicationContext application = (ApplicationContext ) getApplication ();
1494+ application .setSearchParameters (searchParameters );
1495+ }
1496+
1497+ @ Nullable
1498+ public BinarySearchService .SearchStatusListener getSearchStatusListener () {
1499+ return searchStatusListener ;
1500+ }
1501+
1502+ @ Nullable
1503+ public CodeArea getCodeArea () {
1504+ return codeArea ;
1505+ }
1506+
14731507 public static boolean isGoogleTV (Context context ) {
14741508 final PackageManager pm = context .getPackageManager ();
14751509 return pm .hasSystemFeature (PackageManager .FEATURE_LEANBACK );
0 commit comments