Java Code Examples for com.afollestad.materialdialogs.MaterialDialog#SingleButtonCallback

The following examples show how to use com.afollestad.materialdialogs.MaterialDialog#SingleButtonCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogUtils.java    From io16experiment-master with Apache License 2.0 6 votes vote down vote up
/**
 * Create an item dialog
 *
 * @param activity
 * @param titleId
 * @param items
 * @param listCallback
 * @param callback
 * @return
 */
public static MaterialDialog createItemDialog(Activity activity, int titleId, int items, MaterialDialog.ListCallback listCallback,
                                              MaterialDialog.SingleButtonCallback callback) {
    Typeface typeface = Typeface.createFromAsset(activity.getAssets(), Constants.APP_FONT);

    MaterialDialog.Builder builder = new MaterialDialog.Builder(activity)
            .items(items)
            .itemsCallback(listCallback)
            .onNegative(callback)
            .negativeText(R.string.dialog_cancel)
            .typeface(typeface, typeface);

    if (titleId > DialogUtils.DEFAULT_TITLE_ID) {
        builder.title(titleId);
    }

    return builder.build();
}
 
Example 2
Source File: DialogHelper.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public static void showFilenameSuggestingDialog(final Context context,
                                                final MaterialDialog.SingleButtonCallback callback,
                                                final MaterialDialog.InputCallback inputCallback, int titleResId) {


    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(titleResId)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .content(R.string.enter_filename)
            .input("", "", inputCallback)
            .onAny(callback);

    MaterialDialog show = builder.show();
    initFilenameInputDialog(show);
}
 
Example 3
Source File: ConnectFragment.java    From io16experiment-master with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    MainActivity.hide();

    if (mSpinner.getSelectedItemPosition() == 0) {
        MaterialDialog.SingleButtonCallback negativeCallback = new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                PreferencesUtils.setBoolean(mActivity, R.string.key_is_connected, true);
                mCallbacks.onLetsGo();
            }
        };

        DialogUtils.createDialog(mActivity, DialogUtils.DEFAULT_TITLE_ID, R.string.dialog_single_device,
                R.string.dialog_i_found_one, R.string.dialog_nope_just_one, true, null, negativeCallback).show();
    } else {
        mCallbacks.onLetsGo();
    }
}
 
Example 4
Source File: MaterialDialogSupport.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 单选dialog 加取消操作
 * @param context
 * @param title
 * @param items
 * @param selectIndex
 * @param callback
 * @param negativeCallback
 */
public static void openChoiceDialog(Context context, String title, String[] items, int selectIndex,
                                    MaterialDialog.ListCallbackSingleChoice callback, MaterialDialog.SingleButtonCallback negativeCallback) {
    new MaterialDialog.Builder(context)
            .title(title)
            .items(items)
            .itemsCallbackSingleChoice(selectIndex, callback)
            .positiveText(R.string.positive)
            .negativeText(R.string.cancel)
            .onNegative(negativeCallback)
            .negativeColor(Color.parseColor("#9B9B9B"))
            .show();
}
 
Example 5
Source File: LinksContainerView.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reportPost(int position) {
    MaterialDialog.SingleButtonCallback callback = new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            linksPresenter.report(position);
        }
    };
    LinksHelper.callReportDialog(dialogUtil, callback);
}
 
Example 6
Source File: DialogHelper.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
public static void alertDialog(Context context, String title, String msg, MaterialDialog.SingleButtonCallback onPositive) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(title)
            .onPositive(onPositive)
            .content(msg)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .show();
}
 
Example 7
Source File: DonateDialog.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@NonNull
private MaterialDialog initDialog() {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity())
            .iconRes(R.drawable.ic_gift_white_24dp)
            .title(R.string.donate_dialog_title)
            .customView(R.layout.dialog_donate, false)
            .neutralText(R.string.close);

    final IConfiguration configuration = AppHeap.getInstance().getConfiguration();
    final boolean hasApl = configuration.getBilling().hasAlternativePaymentMethods();
    if (!hasApl) return builder.build();

    final Bitcoin btc = new Bitcoin();
    final PayPal pp = new PayPal();

    MaterialDialog.SingleButtonCallback callback = new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog materialDialog,
                            @NonNull DialogAction dialogAction) {
            if (dialogAction == DialogAction.POSITIVE) {
                startPaymentIntentWithWarningAlertDialog(CoinUtils.getPaymentIntent(btc));
            } else if (dialogAction == DialogAction.NEGATIVE) {
                startPaymentIntentWithWarningAlertDialog(CoinUtils.getPaymentIntent(pp));
            } else if (dialogAction == DialogAction.NEUTRAL) {
                dismiss();
            }
        }
    };
    return builder
            .positiveText(btc.getNameResource())
            .negativeText(pp.getNameResource())
            .onPositive(callback)
            .onNegative(callback)
            .onNeutral(callback)
            .autoDismiss(false)
            .build();
}
 
