Exemple #1
0
 public State libraryEvent(Object library, int event, Object data) {
   if (library == apirequest) {
     switch (event) {
       case PRequest.EVENT_CONNECTED:
         parser.start(apirequest);
         break;
       case PRequest.EVENT_ERROR:
         this.selection = 0;
         this.index = 0;
         this.count = 0;
         this.assets = null;
       case PRequest.EVENT_DONE:
         apirequest = null;
         break;
     }
   } else if (library == imgrequest) {
     switch (event) {
       case PRequest.EVENT_CONNECTED:
         imgrequest.readBytes();
         break;
       case PRequest.EVENT_DONE:
         imgfetching.image = new PImage((byte[]) data);
       case PRequest.EVENT_ERROR:
         imgfetching = null;
         imgrequest = null;
         break;
     }
   } else if (library == parser) {
     switch (event) {
       case XMLParser.EVENT_TAG_START:
         if ("asset".equals(data)) {
           apifetching = new Asset();
         }
         break;
       case XMLParser.EVENT_TEXT:
         text = (String) data;
         break;
       case XMLParser.EVENT_TAG_END:
         if ("count".equals(data)) {
           int count = PMIDlet.toInt(text);
           assets = new Asset[count];
         } else if ("asset".equals(data)) {
           assets[count] = apifetching;
           apifetching = null;
           count++;
         } else if (apifetching != null) {
           apifetching.put(data, text);
         }
         break;
       case XMLParser.EVENT_DOCUMENT_END:
         apirequest = null;
         break;
     }
   }
   return this;
 }
Exemple #2
0
 public void fetchImage(Asset asset) {
   if (imgrequest == null) {
     String url = (String) asset.get("thumb");
     url = url.substring(20);
     imgfetching = asset;
     imgrequest = client.GET(url);
   }
 }