MiniumApps/launcher3/src/main/java/co/siempo/phone/activities/NotesEditActivity.java
/**
     * Implementation of AlertDialogs such as
     * - colorPickerDialog, fontDialog and saveChangesDialog -
     *
     * @param context The Activity context of the dialogs; in this case NotesEditActivity context
     */
Implementation of AlertDialogs such as
- colorPickerDialog, fontDialog and saveChangesDialog

@param context The Activity context of the dialogs; in this case NotesEditActivity context
Implementation of AlertDialogs such as - colorPickerDialog fontDialog and saveChangesDialog @param context The Activity context of the dialogs ; in this case NotesEditActivity context
protected void initDialogs(Context context) {
        colorPickerDialog = ColorPickerDialog.newInstance(R.string.title_noteColor,
                colourArrResId, Color.parseColor(colour), 3,
                isTablet(this) ? ColorPickerDialog.SIZE_LARGE : ColorPickerDialog.SIZE_SMALL);
        colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
            @Override
            public void onColorSelected(int color) {
                String selectedColourAsString = String.format("#%06X", (0xFFFFFF & color));
                for (String aColour : colourArr)
                    if (aColour.equals(selectedColourAsString))
                        colour = aColour;
                relativeLayoutEdit.setBackgroundColor(Color.parseColor(colour));
            }
        });
        fontDialog = new AlertDialog.Builder(context)
                .setTitle(R.string.title_fontSize)
                .setItems(fontSizeNameArr, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        fontSize = fontSizeArr[which];
                        bodyEdit.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
                    }
                })
                .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create();
        saveChangesDialog = new AlertDialog.Builder(context)
                .setMessage(R.string.title_saveChanges)
                .setPositiveButton(R.string.label_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (!isEmpty(titleEdit))
                            saveChanges();
                        else
                            toastEditTextCannotBeEmpty();
                    }
                })
                .setNegativeButton(R.string.label_no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (bundle != null && bundle.getInt(NOTE_REQUEST_CODE) ==
                                NEW_NOTE_REQUEST) {
                            Intent intent = new Intent();
                            intent.putExtra("request", "discard");
                            setResult(RESULT_CANCELED, intent);
                            imm.hideSoftInputFromWindow(titleEdit.getWindowToken(), 0);
                            dialog.dismiss();
                            finish();
                            overridePendingTransition(0, 0);
                        }
                    }
                })
                .create();
    }
protected void initDialogs ( Context context ) { colorPickerDialog = ColorPickerDialog . newInstance ( R . string . title_noteColor , colourArrResId , Color . parseColor ( colour ) , 3 , isTablet ( this ) ? ColorPickerDialog . SIZE_LARGE : ColorPickerDialog . SIZE_SMALL ) ; colorPickerDialog . setOnColorSelectedListener ( new ColorPickerSwatch . OnColorSelectedListener ( ) { @ Override public void onColorSelected ( int color ) { String selectedColourAsString = String . format ( "#%06X" , ( 0xFFFFFF & color ) ) ; for ( String aColour : colourArr ) if ( aColour . equals ( selectedColourAsString ) ) colour = aColour ; relativeLayoutEdit . setBackgroundColor ( Color . parseColor ( colour ) ) ; } } ) ; fontDialog = new AlertDialog . Builder ( context ) . setTitle ( R . string . title_fontSize ) . setItems ( fontSizeNameArr , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { fontSize = fontSizeArr [ which ] ; bodyEdit . setTextSize ( TypedValue . COMPLEX_UNIT_SP , fontSize ) ; } } ) . setNeutralButton ( android . R . string . cancel , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) . create ( ) ; saveChangesDialog = new AlertDialog . Builder ( context ) . setMessage ( R . string . title_saveChanges ) . setPositiveButton ( R . string . label_yes , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { if ( ! isEmpty ( titleEdit ) ) saveChanges ( ) ; else toastEditTextCannotBeEmpty ( ) ; } } ) . setNegativeButton ( R . string . label_no , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { if ( bundle != null && bundle . getInt ( NOTE_REQUEST_CODE ) == NEW_NOTE_REQUEST ) { Intent intent = new Intent ( ) ; intent . putExtra ( "request" , "discard" ) ; setResult ( RESULT_CANCELED , intent ) ; imm . hideSoftInputFromWindow ( titleEdit . getWindowToken ( ) , 0 ) ; dialog . dismiss ( ) ; finish ( ) ; overridePendingTransition ( 0 , 0 ) ; } } } ) . create ( ) ; }
Implementation of AlertDialogs such as
 - colorPickerDialog, fontDialog and saveChangesDialog
Implementation of AlertDialogs such as - colorPickerDialog fontDialog and saveChangesDialog
// Colour picker dialog // Colour picker listener in colour picker dialog // Format selected colour to string // Check which colour is it and equal to main colour // Re-set background colour // Font size picker dialog // Font size updated with new pick // 'Save changes?' dialog // If 'Yes' clicked -> check if title is empty // If title not empty -> save and go back; Otherwise toast // If 'No' clicked in new note -> put extra 'discard' to show toast