MiniumApps/launcher3/src/main/java/co/siempo/phone/activities/NoteListActivity.java
/**
     * Implementation of AlertDialogs such as
     * - backupCheckDialog, backupOKDialog, restoreCheckDialog, restoreFailedDialog -
     *
     * @param context The Activity context of the dialogs; in this case DashboardActivity context
     */


@param context The Activity context of the dialogs; in this case DashboardActivity context
@param context The Activity context of the dialogs ; in this case DashboardActivity context
protected void initDialogs(Context context) {
        /*
         * Backup check dialog
         *  If not sure -> dismiss
         *  If yes -> check if notes length > 0
         *    If yes -> save current notes to backup file in backupPath
         */
        backupCheckDialog = new AlertDialog.Builder(context)
                .setTitle(R.string.label_backup)
                .setMessage(R.string.prompt_backup)
                .setPositiveButton(R.string.label_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (notes.length() > 0) {
                            boolean backupSuccessful = saveData(backupPath, notes);
                            if (backupSuccessful)
                                showBackupSuccessfulDialog();
                            else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        getResources().getString(R.string.msg_backupUnsuccessful),
                                        Toast.LENGTH_SHORT);
                                toast.show();
                            }
                        }
                        else {
                            Toast toast = Toast.makeText(getApplicationContext(),
                                    getResources().getString(R.string.msg_noNotesToBackup),
                                    Toast.LENGTH_SHORT);
                            toast.show();
                        }
                    }
                })
                .setNegativeButton(R.string.label_no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create();
        backupOKDialog = new AlertDialog.Builder(context)
                .setTitle(R.string.title_backupCreated)
                .setMessage(getString(R.string.msg_backupCreated) + " "
                        + backupPath.getAbsolutePath())
                .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create();
        /*
         * Restore check dialog
         *  If not sure -> dismiss
         *  If yes -> check if backup notes exists
         *    If not -> display restore failed dialog
         *    If yes -> retrieve notes from backup file and store into local file
         */
        restoreCheckDialog = new AlertDialog.Builder(context)
                .setTitle(R.string.label_restore)
                .setMessage(R.string.prompt_restore)
                .setPositiveButton(R.string.label_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONArray tempNotes = retrieveData(backupPath);
                        if (tempNotes != null) {
                            boolean restoreSuccessful = saveData(localPath, tempNotes);
                            if (restoreSuccessful) {
                                notes = tempNotes;
                                adapter = new NoteAdapter(NoteListActivity.this, notes);
                                listView.setAdapter(adapter);
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        getResources().getString(R.string.msg_notesRestored),
                                        Toast.LENGTH_SHORT);
                                toast.show();
                                if (notes.length() == 0)
                                    noNotes.setVisibility(View.VISIBLE);
                                else
                                    noNotes.setVisibility(View.INVISIBLE);
                            }
                            else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        getResources().getString(R.string.msg_restoreUnsuccessful),
                                        Toast.LENGTH_SHORT);
                                toast.show();
                            }
                        }
                        else
                            showRestoreFailedDialog();
                    }
                })
                .setNegativeButton(R.string.label_no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create();
        restoreFailedDialog = new AlertDialog.Builder(context)
                .setTitle(R.string.title_restoreFailed)
                .setMessage(R.string.msg_restoreFailed)
                .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create();
    }
protected void initDialogs ( Context context ) { /*
         * Backup check dialog
         *  If not sure -> dismiss
         *  If yes -> check if notes length > 0
         *    If yes -> save current notes to backup file in backupPath
         */ backupCheckDialog = new AlertDialog . Builder ( context ) . setTitle ( R . string . label_backup ) . setMessage ( R . string . prompt_backup ) . setPositiveButton ( R . string . label_yes , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { if ( notes . length ( ) > 0 ) { boolean backupSuccessful = saveData ( backupPath , notes ) ; if ( backupSuccessful ) showBackupSuccessfulDialog ( ) ; else { Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_backupUnsuccessful ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; } } else { Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_noNotesToBackup ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; } } } ) . setNegativeButton ( R . string . label_no , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) . create ( ) ; backupOKDialog = new AlertDialog . Builder ( context ) . setTitle ( R . string . title_backupCreated ) . setMessage ( getString ( R . string . msg_backupCreated ) + " " + backupPath . getAbsolutePath ( ) ) . setNeutralButton ( android . R . string . ok , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) . create ( ) ; /*
         * Restore check dialog
         *  If not sure -> dismiss
         *  If yes -> check if backup notes exists
         *    If not -> display restore failed dialog
         *    If yes -> retrieve notes from backup file and store into local file
         */ restoreCheckDialog = new AlertDialog . Builder ( context ) . setTitle ( R . string . label_restore ) . setMessage ( R . string . prompt_restore ) . setPositiveButton ( R . string . label_yes , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { JSONArray tempNotes = retrieveData ( backupPath ) ; if ( tempNotes != null ) { boolean restoreSuccessful = saveData ( localPath , tempNotes ) ; if ( restoreSuccessful ) { notes = tempNotes ; adapter = new NoteAdapter ( NoteListActivity . this , notes ) ; listView . setAdapter ( adapter ) ; Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_notesRestored ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; if ( notes . length ( ) == 0 ) noNotes . setVisibility ( View . VISIBLE ) ; else noNotes . setVisibility ( View . INVISIBLE ) ; } else { Toast toast = Toast . makeText ( getApplicationContext ( ) , getResources ( ) . getString ( R . string . msg_restoreUnsuccessful ) , Toast . LENGTH_SHORT ) ; toast . show ( ) ; } } else showRestoreFailedDialog ( ) ; } } ) . setNegativeButton ( R . string . label_no , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) . create ( ) ; restoreFailedDialog = new AlertDialog . Builder ( context ) . setTitle ( R . string . title_restoreFailed ) . setMessage ( R . string . msg_restoreFailed ) . setNeutralButton ( android . R . string . ok , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) . create ( ) ; }
Implementation of AlertDialogs such as
 - backupCheckDialog, backupOKDialog, restoreCheckDialog, restoreFailedDialog
Implementation of AlertDialogs such as - backupCheckDialog backupOKDialog restoreCheckDialog restoreFailedDialog
// If note array not empty -> continue // If notes array is empty -> toast backup no notes found // Dialog to display backup was successfully created in backupPath // If backup file exists -> copy backup notes to local file // If no notes -> show 'Press + to add new note' text, invisible otherwise // If restore unsuccessful -> toast restore unsuccessful // If backup file doesn't exist -> show restore failed dialog // Dialog to display restore failed when no backup file found