MiniumApps/launcher3/src/main/java/co/siempo/phone/activities/NoteListActivity.java
/**
     * Callback method when NotesEditActivity finished adding new note or editing existing note
     *
     * @param requestCode requestCode for intent sent, in our case either NEW_NOTE_REQUEST or position
     * @param resultCode  resultCode from activity, either RESULT_OK or RESULT_CANCELED
     * @param data        Data bundle passed back from NotesEditActivity
     */
Callback method when NotesEditActivity finished adding new note or editing existing note
@param requestCode requestCode for intent sent, in our case either NEW_NOTE_REQUEST or position
@param resultCode  resultCode from activity, either RESULT_OK or RESULT_CANCELED
@param data        Data bundle passed back from NotesEditActivity
Callback method when NotesEditActivity finished adding new note or editing existing note @param requestCode requestCode for intent sent in our case either NEW_NOTE_REQUEST or position @param resultCode resultCode from activity either RESULT_OK or RESULT_CANCELED @param data Data bundle passed back from NotesEditActivity
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (searchActive && searchMenu != null)
                searchMenu.collapseActionView();
            Bundle mBundle = null;
            if (data != null)
                mBundle = data.getExtras();
            if (mBundle != null) {
                if (requestCode == NEW_NOTE_REQUEST) {
                    JSONObject newNoteObject = null;
                    try {
                        newNoteObject = new JSONObject();
                        newNoteObject.put(NOTE_TITLE, mBundle.getString(NOTE_TITLE));
                        newNoteObject.put(NOTE_BODY, mBundle.getString(NOTE_BODY));
                        newNoteObject.put(NOTE_COLOUR, mBundle.getString(NOTE_COLOUR));
                        newNoteObject.put(NOTE_FAVOURED, false);
                        newNoteObject.put(NOTE_FONT_SIZE, mBundle.getInt(NOTE_FONT_SIZE));
                        newNoteObject.put(NOTE_HIDE_BODY, mBundle.getBoolean(NOTE_HIDE_BODY));
                        notes.put(newNoteObject);
                    } catch (JSONException e) {
                        CoreApplication.getInstance().logException(e);
                        e.printStackTrace();
                    }
                    if (newNoteObject != null) {
                        adapter.notifyDataSetChanged();
                        Boolean saveSuccessful = saveData(localPath, notes);
                        new EvernoteManager().createNote(newNoteObject);
                        if (saveSuccessful) {
                            Toast toast = Toast.makeText(getApplicationContext(),
                                    getResources().getString(R.string.msg_noteCreated),
                                    Toast.LENGTH_SHORT);
                            toast.show();
                        }
                        if (notes.length() == 0)
                            noNotes.setVisibility(View.VISIBLE);
                        else
                            noNotes.setVisibility(View.INVISIBLE);
                    }
                }
                else {
                    JSONObject newNoteObject = null;
                    try {
                        newNoteObject = notes.getJSONObject(requestCode);
                        newNoteObject.put(NOTE_TITLE, mBundle.getString(NOTE_TITLE));
                        newNoteObject.put(NOTE_BODY, mBundle.getString(NOTE_BODY));
                        newNoteObject.put(NOTE_COLOUR, mBundle.getString(NOTE_COLOUR));
                        newNoteObject.put(NOTE_FONT_SIZE, mBundle.getInt(NOTE_FONT_SIZE));
                        newNoteObject.put(NOTE_HIDE_BODY, mBundle.getBoolean(NOTE_HIDE_BODY));
                        notes.put(requestCode, newNoteObject);
                    } catch (JSONException e) {
                        CoreApplication.getInstance().logException(e);
                        e.printStackTrace();
                    }
                    if (newNoteObject != null) {
                        adapter.notifyDataSetChanged();
                        Boolean saveSuccessful = saveData(localPath, notes);
                        if (saveSuccessful) {
                            Toast toast = Toast.makeText(getApplicationContext(),
                                    getResources().getString(R.string.msg_noteSaved),
                                    Toast.LENGTH_SHORT);
                            toast.show();
                        }
                    }
                }
            }
        } else if (resultCode == RESULT_CANCELED) {
            Bundle mBundle;
            if (data != null && data.hasExtra("request") && requestCode == NEW_NOTE_REQUEST) {
                mBundle = data.getExtras();
                if (mBundle != null && mBundle.getString("request") != null
                        && mBundle.getString("request").equals("discard")) {
                    Toast toast = Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.msg_emptyNoteDiscarded),
                            Toast.LENGTH_SHORT);
                    toast.show();
                }
                if (mBundle != null && mBundle.getString("request") != null
                        && mBundle.getString("request").equals("HOME")) {
                    JSONArray tempNotes = retrieveData(localPath);
                    Tracer.i("All notes: " + tempNotes);
                    if (tempNotes != null) {
                        notes = tempNotes;
                        adapter.setAdapterData(notes);
                        adapter.notifyDataSetChanged();
                    }
                }
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
@ Override protected void onActivityResult ( int requestCode , int resultCode , Intent data ) { if ( resultCode == RESULT_OK ) { if ( searchActive && searchMenu != null ) searchMenu . collapseActionView ( ) ; Bundle mBundle = null ; if ( data != null ) mBundle = data . getExtras ( ) ; if ( mBundle != null ) { if ( requestCode == NEW_NOTE_REQUEST ) { JSONObject newNoteObject = null ; try { newNoteObject = new JSONObject ( ) ; newNoteObject . put ( NOTE_TITLE , mBundle . getString ( NOTE_TITLE ) ) ; newNoteObject . put ( NOTE_BODY , mBundle . getString ( NOTE_BODY ) ) ; newNoteObject . put ( NOTE_COLOUR , mBundle . getString ( NOTE_COLOUR ) ) ; newNoteObject . put ( NOTE_FAVOURED , false ) ; newNoteObject . put ( NOTE_FONT_SIZE , mBundle . getInt ( NOTE_FONT_SIZE ) ) ; newNoteObject . put ( NOTE_HIDE_BODY , mBundle . getBoolean ( NOTE_HIDE_BODY ) ) ; notes . put ( newNoteObject ) ; } catch ( JSONException e ) { CoreApplication . getInstance ( ) . logException ( e ) ; e . printStackTrace ( ) ; } if ( newNoteObject != null ) { adapter . notifyDataSetChanged ( ) ; Boolean saveSuccessful = saveData ( localPath , notes ) ; new EvernoteManager ( ) . createNote ( newNoteObject ) ; if ( saveSuccessful ) { Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_noteCreated ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; } if ( notes . length ( ) == 0 ) noNotes . setVisibility ( View . VISIBLE ) ; else noNotes . setVisibility ( View . INVISIBLE ) ; } } else { JSONObject newNoteObject = null ; try { newNoteObject = notes . getJSONObject ( requestCode ) ; newNoteObject . put ( NOTE_TITLE , mBundle . getString ( NOTE_TITLE ) ) ; newNoteObject . put ( NOTE_BODY , mBundle . getString ( NOTE_BODY ) ) ; newNoteObject . put ( NOTE_COLOUR , mBundle . getString ( NOTE_COLOUR ) ) ; newNoteObject . put ( NOTE_FONT_SIZE , mBundle . getInt ( NOTE_FONT_SIZE ) ) ; newNoteObject . put ( NOTE_HIDE_BODY , mBundle . getBoolean ( NOTE_HIDE_BODY ) ) ; notes . put ( requestCode , newNoteObject ) ; } catch ( JSONException e ) { CoreApplication . getInstance ( ) . logException ( e ) ; e . printStackTrace ( ) ; } if ( newNoteObject != null ) { adapter . notifyDataSetChanged ( ) ; Boolean saveSuccessful = saveData ( localPath , notes ) ; if ( saveSuccessful ) { Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_noteSaved ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; } } } } } else if ( resultCode == RESULT_CANCELED ) { Bundle mBundle ; if ( data != null && data . hasExtra ( "request" ) && requestCode == NEW_NOTE_REQUEST ) { mBundle = data . getExtras ( ) ; if ( mBundle != null && mBundle . getString ( "request" ) != null && mBundle . getString ( "request" ) . equals ( "discard" ) ) { Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_emptyNoteDiscarded ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; } if ( mBundle != null && mBundle . getString ( "request" ) != null && mBundle . getString ( "request" ) . equals ( "HOME" ) ) { JSONArray tempNotes = retrieveData ( localPath ) ; Tracer . i ( "All notes: " + tempNotes ) ; if ( tempNotes != null ) { notes = tempNotes ; adapter . setAdapterData ( notes ) ; adapter . notifyDataSetChanged ( ) ; } } } } super . onActivityResult ( requestCode , resultCode , data ) ; }
Callback method when NotesEditActivity finished adding new note or editing existing note
 @param requestCode requestCode for intent sent, in our case either NEW_NOTE_REQUEST or position
 @param resultCode  resultCode from activity, either RESULT_OK or RESULT_CANCELED
 @param data        Data bundle passed back from NotesEditActivity
Callback method when NotesEditActivity finished adding new note or editing existing note @param requestCode requestCode for intent sent in our case either NEW_NOTE_REQUEST or position @param resultCode resultCode from activity either RESULT_OK or RESULT_CANCELED @param data Data bundle passed back from NotesEditActivity
// If search was active -> call 'searchEnded' method // Get extras // If new note was saved // Add new note to array // If newNoteObject not null -> save notes array to local file and notify adapter // If no notes -> show 'Press + to add new note' text, invisible otherwise // If existing note was updated (saved) // Update array item with new note data // Update note at position 'requestCode' // If newNoteObject not null -> save notes array to local file and notify adapter // If data is not null, has "request" extra and is new note -> get extras to bundle // If new note discarded -> toast empty note discarded // If not null -> equal main notes to retrieved notes