How To Close MessageBox Programmatically in WP8? - windows-phone-8

I'm aware that there are already questions questions asked regarding closing a MessageBox programmatically . But the solution to those questions is to use a timer.
I am trying to develop an NFC application, so when i create a MessageBox, it contains a message Please Tap Your NFC. So technically, the Timer isn't helpful. I need a way to close or dispose a MessageBox.
Please advice.

You can create a custom window yourself as described in the question you linked. However, instead of a timer you can and include a Hide method which you can call once NFC connection event occurs.
Alternatively, you could get Coding4Fun toolkit and use MessagePrompt class which already includes a Hide method.

From lieska at MessageBox.Show in App Closing/Deactivated events
Register BackKeyPress event on RootFrame.
RootFrame.BackKeyPress += BackKeyPressed;
private void BackKeyPressed(object sender, CancelEventArgs e)
{
var result = (MessageBox.Show("Do you want to exit XXXXX?", "Application Closing", MessageBoxButton.OKCancel));
if (result == MessageBoxResult.Cancel)
{
// Cancel default navigation
e.Cancel = true;
}
}

Related

Videojs-swf - rtmp connect without publishing stream or disconnect

How can I set waiting when the stream is not published.
When unpublish (NetStream.Play.UnpublishNotify) set to waiting, and on publish (NetStream.Play.PublishNotify) continue play
I don't use Video-JS so I don't know what their code setup is doing.
Normally (without Video-JS) it's done something like this.
yourNS.addEventListener(NetStatusEvent.NET_STATUS, streamEventsHandler);
private function streamEventsHandler(evt:NetStatusEvent):void
{
//trace(evt.info.code); //if you need to check event status as text
if (evt.info.code == "NetStream.Play.UnpublishNotify") { yourNS.pause(); }
if (evt.info.code == "NetStream.Play.PublishNotify") { yourNS.resume(); }
}
So now in the Video-JS code, find the part that handles NetStream events, and edit the function to pause(); or resume();.
If unsure of the real NetStream name (I just called it yourNS for example) you can try :
Instead of : yourNS.pause(); try as evt.target.pause(); or evt.target.pause();
(PS: I use evt because of the name in function parameter is (evt:NetStatusEvent):void... Check your own Video-JS function)

Windows phone 8.1 BackPressed not working properly

Windows phone 8.1 new to world. Basic function is back button click. Is that function not working properly is this windows phone 8.1. Is that behavior or i'm made mistake.
Below code using in Homepage but this code calling from all other class too while clicking back. I need to access below method only on Home page .
Please check below code and refer me good solution.
Please look my code:
public HomePage()
{
this.InitializeComponent();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
}
Thanks
It is working properly. The BackPressed event is working app-wide. Two options that come to my mind:
write eventhandler that would recognize the Page in which you currently invoke it - simple example can look like this:
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null) return;
if (frame.Content is HomePage)
{
e.Handled = true;
Debug.WriteLine("I'm in HomePage");
}
else if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
second option - subscribe to Windows.Phone.UI.Input.HardwareButtons.BackPressed when you enter the Page and unsubscribe when you leave the Page. Note that in this way there are some pitfalls - you have to handle properly OnNavigatedTo, OnNavigatedFrom, Suspending and Resuming (more about Lifecycle here). Note also that the subscription should be done before others - for example NavigationHelper.
Some remarks - the above code should work, but it also depends on other circumstances:
if there is something other subscribed to BackPressed before (in App.xaml.cs) - remember that usually events are fired in order they were subscribed
check if you are using NavigationHelper - it also subscribes to BackPressed
remember not to subscribe multiple times
remember to allow the User to leave your HomePage

"Events type" in java

