Progress Indicator

hello

I need help on how to configure the progress indicator for my application.

I have a situation where by user requests a certain code that has to be sent to user’s email, now this takes about 3sec to 10 seconts depending on the network and computer speed,

I want to show a progress indicator while this process goes on.

But the problem is i dont know how to attach this activity to the progress bar.

here are the activities,

1 generate a random code

public static class RandomString

	{
		@SuppressWarnings("deprecation")
		public String randomstring(int lo, int hi)
		{
			int n = rand(lo, hi);
			byte b[] = new byte[n]
;
			for (int i = 0; i < n; i++)
				b[i]
 = (byte) rand('a', 'z');
			return new String(b, 0);
		}

		private int rand(int lo, int hi)
		{
			java.util.Random rn = new java.util.Random();
			int n = hi - lo + 1;
			int i = rn.nextInt() % n;
			if (i < 0)
				i = -i;
			return lo + i;
		}

		public String randomstring()
		{
			return randomstring(6, 20);
		}
	}
  1. Update the database table with new code

  2. send email to user

new SendEmail(newEmail, mail_message, code);

send email code


public class SendEmail
{
	String d_email = "email@gmail.com"; 
	String d_password = "password";
	private String d_host = "smtp.gmail.com"; 
	private String d_port = "465"; 

	public SendEmail(String to,  String m_message, String m_subject ) {
		Properties props = new Properties();
		props.put("mail.smtp.user", d_email);
		props.put("mail.smtp.host", d_host);
		props.put("mail.smtp.port", d_port);
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.socketFactory.port", d_port);
		props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");
		
		try {
			Authenticator auth = new SMTPAuthenticator();
			Session session = Session.getInstance(props, auth);
//			session.setDebug(true);
			MimeMessage msg = new MimeMessage(session);			
			msg.setText(m_message);
			msg.setSubject(m_subject);
			msg.setFrom(new InternetAddress(d_email));
			msg.addRecipient(Message.RecipientType.TO,
					new InternetAddress(to));
			Transport.send(msg);
		} 
		catch (Exception mex){
			mex.printStackTrace();
		}
	}
	public class SMTPAuthenticator extends javax.mail.Authenticator	{
		public PasswordAuthentication getPasswordAuthentication(){
			return new PasswordAuthentication(d_email, d_password);
		}
	}
}

Thanks in advance.

I just made a ticket (http://dev.itmill.com/ticket/2118) and added simple demo as ticket attachment.