Пример #1
0
 private Vector parseWallpaperThumbnailJSON(String response, List cmp) {
   Vector resultVector = new Vector();
   Image blank = Image.createImage(50, 50);
   try {
     JSONObject jSONObject = new JSONObject(response);
     System.out.println(jSONObject);
     Enumeration e = jSONObject.keys();
     while (e.hasMoreElements()) {
       String key = (String) e.nextElement();
       //                System.out.println(key + " : " + jSONObject.getString(key));
       if (key.equalsIgnoreCase("wallpapers")) {
         JSONArray jSONArray = jSONObject.getJSONArray(key);
         for (int i = 0; i < jSONArray.length(); i++) {
           JSONObject wallpaper = jSONArray.getJSONObject(i);
           if (wallpaper.has("image_thumb_url")
               && wallpaper.has("image_category")
               && wallpaper.has("image_url")
               && wallpaper.has("wallpaper_price")) {
             // download the thumbnail and display it.
             Hashtable hashtable = new Hashtable();
             hashtable.put("wallpaperThumbnailURL", wallpaper.getString("image_thumb_url"));
             hashtable.put("wallpaperURL", wallpaper.get("image_url"));
             hashtable.put("wallpaperPrice", "Price: " + wallpaper.get("wallpaper_price"));
             hashtable.put("wallpaperIcon", blank);
             resultVector.addElement(hashtable);
             final ImageDownloadService ids =
                 new ImageDownloadService(
                     wallpaper.getString("image_thumb_url"),
                     cmp,
                     resultVector.size() - 1,
                     "wallpaperIcon") {
                   protected void handleException(Exception err) {
                     if (err instanceof NullPointerException) {
                       System.out.println("NULL POINTER EXCEPTION CAUGHT");
                       return;
                     }
                     super.handleException(
                         err); // To change body of generated methods, choose Tools | Templates.
                   }
                 };
             NetworkManager.getInstance().addToQueue(ids);
           }
         }
       }
     }
   } catch (Exception ex) {
     System.out.println("error downloading images.");
     ex.printStackTrace();
     Dialog.show(null, "error downloading images", "OK", null);
   }
   return resultVector;
 }
Пример #2
0
 /**
  * this method should be used to initialize variables instead of the constructor/class scope to
  * avoid race conditions
  */
 protected void initVars() {
   NetworkManager.getInstance().start();
 }