My program contain two classes, one represent the main program and the other one is a gui implemented using swing,
I'm trying to create an "event type", meaning I want my main program to wait until the UserInterface (GUI) will indicate some event, like pressing a button, and I would like to sends some information when my button is pressed.
General Code for the main program (this is the relevant section)
// Open window GUI with the requested BID and wait for confirmation or denial
HumanIFWindow nextWindowGUI = new HumanIFWindow();
nextWindowGUI.setVisible(true);
// ----------------- //
// - Wait on event - //
// ----------------- //
// Here is where I want to wait for the gui Indication
return returnedBid;
Code for the GUI (Again only relevant part)
JButton btnAprove = new JButton("Aprove");
btnAprove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// ----------------- //
// - Trigger event - //
// ----------------- //
// Here is where I want to trigger the event
}});
Preferably I would like to use some library, is there's one that match my needs?
(Maybe BusEvent?)
Edit to specify the question (Thanks Kishan Sarsecha Gajjar)
I want the first class (the general one) to enter a wait statement, I know how to wait using:
while( someBoolean...)
Thread.sleep(...)
and I can change someBoolean with a handle in the GUI class, Like:
FisrtClass.someBoolean == False
But I want something nicer and neater, like a library that Implements the sleep statement. and there's no additional code needed. Is there something like that?
I've looked at Google-BusEvent library but I'm not sure if that's compatible
EDIT, adding JDialog
updated code: Main program:
Bid returnedBid = requestBid;
// Open window GUI with the requested BID and wait for confirmation
DialogHumanConfirmManual nextWindowGUI = new DialogHumanConfirmManual(requestBid);
// Wait on event
if ( (returnedBid = nextWindowGUI.getAnswer()) != null ){
System.out.println("Got Bid " + returnedBid.print());
}
GUI - Dialog:
public DialogHumanConfirmManual(Bid requestedBid){
currentBid = requestedBid;
currentBid.approvedHuman = false;
Dialog mainFrame = new Dialog(new Frame());
myPanel = new JPanel();
getContentPane().add(myPanel);
myPanel.add(new JLabel("Confirmation Dialog"));
yesButton = new JButton("Confirm");
yesButton.addActionListener(this);
myPanel.add(yesButton);
noButton = new JButton("No");
noButton.addActionListener(this);
myPanel.add(noButton);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (yesButton == e.getSource()) {
currentBid.approvedHuman = true;
answeredBid = currentBid;
}
}
After opening the Dialog the if ( returnBid ) is called, which result in Null Pointer Exception later on in the code, So How can I delay the main program until the user can Confirm the request??
the other one is a gui implemented using swing,
Use a modal JDialog not a JFrame.
Once the dialog is made visible, the code after the setVisible(true) statement will NOT execute until the dialog is closed.
Read the section from the Swing tutorial on How to Make Dialogs for more information. The tutorial covers the JOptionPane class, but you can just use a JDialog, which is created exactly the same way a JFrame is. You can choose whether to use a JOptionPane or JDialog depending on your exact requirement.

Cancel Windows Phone SpeechSynthesizer

My app is calling SpeechSynthesizer.SpeakTextAsync multiple time, so most of the text will be add to the queue before spoken. I want to give user the ability to cancel the speech and discard eveyything that's still in the queue.
I tried calling either SpeechSynthesizer.CancelAll or SpeechSynthesizer.Dispose and the app will just crash when either of the methods were called.
I've looked at Cancel speech synthesis in windows phone 8 but since my app add multiple speech to the queue, Task.Cancel doesn't seem to work.
Well, according to the documentation, when you call CancellAll, you're cancelling the Tasks that are executing asynchronously. By contract, this results in an OperationCancelledException being thrown. That means that wherever you call SpeakTextAsync, SpeakSsmlAsync or SpeakSsmlFromUriAsync, you must surround these calls with a try/catch statement to prevent this exception from going uncaught.
private static SpeechSynthesizer synth;
public async static Task<SpeechSynthesizer> SpeechSynth(string dataToSpeak)
{
synth = new SpeechSynthesizer();
IEnumerable<VoiceInformation> englishVoices = from voice in InstalledVoices.All
where voice.Language == "en-US"
&& voice.Gender.Equals(VoiceGender.Female)
select voice;
if (englishVoices.Count() > 0)
{
synth.SetVoice(englishVoices.ElementAt(0));
}
await synth.SpeakTextAsync(dataToSpeak);
return synth;
}
public static void CancelSpeech()
{
synth.CancelAll();
}
Now call the SpeechSynth("Some Data to Speak") where you want, and whenever you want to cancel it, just call CancelSpeech().
Its Done! Enjoy...!

Can I specify a delay before the browser raises "rollover" event?

I am working on an ASP.NET web application that is required to bring up a popup on a roolover. I am using the "OnMouseOver" event and it works as expected. The problem is that the event is on a "hair trigger"; even a casual passage of the mouse over the control brings up the popup (which then must be manually dismissed). I want to add a delay so that a rapid pass over the control in question does not trigger the event. Is there a way to set such a delay or is there a different event that I could use to get the same "trigger event on a slow rollover"?
One solution that comes to mind, there may be better ways though:
Make the onmouseover call the function via a setTimeout delay
Inside the function, check the mouse is actually over that element.
You could also use an onmouseout to clear the setTimeout, but then you'd have to store a reference to the timer in a global variable to get at it again.
What I ended up doing is as follows (oRow is a table row but it could be any control):
function ItemMouseOver(oRow, "parameters for the popup")
{
oRow.showTimer = window.setTimeout(function()
{
alert('popup');
}, 1000);
}
function ItemMouseOut(oRow)
{
if (oRow.showTimer)
window.clearTimeout(oRow.showTimer);
In the ASP.NET grid view RowDataBound event: I added the following code:
protected void ReportGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (
e.Row.RowState == DataControlRowState.Normal
|| e.Row.RowState == DataControlRowState.Alternate))
{
// get the input values for the popup for the row (stuff deleted)
e.Row.Attributes["onmouseover"] = "javascript:ItemMouseOver(this,
"parameters for the popup");";
e.Row.Attributes["onmouseout"] = "javascript:ItemMouseOut(this);";
}
}
It works just fine. Thanks.