I need to have a sort of "blocked alert" that can't be dismissed by the user until some event occurs. So, I created the alert and removed all the buttons from it:
Alert waitingAlert = new Alert(Alert.AlertType.INFORMATION);
waitingAlert.setTitle("Proposta Inviata");
waitingAlert.getButtonTypes().setAll();
waitingAlert.setHeaderText("La proposta รจ stata inviata a " + trade.getPlayer2Name());
waitingAlert.showAndWait();
Then, I need to dismiss it when a particular event occurs. I just tried doing it this way:
waitingAlert.close();
But it doesn't work.
Edit
The panel is shown when an user wants to send a request to another user in the network that needs to be accepted or refused. The principle is that the UI gets blocked until the other user says if he has accepted or refused the request. The request is send through a remote method invokation through a ring network. When I receive the response I want to close dismiss the panel.
To have a dialog that can't be dismissed by the user, but wait on a process, you will need to use dialog.show() as noted by James_D.
However, without buttons, the dialog actually will not close and you need to force it.
//for example
dialog.getButtonTypes().add(ButtonType.CANCEL);
dialog.hide();
dialog.getButtonTypes().remove(ButtonType.CANCEL);
This will allow you to close a dialog which has no buttons.
Related
Edit: The possible duplicates mentioned deals with how to pass credentials and login for Authentication pop ups. My questions here is how to Cancel the Authentication popup.
Is it achievable trough Robot class?
/Edit
I want to Cancel the below Authentication pop up. I tried using Robot class, but not able to Cancel the pop.
Also the code is working, i.e. I am not getting any error.
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
alert.accept() โ Will click on OK button
alert.dismiss() โ Will click on Cancel button
alert.text โ will get the text which is present on the Alert
http://allselenium.info/python-selenium-handle-alerts-prompts-confirmation-popups/
you can try using autoit to achieve your goal of interact with popup.
Software: https://www.autoitscript.com/site/
Here is an example usage: https://www.autoitscript.com/forum/topic/193594-windows-security-continues-to-pop-up-after-credentials-are-enterd/
I want to show a Message Dialog to the user informing him that my application is busy and that he has to wait.
JOptionPane.showMessageDialog(
null,
"Operation in progress",
"Waiting",
JOptionPane.INFORMATION_MESSAGE);
I create this simple message dialog but user can easy close this window. This message dialog must close only from my code.
Instead of using JOptionPane.showMessageDialog() to display the predefined dialog create a new JDialog object yourself and prevent user closing with setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE).
I have this method which basically waits for items in the singleton queue to become empty, there is a background service which is running and the service stops once it removes all items in the queue and process each one by one. This code runs in the main thread, what will happen when I call wait here? will the alert dialog still be showing and blocking the user from performing any other action?
void waitForService() {
openConnectionToUploadQueue();
if(answersQueue.getCount(objInterviewQuestion.getQid()) <= 0){
answersQueue.close();
return;
}
if(!answersQueue.isInterviewUploadServiceRunning()) {
answersQueue.startInterviewUploadService();
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getString(R.string.auto_submit_alert_title));
builder.setCancelable(false);
builder.setMessage(R.string.uploading_pending_answers);
AlertDialog waitForServiceDialog = builder.create();
waitForServiceDialog.show();
while (answersQueue.getCount(objInterviewQuestion.getQid()) > 0) {
// do nothing and keep loop running till answersQueue is empty
}
waitForServiceDialog.dismiss();
}
You should never block UI Thread. When you hold UI Thread for too long, this is when the system will show a dialog saying XXX is not responding and ask user to kill your application.
Instead, you should use a callback style call, and when the service is up, and you receive the method call from callback, you dismiss the dialog.
Edit:
As discussed, you would need to implement BroadcastReceiver
Here is a demo project of mine for something else, you can use it as a sample on how to create and use BroadcastReceiver.
https://github.com/cyfung/ActivityRecognitionSample
I'm using Oauth to subscribe to Fitbit. When the user clicks a connect button in my website, he/she is redirected to the Fitbit authentication page, which open as a new tab in the browser, while it shows a loading progress bar in my website.
When user clicks the accept or deny button in the fitbit authentication page, fitbit pings my back end and everything works fine. But, if the user closes the window not opting to click neither accept nor deny, I'm stuck with the progress bar in my website. How can I get around this?
This is the how actually the progress bar closes. I use a column in my database called is_connected which returns the status of the connection
is_connected=0 // not connected
is_connected=1 // connected
is_connected=2 // connecting
so while the progress bar is showing(is_connected=2), the frontend keeps on pinging the backend requesting the status of is_connected field. When it detects a change, the progress bar closes.
I'm trying to ask the user if he wants to retry a login process if the initial one has failed.
I do this using an AlertDialog. The problem is i'm going around in a circle. Let me explain:
I have the login method named Login which I call from the main activity. If this fails, I open an AlertDialog. The response from AlertDialog comes on the main thread. How do I make the AlertDialog dissapear before I call Login again?
Now I have something like this onCreate->Login->AlertDialog->ResponseHandler->Login. If I do this, the AlertDialog will never close because everything happens on the same thread.
Is there a way to send the response from the AlertDialog to the activity in a asynchronous way?
You can declare a Handler object as an anonymous inner class in your activity and on its reference call the sendEmptyMessage(0). in the handlerMessage() of the handler instance just dismiss the AlertDialog.
Here is a tutorial link which will help you more http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html