Android dialog with positive, negative and cancel listeners.
public void dialogDeviceEnabling() {
isDialogDeviceEnablingCalled = true;
new MaterialDialog.Builder(this)
.title(R.string.message_cant_connect_device)
.content(R.string.message_prompt_enable_device)
.positiveText(R.string.btn_enabled)
.negativeText(R.string.btn_change_device_id)
.canceledOnTouchOutside(true)
//refresh connecting process
.onPositive((dialog, which) -> {
isDialogDeviceEnablingCalled = false;
performConnect();
})
//go to device scan activity to change device
.onNegative((dialog, which) -> {
discardDialogDeviceEnabling = true;
Intent intent = new Intent(ConnectActivity.this, ScanActivity.class);
isDialogDeviceEnablingCalled = false;
startActivity(intent);
})
//refresh connection process task
.cancelListener(dialogInterface -> {
isDialogDeviceEnablingCalled = false;
performConnect();
})
//show dialog
.show();