Android Open Source - AndroIUT Mail Reader Activity






From Project

Back to project page AndroIUT.

License

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.

Java Source Code

package com.iutdijon.androiut2.mail.activities;
// w  ww  .ja va2s  . c o  m
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.mail.MessagingException;
import javax.mail.Part;
import javax.mail.internet.MimeBodyPart;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;

import com.iutdijon.androiut2.R;
import com.iutdijon.androiut2.util.UIUtil;
import com.iutdijon.androiut2.util.bridge.BridgeFinder;
import com.iutdijon.androiut2.util.loaders.GetAsyncServiceCall;

/**
 * Classe g?rant l'affichage d'un email ? des fins de lecture.
 * Elle utilise une WebView afin de rendre le plus fid?lement les emails dont la plupart sont ?crit en HTML
 * Elle affiche l'exp?diteur, l'objet, le message ainsi que les pi?ces jointes.
 * @author Morgan Funtowicz
 *
 */
public class MailReaderActivity extends Activity implements OnChildClickListener {

  private WebView text_holder;
  private TextView text_header;
  private ExpandableListView text_footer;
  
  /*
   * TODO : Reprendre la gestion de la lecture des pi?ces jointes, bricolage actuellement avec la variable statique
   */
  public static HashMap<String, Part> attachments;

  public MailReaderActivity() {

  }

