×
Namespaces

Variants
Actions
(Difference between revisions)

How to add an activity or progress indicator to an Alert

From Nokia Developer Wiki
Jump to: navigation, search
skalogir (Talk | contribs)
(Skalogir -)
skalogir (Talk | contribs)
(Skalogir - - Overview)
Line 32: Line 32:
 
==Overview==
 
==Overview==
  
This code example uses two high-level LCDUI components, an Alert and a Gauge. The alert is manually launched by the end user, while the gauge is used as activity indicator. The activity indicator describes the progress for completing a 10-step task. The range of the indicator is between 0 and 100, in increments of 10.
+
This code example uses two high-level LCDUI components, an Alert and a Gauge. The alert is manually launched by the end user, while the gauge is used as activity indicator inside the Alert. The activity indicator describes the progress for completing a 10-step task. The range of the indicator is between 0 and 100, in increments of 10.
  
 
<gallery widths=250px heights=500px>
 
<gallery widths=250px heights=500px>
Line 39: Line 39:
 
File:step9.png| Step 9 in a 10-step progress activity
 
File:step9.png| Step 9 in a 10-step progress activity
 
</gallery>
 
</gallery>
+
 
 
== The User Interface ==
 
== The User Interface ==
 
Both TextFields are empty by default. The TextField at the top of the form becomes of type {{Icode|PHONENUMBER}} and can take up to 20 digits, while the TextField beneath it, becomes of type {{Icode|PLAIN}} and takes up to 160 characters, which is the character limit for an SMS transmission without splitting it up to more than one piece. In the constructor, we instantiate the MessageConnection object and bind it to port 6553. Also a {{Icode|TextMessage}} instance is created of type TEXT_MESSAGE, since this example will be used for sending a message containing characters in the form of a text. If the port cannot be opened, an error message will be appended to the form.
 
Both TextFields are empty by default. The TextField at the top of the form becomes of type {{Icode|PHONENUMBER}} and can take up to 20 digits, while the TextField beneath it, becomes of type {{Icode|PLAIN}} and takes up to 160 characters, which is the character limit for an SMS transmission without splitting it up to more than one piece. In the constructor, we instantiate the MessageConnection object and bind it to port 6553. Also a {{Icode|TextMessage}} instance is created of type TEXT_MESSAGE, since this example will be used for sending a message containing characters in the form of a text. If the port cannot be opened, an error message will be appended to the form.

Revision as of 13:01, 24 July 2012

This code example demonstrates how to add an activity indicator to an Alert, that displays the progress for the completion of a process and dismisses itself, when the process is completed.

Contents

Overview

This code example uses two high-level LCDUI components, an Alert and a Gauge. The alert is manually launched by the end user, while the gauge is used as activity indicator inside the Alert. The activity indicator describes the progress for completing a 10-step task. The range of the indicator is between 0 and 100, in increments of 10.

The User Interface

Both TextFields are empty by default. The TextField at the top of the form becomes of type PHONENUMBER and can take up to 20 digits, while the TextField beneath it, becomes of type PLAIN and takes up to 160 characters, which is the character limit for an SMS transmission without splitting it up to more than one piece. In the constructor, we instantiate the MessageConnection object and bind it to port 6553. Also a TextMessage instance is created of type TEXT_MESSAGE, since this example will be used for sending a message containing characters in the form of a text. If the port cannot be opened, an error message will be appended to the form.

        mainForm = new Form("SMS Example");
 
smsNumber = new TextField("Phone number", null, 20,
TextField.PHONENUMBER);
mainForm.append(smsNumber);
 
smsText = new TextField("Text", null, 160, TextField.PLAIN);
mainForm.append(smsText);
 
sendCommand = new Command("Send", Command.OK, 0);
mainForm.addCommand(sendCommand);
 
exitCommand = new Command("Exit", Command.EXIT, 0);
mainForm.addCommand(exitCommand);
 
mainForm.setCommandListener(this);
 
// Open the connection
 
try{
connection = (MessageConnection)Connector.open("sms://:6553");
message = (TextMessage)connection.newMessage(MessageConnection.TEXT_MESSAGE);
}
catch (IOException ex) {
mainForm.append("error:" + ex.getMessage() + "\n");
}

Sending the text message

The method handleSendCommand is called via the CommandListener when the user selects the Send action. The TextMessage instance is being given an address in the form sms:// [recipient number] : [port number]. The port number is hard coded in this example to 6553. A payload is added to the message by calling the setPayloadText method and passing as argument the content of the second TextField.

       private void handleSendCommand() {
 
//Set the destination address
String number = "sms://" + smsNumber.getString() + ":6553";
message.setAddress(number);
 
// Obtain the specified text and set it as the payload
String text = smsText.getString();
message.setPayloadText(text);
 
}

After a payload and an address is set to the message, the sending operation takes place inside a thread:

 
// Send the message on its own thread of execution
Thread smsThread = new Thread() {
public void run() {
try {
connection.send(message);
mainForm.append("Message sent!\n");
}
catch (InterruptedIOException ex) {
mainForm.append("Interrupted Exception!\n");
}
catch (IOException ex) {
mainForm.append("IOException!\n");
}
catch (IllegalArgumentException ex) {
mainForm.append("Illegal Argument!\n");
}
catch (SecurityException ex) {
mainForm.append("Security");
}
}
};
smsThread.start();

In order to send the message, as seen from above, we only need to call the send method from the connection instance and pass as argument the TextMessage instance that now contains both a recipient address and a payload.

See also

118 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×