Example 8
Source File: BaseFragment.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
static void areYouSure(@NonNull Activity activity, String contentText, MaterialDialog.SingleButtonCallback positiveSingleButtonCallback, MaterialDialog.SingleButtonCallback negativeSingleButtonCallback) {
    new MaterialDialog.Builder(activity).title(R.string.areyousure)
            .content(contentText)
            .iconAttr(android.R.attr.alertDialogIcon)
            .positiveText(android.R.string.yes)
            .negativeText(android.R.string.no)
            .onPositive(positiveSingleButtonCallback)
            .onNegative(negativeSingleButtonCallback)
            .show();
}
 
Example 9
Source File: MaterialDialogSupport.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void openDialog(Context context, String title, String message, String positiveText, String cancelText, MaterialDialog.SingleButtonCallback callback) {
    new MaterialDialog.Builder(context)
            .title(title)
            .content(message)
            .positiveText(positiveText)
            .negativeText(cancelText)
            .negativeColor(Color.parseColor("#9B9B9B"))
            .onPositive(callback)
            .show();
}
 
Example 10
Source File: LogcatActivity.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
private void completePartialSelect() {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    COMPLETE_PARTIAL_SELECT_REQUEST);
            return;
        }
        if (!SaveLogHelper.checkSdCard(this)) {
            cancelPartialSelect();
            return;
        }

        MaterialDialog.InputCallback onClickListener = (materialDialog, charSequence) -> {
            if (DialogHelper.isInvalidFilename(charSequence)) {
                cancelPartialSelect();
                Toast.makeText(LogcatActivity.this, R.string.enter_good_filename, Toast.LENGTH_SHORT).show();
            } else {
                String filename = charSequence.toString();
                if (partiallySelectedLogLines.size() == 2)
                    savePartialLog(filename, partiallySelectedLogLines.get(0), partiallySelectedLogLines.get(1));
            }
        };


        MaterialDialog.SingleButtonCallback onCancelListener = (dialog, which) -> {
            if(which == DialogAction.NEGATIVE) {
                cancelPartialSelect();
            }
        };

        DialogHelper.showFilenameSuggestingDialog(this, onCancelListener, onClickListener, R.string.save_log);

    }
 
Example 11
Source File: MaterialDialogSupport.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 单个按钮 提示对话框
 * @param context
 * @param message
 * @param positiveCallback
 */
public static void openAlertDialog(Context context, String message, MaterialDialog.SingleButtonCallback positiveCallback) {
    new MaterialDialog.Builder(context)
            .title(R.string.hint)
            .content(message)
            .positiveText(R.string.positive)
            .onPositive(positiveCallback)
            .show();
}
 
Example 12
Source File: DialogHelper.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
public static void showFilenameSuggestingDialog(final Context context,
                                                final MaterialDialog.SingleButtonCallback callback, final MaterialDialog.InputCallback inputCallback, int titleResId) {


    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(titleResId)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .content(R.string.enter_filename)
            .input("", "", inputCallback)
            .onAny(callback);

    MaterialDialog show = builder.show();
    initFilenameInputDialog(show);
}
 
Example 13
Source File: MaterialDialogSupport.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 打开自定义界面 dialog
 * @param context
 * @param title
 * @param viewLayout
 * @param positiveCallback
 */
public static MaterialDialog openCustomViewDialog(Context context, String title, int viewLayout, MaterialDialog.SingleButtonCallback positiveCallback) {
    return new MaterialDialog.Builder(context)
            .title(title)
            .customView(viewLayout, true)
            .positiveText(R.string.positive)
            .negativeText(R.string.cancel)
            .negativeColor(Color.parseColor("#9B9B9B"))
            .onPositive(positiveCallback).show();
}
 
Example 14
Source File: LinksHelper.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
public static void callReportDialog(DialogUtil dialogUtil, MaterialDialog.SingleButtonCallback callback) {
    dialogUtil.build()
            .title("Report Post?")
            .positiveText("Report")
            .negativeText("Cancel")
            .onPositive(callback)
            .show();
}
 
Example 15
Source File: LogcatActivity.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private void completePartialSelect() {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    COMPLETE_PARTIAL_SELECT_REQUEST);
            return;
        }
        if (!SaveLogHelper.checkSdCard(this)) {
            cancelPartialSelect();
            return;
        }

        MaterialDialog.InputCallback onClickListener = new MaterialDialog.InputCallback() {

            @Override
            public void onInput(@NonNull MaterialDialog materialDialog, CharSequence charSequence) {
                if (DialogHelper.isInvalidFilename(charSequence)) {
                    cancelPartialSelect();
                    Toast.makeText(LogcatActivity.this, R.string.enter_good_filename, Toast.LENGTH_SHORT).show();
                } else {
                    String filename = charSequence.toString();
                    savePartialLog(filename, partiallySelectedLogLines.get(0), partiallySelectedLogLines.get(1));
                }
            }
        };


        MaterialDialog.SingleButtonCallback onCancelListener = new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (which == DialogAction.NEGATIVE) {
                    cancelPartialSelect();
                }
            }
        };

        DialogHelper.showFilenameSuggestingDialog(this, onCancelListener, onClickListener, R.string.save_log);

    }
 