  /**
   * Cr?ation de la vue utilisateur avec les donn?es m?moires du message
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    
    
    Bundle data = getIntent().getBundleExtra("data");

    setContentView(R.layout.activity_mail_reading);

    text_holder = (WebView) findViewById(R.id.mail_content_textview);
    text_header = (TextView) findViewById(R.id.mail_header_textview);
    text_footer = (ExpandableListView) findViewById(R.id.mail_footer_attachment);
        
    text_header.setText(Html.fromHtml("<b>" + data.getString("sender") + "</b><br/>" + data.getString("subject")));

    String[] attachments = data.getStringArray("attachment");

    if (attachments != null) {
      List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
          List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
          
          //Titre de la liste
          Map<String, String> curGroupMap = new HashMap<String, String>();
            groupData.add(curGroupMap);
            curGroupMap.put("NAME", getString(R.string.attachments_label));
          
            //Contenu du sous groupe avec la liste des pi?ces jointes
            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            for (int i = 0; i < attachments.length; i++) {
                Map<String, String> curChildMap = new HashMap<String, String>();
                children.add(curChildMap);
                curChildMap.put("NAME", attachments[i]);
            }
            
            childData.add(children);
            
            SimpleExpandableListAdapter mAdapter = new SimpleExpandableListAdapter(
                    this,
                    groupData,
                    R.layout.expandable_list_view,
                    new String[] { "NAME" },
                    new int[] {android.R.id.text1},
                    childData,
                    R.layout.expandable_list_view_child,
                    new String[] { "NAME" },
                    new int[] { android.R.id.text2}
            );
            text_footer.setAdapter(mAdapter);
            text_footer.setOnChildClickListener(this);
    }
    text_holder.loadDataWithBaseURL("", data.getString("content"),"text/html", "utf-8", null);
  }
  
  @Override
  protected void onDestroy() {
    super.onDestroy();
    if(attachments != null){
      attachments = null;
    }
  }

  @Override
  @SuppressWarnings("unchecked")
  public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
    String attachment_name = ((HashMap<String, String>) text_footer.getExpandableListAdapter().getChild(groupPosition, childPosition)).get("NAME");
    if(attachments.containsKey(attachment_name)){

      new GetAsyncServiceCall<Part, Void, File>(this) {

        @Override
        protected File run(Part... params) throws IOException {
          
          Part p = params[0];
          File temp = null;
          
          try {
            temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), p.getFileName());
            if(p instanceof MimeBodyPart){
              ((MimeBodyPart)p).saveFile(temp);
            }
          } catch (MessagingException e) {
            UIUtil.showMessage(MailReaderActivity.this, e.getMessage());
            e.printStackTrace();
          }
          
          return temp;
        }
        
        @Override
        protected void onPostRun(File result) {
          super.onPostRun(result);
          
          try{
            Intent reader = BridgeFinder.getDefaultApplicationFromFileName(result);
            
            if(reader == null){
              UIUtil.showMessage(MailReaderActivity.this, R.string.no_application_found);
            }
            startActivity(reader);
          }catch(Exception e){
            e.printStackTrace();
          }
          
        }
      }.execute(attachments.get(attachment_name));
    }else{
      UIUtil.showMessage(this, R.string.downloading_attachment);
      return false;
    }
    return true;
  }
}




Java Source Code List

.ADEResourcesDataTree.java
com.iutdijon.androiut2.ade.activities.ADEActivity.java
com.iutdijon.androiut2.ade.activities.ADEListResourcesChooser.java
com.iutdijon.androiut2.ade.activities.OnImageDownloadedCallback.java
com.iutdijon.androiut2.ade.service.ADEICalendarDownloader.java
com.iutdijon.androiut2.ftp.activities.FTPActivity.java
com.iutdijon.androiut2.ftp.adapters.FTPFileListAdapter.java
com.iutdijon.androiut2.ftp.data.FTPCommandResult.java
com.iutdijon.androiut2.ftp.data.FTPCommandWrapper.java
com.iutdijon.androiut2.ftp.data.FTPCommand.java
com.iutdijon.androiut2.ftp.services.FTPDownloadMonitor.java
com.iutdijon.androiut2.ftp.services.FTPServiceCall.java
com.iutdijon.androiut2.ftp.services.ProgressDownload.java
com.iutdijon.androiut2.global.AndroIUTApplication.java
com.iutdijon.androiut2.iut.activities.HomeActivity.java
com.iutdijon.androiut2.iut.activities.LoginActivity.java
com.iutdijon.androiut2.iut.data.Credential.java
com.iutdijon.androiut2.iut.data.UserFactory.java
com.iutdijon.androiut2.iut.data.account.StudentAccount.java
com.iutdijon.androiut2.iut.data.account.TeacherAccount.java
com.iutdijon.androiut2.iut.data.account.UserAccount.java
com.iutdijon.androiut2.iut.services.IUTLoginServiceCall.java
com.iutdijon.androiut2.mail.activities.MailActivity.java
com.iutdijon.androiut2.mail.activities.MailReaderActivity.java
com.iutdijon.androiut2.mail.adapters.MailDisplayAdapter.java
com.iutdijon.androiut2.mail.adapters.MailsListAdapter.java
com.iutdijon.androiut2.mail.services.EmailUtils.java
com.iutdijon.androiut2.mail.services.MailReader.java
com.iutdijon.androiut2.mail.services.MailService.java
com.iutdijon.androiut2.schooling.activities.SchoolingActivity.java
com.iutdijon.androiut2.schooling.activities.SchoolingTabActivity.java
com.iutdijon.androiut2.schooling.adapters.SectionedAdapter.java
com.iutdijon.androiut2.schooling.data.Absence.java
com.iutdijon.androiut2.schooling.data.Mark.java
com.iutdijon.androiut2.schooling.data.SchoolingData.java
com.iutdijon.androiut2.schooling.service.SchoolingDataServiceCall.java
com.iutdijon.androiut2.util.AndroIUTLogger.java
com.iutdijon.androiut2.util.IOUtils.java
com.iutdijon.androiut2.util.PreferencesManager.java
com.iutdijon.androiut2.util.UIUtil.java
com.iutdijon.androiut2.util.adapters.AbsencesAdapter.java
com.iutdijon.androiut2.util.adapters.BitmapAdapter.java
com.iutdijon.androiut2.util.adapters.CalendarAdapter.java
com.iutdijon.androiut2.util.adapters.IAdapter.java
com.iutdijon.androiut2.util.adapters.MarksAdapter.java
com.iutdijon.androiut2.util.adapters.UserAdapter.java
com.iutdijon.androiut2.util.adapters.XmlAdapter.java
com.iutdijon.androiut2.util.bridge.BridgeFinder.java
com.iutdijon.androiut2.util.loaders.AndroIUTHTTPConnection.java
com.iutdijon.androiut2.util.loaders.AsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.BitmapDownloaderTask.java
com.iutdijon.androiut2.util.loaders.GetAsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.ImageDownloader.java
com.iutdijon.androiut2.util.loaders.PostAsyncServiceCall.java
com.iutdijon.androiut2.util.observers.Observable.java
com.iutdijon.androiut2.util.observers.Observer.java
com.iutdijon.androiut2.util.security.SecureCenter.java
com.iutdijon.androiut2.util.view.ImageZoomView.java
com.iutdijon.androiut2.util.zoom.AspectQuotient.java
com.iutdijon.androiut2.util.zoom.DynamicZoomControl.java
com.iutdijon.androiut2.util.zoom.LongPressZoomListener.java
com.iutdijon.androiut2.util.zoom.PinchZoomListener.java
com.iutdijon.androiut2.util.zoom.SimpleZoomListener.java
com.iutdijon.androiut2.util.zoom.ZoomState.java
com.iutdijon.androiut2.util.zoom.util.Dynamics.java
com.iutdijon.androiut2.util.zoom.util.SpringDynamics.java