MiniumApps/launcher3/src/main/java/co/siempo/phone/activities/NoteListActivity.java
/**
     * Callback method for 'searchView' menu item widget text change
     *
     * @param s String which changed
     * @return true if text changed and logic finished, false otherwise
     */
Callback method for 'searchView' menu item widget text change
@param s String which changed
@return true if text changed and logic finished, false otherwise
Callback method for ' searchView ' menu item widget text change @param s String which changed @return true if text changed and logic finished false otherwise
@Override
    public boolean onQueryTextChange(String s) {
        s = s.toLowerCase(); 
        if (s.length() > 0) {
            JSONArray notesFound = new JSONArray();
            realIndexesOfSearchResults = new ArrayList<>();
            for (int i = 0; i < notes.length(); i++) {
                JSONObject note = null;
                try {
                    note = notes.getJSONObject(i);
                } catch (JSONException e) {
                    CoreApplication.getInstance().logException(e);
                    e.printStackTrace();
                }
                if (note != null) {
                    try {
                        if (note.getString(NOTE_TITLE).toLowerCase().contains(s) ||
                                note.getString(NOTE_BODY).toLowerCase().contains(s)) {
                            notesFound.put(note);
                            realIndexesOfSearchResults.add(i);
                        }
                    } catch (JSONException e) {
                        CoreApplication.getInstance().logException(e);
                        e.printStackTrace();
                    }
                }
            }
            NoteAdapter searchAdapter = new NoteAdapter(NoteListActivity.this, notesFound);
            listView.setAdapter(searchAdapter);
        }
        else {
            realIndexesOfSearchResults = new ArrayList<>();
            for (int i = 0; i < notes.length(); i++)
                realIndexesOfSearchResults.add(i);
            adapter = new NoteAdapter(NoteListActivity.this, notes);
            listView.setAdapter(adapter);
        }
        return false;
    }
@ Override public boolean onQueryTextChange ( String s ) { s = s . toLowerCase ( ) ; if ( s . length ( ) > 0 ) { JSONArray notesFound = new JSONArray ( ) ; realIndexesOfSearchResults = new ArrayList < > ( ) ; for ( int i = 0 ; i < notes . length ( ) ; i ++ ) { JSONObject note = null ; try { note = notes . getJSONObject ( i ) ; } catch ( JSONException e ) { CoreApplication . getInstance ( ) . logException ( e ) ; e . printStackTrace ( ) ; } if ( note != null ) { try { if ( note . getString ( NOTE_TITLE ) . toLowerCase ( ) . contains ( s ) || note . getString ( NOTE_BODY ) . toLowerCase ( ) . contains ( s ) ) { notesFound . put ( note ) ; realIndexesOfSearchResults . add ( i ) ; } } catch ( JSONException e ) { CoreApplication . getInstance ( ) . logException ( e ) ; e . printStackTrace ( ) ; } } } NoteAdapter searchAdapter = new NoteAdapter ( NoteListActivity . this , notesFound ) ; listView . setAdapter ( searchAdapter ) ; } else { realIndexesOfSearchResults = new ArrayList < > ( ) ; for ( int i = 0 ; i < notes . length ( ) ; i ++ ) realIndexesOfSearchResults . add ( i ) ; adapter = new NoteAdapter ( NoteListActivity . this , notes ) ; listView . setAdapter ( adapter ) ; } return false ; }
Callback method for 'searchView' menu item widget text change
 @param s String which changed
 @return true if text changed and logic finished, false otherwise
Callback method for ' searchView ' menu item widget text change @param s String which changed @return true if text changed and logic finished false otherwise
// Turn string into lowercase // If query text length longer than 0 // Create new JSONArray and reset realIndexes array // Loop through main notes list // Get note at position i // If note not null and title/body contain query text // -> Put in new notes array and add i to realIndexes array // Create and set adapter with notesFound to refresh ListView // If query text length is 0 -> re-init realIndexes array (0 to length) and reset adapter