Example 16
Source File: ImportSpreadsheetDialog.java    From call_manage with MIT License 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);

    //Let's create the custom view
    @SuppressLint("InflateParams")
    View customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_import_spreadsheet, null, false);
    ButterKnife.bind(this, customView);

    MaterialDialog.SingleButtonCallback onPositive = (dialog, which) -> {

        onEditName(mEditName.getText());
        onEditNameIndex(mEditNameIndex.getText());
        onEditNumberIndex(mEditNumberIndex.getText());

        //If one of the inputs shows an error
        if (mEditName.getError() != null || mEditNumberIndex.getError() != null || mEditNameIndex.getError() != null) {
            Utilities.vibrate(getContext(), Utilities.LONG_VIBRATE_LENGTH);
            return;
        }

        if (mBuilder.onImportListener != null) {
            String name = mEditName.getText().toString();
            File excelFile = new File(mEditPath.getText().toString());
            int nameIndex = Integer.parseInt(mEditNameIndex.getText().toString());
            int numberIndex = Integer.parseInt(mEditNumberIndex.getText().toString());

            mBuilder.onImportListener.onImport(
                    new CGroup(name),
                    excelFile,
                    nameIndex,
                    numberIndex);
        }
        dismiss();
    };

    MaterialDialog.SingleButtonCallback onNegative = (dialog, which) -> dialog.dismiss();

    return new MaterialDialog.Builder(getContext())
            .customView(customView, false)
            .title("Import contacts from spreadsheet")
            .positiveText("Import")
            .negativeText("Cancel")
            .autoDismiss(false)
            .onPositive(onPositive)
            .onNegative(onNegative)
            .build();
}
 
Example 17
Source File: SaveConfirmDialog.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
public SaveConfirmDialog(Context context, String filename, MaterialDialog.SingleButtonCallback callback) {
    super(context);
    this.callback = callback;
    this.filename = filename;
}
 
Example 18
Source File: DialogUtils.java    From io16experiment-master with Apache License 2.0 4 votes vote down vote up
/**
 * Create a MaterialDesign dialog
 *
 * @param activity
 * @param titleId
 * @param messageId
 * @param layoutId
 * @param positiveTextId
 * @param negativeTextId
 * @param cancelable
 * @param positiveCallback
 * @param negativeCallback
 * @param formatArgs
 * @return
 */
private static MaterialDialog createDialogBase(Activity activity, int titleId, int messageId, int layoutId, int positiveTextId,
                                               int negativeTextId, boolean cancelable,
                                               MaterialDialog.SingleButtonCallback positiveCallback,
                                               MaterialDialog.SingleButtonCallback negativeCallback, Object... formatArgs) {
    Typeface typeface = Typeface.createFromAsset(activity.getAssets(), Constants.APP_FONT);

    if (negativeCallback == null) {
        negativeCallback = new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                dialog.dismiss();
            }
        };
    }

    MaterialDialog.Builder builder = new MaterialDialog.Builder(activity)
            .cancelable(cancelable)
            .onPositive(positiveCallback)
            .onNegative(negativeCallback)
            .typeface(typeface, typeface);

    if (titleId > DEFAULT_TITLE_ID) {
        builder.title(titleId);
    }

    if (messageId > DEFAULT_MESSAGE_ID) {
        builder.content(activity.getString(messageId, formatArgs));
    }

    if (layoutId > DEFAULT_LAYOUT_ID) {
        builder.customView(layoutId, true);
    }

    if (positiveTextId > DEFAULT_POSITIVE_TEXT_ID) {
        builder.positiveText(positiveTextId);
    }

    if (negativeTextId > DEFAULT_NEGATIVE_TEXT_ID) {
        builder.negativeText(negativeTextId);
    }

    return builder.build();
}
 
Example 19
Source File: ProfileDialog.java    From andela-med-manager with Apache License 2.0 4 votes vote down vote up
public static ProfileDialog newInstance(MaterialDialog.SingleButtonCallback buttonCallback) {
    callback = buttonCallback;
    return new ProfileDialog();
}
 
Example 20
Source File: DialogUtils.java    From io16experiment-master with Apache License 2.0 3 votes vote down vote up
/**
 * Create a MaterialDesign dialog
 *
 * @param activity
 * @param titleId
 * @param messageId
 * @param positiveTextId
 * @param negativeTextId
 * @param cancelable
 * @param positiveCallback
 * @param negativeCallback
 * @return
 */
public static MaterialDialog createDialog(Activity activity, int titleId, int messageId, int positiveTextId, int negativeTextId,
                                          boolean cancelable, MaterialDialog.SingleButtonCallback positiveCallback,
                                          MaterialDialog.SingleButtonCallback negativeCallback) {
    return createDialogBase(activity, titleId, messageId, DEFAULT_LAYOUT_ID, positiveTextId, negativeTextId,
            cancelable, positiveCallback, negativeCallback);
}