app/src/main/java/com/treslines/pagsegurodemo/AppUtil.java
public static void showOkCancelDialog(@NonNull final Context ctx, @NonNull final String msg, final String okBtn, final String cancelBtn, final AlertAction okAction, final AlertAction cancelAction, final AlertAction backPressendAction) {
        if (msg.isEmpty()) {
            throw new IllegalArgumentException("This value can't be empty!");
        }
        final AlertDialog dialog = new AlertDialog.Builder(ctx).setMessage(msg)
                .setPositiveButton((okBtn == null ? "Ok" : okBtn), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (okAction != null) {
                            okAction.perform();
                        }
                    }
                }).setNegativeButton((cancelBtn == null ? "Cancel" : cancelBtn), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (cancelAction != null) {
                            cancelAction.perform();
                        }
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                        if (backPressendAction != null) {
                            backPressendAction.perform();
                        }
                    }
                }).create();
        dialog.show();
    }
/**
     * Shows a confirm dialog with a custom message, custom buttons and custom actions.
     *
     * @param ctx                the apps context. This value can't be null.
     * @param msg                the message to be shown This value can't be null or empty.
     * @param okBtn              the text to be shown in the ok button. If you pass null, ok will be shown per default
     * @param cancelBtn          the text to be shown in the cancel button. If you pass null, cancel will be shown per default
     * @param okAction           the action to be performed as soon as the user presses the ok button. if you pass null, nothing happens.
     * @param cancelAction       the action to be performed as soon as the user presses the cancel button. if you pass null, nothing happens.
     * @param backPressendAction the action to be performed as soon as the user presses the system back button. if you pass null, nothing happens.
     */
Shows a confirm dialog with a custom message, custom buttons and custom actions.
@param ctx                the apps context. This value can't be null.
@param msg                the message to be shown This value can't be null or empty.
@param okBtn              the text to be shown in the ok button. If you pass null, ok will be shown per default
@param cancelBtn          the text to be shown in the cancel button. If you pass null, cancel will be shown per default
@param okAction           the action to be performed as soon as the user presses the ok button. if you pass null, nothing happens.
@param cancelAction       the action to be performed as soon as the user presses the cancel button. if you pass null, nothing happens.
@param backPressendAction the action to be performed as soon as the user presses the system back button. if you pass null, nothing happens.
Shows a confirm dialog with a custom message custom buttons and custom actions . @param ctx the apps context . This value can ' t be null . @param msg the message to be shown This value can ' t be null or empty . @param okBtn the text to be shown in the ok button . If you pass null ok will be shown per default @param cancelBtn the text to be shown in the cancel button . If you pass null cancel will be shown per default @param okAction the action to be performed as soon as the user presses the ok button . if you pass null nothing happens . @param cancelAction the action to be performed as soon as the user presses the cancel button . if you pass null nothing happens . @param backPressendAction the action to be performed as soon as the user presses the system back button . if you pass null nothing happens .
public static void showOkCancelDialog(@NonNull final Context ctx, @NonNull final String msg, final String okBtn, final String cancelBtn, final AlertAction okAction, final AlertAction cancelAction, final AlertAction backPressendAction) {
        if (msg.isEmpty()) {
            throw new IllegalArgumentException("This value can't be empty!");
        }
        final AlertDialog dialog = new AlertDialog.Builder(ctx).setMessage(msg)
                .setPositiveButton((okBtn == null ? "Ok" : okBtn), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (okAction != null) {
                            okAction.perform();
                        }
                    }
                }).setNegativeButton((cancelBtn == null ? "Cancel" : cancelBtn), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (cancelAction != null) {
                            cancelAction.perform();
                        }
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                        if (backPressendAction != null) {
                            backPressendAction.perform();
                        }
                    }
                }).create();
        dialog.show();
    }
public static void showOkCancelDialog ( @ NonNull final Context ctx , @ NonNull final String msg , final String okBtn , final String cancelBtn , final AlertAction okAction , final AlertAction cancelAction , final AlertAction backPressendAction ) { if ( msg . isEmpty ( ) ) { throw new IllegalArgumentException ( "This value can't be empty!" ) ; } final AlertDialog dialog = new AlertDialog . Builder ( ctx ) . setMessage ( msg ) . setPositiveButton ( ( okBtn == null ? "Ok" : okBtn ) , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; if ( okAction != null ) { okAction . perform ( ) ; } } } ) . setNegativeButton ( ( cancelBtn == null ? "Cancel" : cancelBtn ) , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; if ( cancelAction != null ) { cancelAction . perform ( ) ; } } } ) . setOnCancelListener ( new DialogInterface . OnCancelListener ( ) { @ Override public void onCancel ( DialogInterface dialog ) { dialog . dismiss ( ) ; if ( backPressendAction != null ) { backPressendAction . perform ( ) ; } } } ) . create ( ) ; dialog . show ( ) ; }
Shows a confirm dialog with a custom message, custom buttons and custom actions.
Shows a confirm dialog with a custom message custom buttons and custom actions .