/**
   * Initializes the storage.
   *
   * @param width The width of the screen. This is used to determine how large images should be.
   */
  public static synchronized void init(final int width) {
    if (feedCache == null) {
      final ImageCacheView imageCacheView = PlatformUtils.getInstance().getImageCacheView();

      screenWidth = width;

      if (screenWidth < 256) {
        imageSide = 128; // Must be supported picasa thumb size
        imageSize = 288; // Image max size to get suitable sized images from picasa
      } else {
        imageSide = 256; // Must be supported thumb size in picasa
        imageSize = 720; // Picasa size for "fullsize" images
      }

      imageCacheView.setMaxSize(width, width);

      try {
        imageCache =
            StaticWebCache.getWebCache(
                '4',
                PlatformUtils.PHONE_DATABASE_CACHE,
                imageCacheView,
                new StaticWebCache.HttpTaskFactory(),
                null);
      } catch (FlashDatabaseException e) {
        L.e("Could not initialize imageCache.", "", e);
      }

      try {
        feedCache = StaticWebCache.getWebCache('5', (CacheView) new ImageObjectTypeHandler());
      } catch (FlashDatabaseException e) {
        L.e("Could not initialize feedCache.", "", e);
      }

      thumbSize = imageSide + "c"; // c is for cropped, ensures image proportions

      urlOptions =
          "?alt=json&kind=photo&max-results="
              + NR_OF_FEATURED
              + "&thumbsize="
              + thumbSize
              + "&fields=entry(title,author(name),updated,media:group)"
              + "&imgmax="
              + imageSize;

      featURL = "http://picasaweb.google.com/data/feed/base/featured" + urlOptions;

      searchURL = "http://picasaweb.google.com/data/feed/base/all" + urlOptions + "&q=";
    }
  }
    protected Object exec(Object in) {

      if (in != null) {
        // #debug
        L.i("Load feed success, type=" + getType, search);

        scrollY = 0;
        imageObjectModel.removeAllElements();
        images.clear();

        L.i("Vector in", in.toString());

        final Vector newModel = (Vector) in;

        for (int i = 0; i < newModel.size(); i++) {
          imageObjectModel.addElement(newModel.elementAt(i));
          String thumbUrl = ((PicasaImageObject) imageObjectModel.elementAt(i)).thumbUrl;
          try {
            PicasaStorage.imageCache.prefetch(thumbUrl);
          } catch (FlashDatabaseException e) {
            L.e("Could not fetch image", thumbUrl, e);
          }
        }

        top = -((imageObjectModel.size() * imageSide) / 2 - getHeight() / 2) + imageSide - 20;

        stopSpinner();
      } else {
        L.i("Variable in is null", "");
      }

      return in;
    }
示例#3
0
  /**
   * Get the cache singleton associated with these parameters.
   *
   * @param priority
   * @param cacheType
   * @param startupTask
   * @return
   * @throws FlashDatabaseException
   */
  public FlashCache getFlashCache(
      final char priority, final int cacheType, final FlashCache.StartupTask startupTask)
      throws FlashDatabaseException {
    switch (cacheType) {
      case PlatformUtils.PHONE_DATABASE_CACHE:
        try {
          return new RMSFastCache(priority, startupTask);
        } catch (Exception e) {
          // #debug
          L.e(
              "Can not create flash cache, will attempt delete and re-init one time",
              "" + priority,
              e);
          RMSFastCache.deleteDataFiles(priority);
          try {
            final RMSFastCache cache = new RMSFastCache(priority, startupTask);
            // #debug
            L.i(
                "After deleting the files giving and error, we successfully created flash cache",
                "" + priority);
            return cache;
          } catch (Exception e2) {
            throw new FlashDatabaseException("Can not create flash cache: " + e2);
          }
        }

      default:
        throw new IllegalArgumentException(
            "Unsupported cache type "
                + cacheType
                + ": only PlatformAdapter.PHONE_DATABASE_CACHE is supported at this time");
    }
  }
