Android Open Source - AndroIUT A D E List Resources Chooser






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.ade.activities;
/*from w w  w.j a v  a  2  s.  c  o m*/
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.activation.UnsupportedDataTypeException;
import javax.xml.parsers.ParserConfigurationException;

import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.xml.sax.SAXException;

import android.app.ListActivity;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.iutdijon.androiut2.R;

public class ADEListResourcesChooser extends ListActivity {

  public final static String RESOURCE_BASE_INTENT_EXTRA = "resourceBase";
  
  private Element resourceBaseTree = null;
  public ADEListResourcesChooser() {
    
  }
  
  @SuppressWarnings("unchecked")
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    ADEResource res = (ADEResource) l.getAdapter().getItem(position);
    
    List<Element> children = res.getNode().getChildren();
    if(children.size() != 0){
      ((ArrayAdapter<ADEResource>)l.getAdapter()).clear();
      for (int i = 0; i < children.size(); i++) {
        ((ArrayAdapter<ADEResource>)l.getAdapter()).add(new ADEResource(children.get(i)));
      }
  
      ((ArrayAdapter<ADEResource>)l.getAdapter()).notifyDataSetChanged();
    }else{
      setResult(Integer.parseInt(res.getID()));
      finish();
    }
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    try {
      String resourceBase = getIntent().getStringExtra(RESOURCE_BASE_INTENT_EXTRA);
      resourceBaseTree = queryForDerivedResource(resourceBase.substring(0, resourceBase.indexOf('/')));
      
      if(resourceBaseTree == null){
        throw new UnsupportedDataTypeException("Impossible de d?terminer la section associ?e au compte");
      }
      
      
      setListAdapter(new ArrayAdapter<ADEResource>(this, android.R.layout.simple_list_item_1, ADEResource.generateListOfResourceFromNode(resourceBaseTree.getChildren())));
      
    } catch (Exception e){
      e.printStackTrace();
    }
  }
  
  /**
   * Demande la liste des descendants dans le XML ADE pour l'id pass?.
   * @param resourceBase ID du conteneur global de la section de l'?dudiant
   * @return Map<Nom ADE, id ADE> des descendants
   * @throws SAXException 
   * @throws IOException 
   * @throws NotFoundException 
   * @throws ParserConfigurationException 
   * @throws JDOMException 
   */
  private Element queryForDerivedResource(String sectionIdentifier) throws NotFoundException, IOException, SAXException, ParserConfigurationException, JDOMException{
    
    Element sectionRoot = null;
    
    Document xml = new SAXBuilder().build(getResources().openRawResource(R.raw.resources_iut));
    
    sectionRoot = getElementByAttributeValue(xml.getRootElement(), sectionIdentifier);
        
    return sectionRoot;
  }
  
  public static Element getElementByAttributeValue(Element rootElement, String attributeValue) {

    Element found = null;
      if (rootElement != null && rootElement.getChildren().size() != 0) {
          List<Element> nodeList = rootElement.getChildren();

          for (int i = 0; i < nodeList.size(); i++) {
              Element subNode = nodeList.get(i);

              if (subNode.hasAttributes()) {
                  Attribute attrNode = subNode.getAttribute("name");
                  if(attrNode != null){
                      if(attrNode.getValue().equalsIgnoreCase(attributeValue)){
                        return subNode;
                      }
                      found = getElementByAttributeValue(subNode, attributeValue);
                  }               
              }
          }
      }
      return found;
  }
  
  private static class ADEResource{
    private final Element node;
    
    public ADEResource(Element e) {
      node = e;
    }
    
    public String getID(){
      return node.getAttributeValue("id");
    }
    
    public String getName(){
      return node.getAttributeValue("name");
    }
    
    public Element getNode(){
      return node;
    }
    
    @Override
    public String toString(){
      return getName();
    }
    
    public static List<ADEResource> generateListOfResourceFromNode(List<? extends Element> values){
      List<ADEResource> resources = new ArrayList<ADEListResourcesChooser.ADEResource>(values.size());
      
      for (Iterator<? extends Element> val = values.iterator(); val.hasNext();) {
        Element adeResource = val.next();
        resources.add(new ADEResource(adeResource));
      }
      
      return resources;
    }
  }
}




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