Back to project page AndroIUT.
The source code is released under:
GNU General Public License
If you think the Android project AndroIUT listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.iutdijon.androiut2.mail.services; /*from w ww. j a va 2s. c o m*/ import java.util.MissingResourceException; import javax.mail.Message; import javax.mail.MessagingException; import android.app.ListActivity; import android.app.ProgressDialog; import android.os.AsyncTask; import com.iutdijon.androiut2.R; import com.iutdijon.androiut2.mail.adapters.MailsListAdapter; import com.iutdijon.androiut2.util.UIUtil; /** * Service permettant de g?rer toutes les requ?tes sur le serveur des emails * @author Morgan Funtowicz * */ public class MailService extends AsyncTask<String, Void, Message[]>{ public static int MAIL_SIZE_LIMIT = 15; private MailReader reader; private ListActivity context; private ProgressDialog progressBar; /** * Construit un nouvel objet MailServices * @param context Un r?f?rence vers l'activit? qui contiendra le r?sultat des requ?tes */ public MailService(ListActivity context) { reader = new MailReader(MailReader.Protocol.IMAPS, "iut-dijon.u-bourgogne.fr"); this.context = context; } @Override protected Message[] doInBackground(String... params) { if(params.length < 2) throw new MissingResourceException("Mail Reader execute params have to be login/password", null, null); Message[] emails = null; try { reader.connect(params[0], params[1]); emails = reader.getMessages(MAIL_SIZE_LIMIT); } catch (MessagingException e) { progressBar.dismiss(); UIUtil.showMessage(context, R.string.error_connection_to_server); e.printStackTrace(); } return emails; } @Override protected void onPreExecute() { progressBar = ProgressDialog.show(context, "", context.getText(R.string.downloading_emails)); super.onPreExecute(); } @Override protected void onPostExecute(Message[] result) { if(progressBar.isShowing()){ progressBar.dismiss(); } context.setListAdapter(new MailsListAdapter(context, result)); super.onPostExecute(result); } }