示例#4
0
  /**
   * You can call this as the return statement of your overriding method once you have set the
   * result
   *
   * @return
   */
  public final Object exec(Object in) {
    Object out = in;

    try {
      synchronized (this) {
        if (in == null) {
          in = value;
        } else {
          value = in;
        }
        if (status == Task.CANCELED || status == Task.EXCEPTION) {
          throw new IllegalStateException(
              this.getStatusString() + " state can not be executed: " + this);
        } else if (status != Task.EXEC_STARTED) {
          setStatus(Task.EXEC_STARTED);
        }
      }
      out = doInBackground(in);

      final boolean doRun;
      final Task t;
      synchronized (this) {
        value = out;
        doRun = status == EXEC_STARTED;
        if (doRun) {
          setStatus(EXEC_FINISHED);
        }
        t = chainedTask;
      }
      if (this instanceof UITask && doRun) {
        PlatformUtils.runOnUiThread((UITask) this);
      }
      if (t != null) {
        // #debug
        L.i("Begin exec chained task", chainedTask.toString() + " INPUT: " + out);
        t.exec(out);
        // #debug
        L.i("End exec chained task", chainedTask.toString());
      }
    } catch (final Throwable t) {
      // #debug
      L.e("Unhandled task exception", this.toString(), t);
      setStatus(EXCEPTION);
    }

    return out;
  }
示例#5
0
 /**
  * When parsing this RSS XML document, this indicates the body of an XML tag
  *
  * @param qname
  * @param chars
  * @param attributes
  */
 protected synchronized void parseElement(
     final String qname, final String chars, final XMLAttributes attributes) {
   try {
     if (currentItem != null) {
       synchronized (currentItem) {
         if (qname.equals("title")) {
           currentItem.setTitle(chars);
         } else if (qname.equals("description")) {
           currentItem.setDescription(chars);
         } else if (qname.equals("link")) {
           currentItem.setLink(chars);
         } else if (qname.equals("pubDate")) {
           currentItem.setPubDate(chars);
         } else if (qname.equals("media:thumbnail")) {
           currentItem.setThumbnail((String) attributes.getValue("url"));
         }
       }
     }
   } catch (Exception e) {
     // #debug
     L.e("RSS parsing error", "qname=" + qname + " - chars=" + chars, e);
   }
 }
    public Object convertToUseForm(Object key, byte[] bytes) {
      JSONObject responseJson;

      try {
        responseJson = new JSONObject(new String(bytes));
      } catch (JSONException ex) {
        // #debug
        L.e("bytes are not a JSON object", featURL, ex);
        return null;
      }

      JSONArray entries = new JSONArray();
      final Vector vector = new Vector();

      try {
        final JSONObject feed = ((JSONObject) responseJson).getJSONObject("feed");
        entries = feed.getJSONArray("entry");
      } catch (JSONException e) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));

        // #debug
        L.e("JSON no result", featURL, e);
      }

      for (int i = 0; i < entries.length(); i++) {
        try {
          final JSONObject jsonObject = entries.getJSONObject(i);
          final String title = jsonObject.getJSONObject("title").getString("$t");
          final String author =
              jsonObject
                  .getJSONArray("author")
                  .getJSONObject(0)
                  .getJSONObject("name")
                  .getString("$t");
          final String thumbUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$thumbnail")
                  .getJSONObject(0)
                  .getString("url");
          final String imageUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$content")
                  .getJSONObject(0)
                  .getString("url");

          // #mdebug
          L.i("JSON parsed title: ", title);
          L.i("JSON parsed author: ", author);
          L.i("JSON parsed thumb url: ", thumbUrl);
          L.i("JSON parsed image url: ", imageUrl);
          // #enddebug

          vector.addElement(new PicasaImageObject(title, author, thumbUrl, imageUrl));
        } catch (JSONException e) {
          // #debug
          L.e("JSON item parse error", featURL, e);
        }
      }

      if (entries.length() == 0) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));
      }

      return vector;
    }