/**
   * Configure this Preference object from the Gecko search engine JSON object.
   *
   * @param geckoEngineJSON The Gecko-formatted JSON object representing the search engine.
   * @throws JSONException If the JSONObject is invalid.
   */
  public void setSearchEngineFromJSON(JSONObject geckoEngineJSON) throws JSONException {
    mIdentifier = geckoEngineJSON.getString("identifier");

    // A null JS value gets converted into a string.
    if (mIdentifier.equals("null")) {
      mIdentifier = "other";
    }

    final String engineName = geckoEngineJSON.getString("name");
    final SpannableString titleSpannable = new SpannableString(engineName);

    setTitle(titleSpannable);

    final String iconURI = geckoEngineJSON.getString("iconURI");
    // Keep a reference to the bitmap - we'll need it later in onBindView.
    try {
      final int desiredWidth;
      if (mFaviconView != null) {
        desiredWidth = mFaviconView.getWidth();
      } else {
        // largestFaviconSize is initialized when Favicons is attached to a
        // context, which occurs during GeckoApp.onCreate. That might not
        // ever happen (leaving it at 0), so we fall back.
        if (Favicons.largestFaviconSize == 0) {
          desiredWidth = 128;
        } else {
          desiredWidth = Favicons.largestFaviconSize;
        }
      }

      Favicons.getSizedFavicon(
          getContext(),
          mIdentifier,
          iconURI,
          desiredWidth,
          0,
          new OnFaviconLoadedListener() {
            @Override
            public void onFaviconLoaded(String url, String faviconURL, Bitmap favicon) {
              synchronized (bitmapLock) {
                mIconBitmap = favicon;

                if (mFaviconView != null) {
                  mFaviconView.updateAndScaleImage(mIconBitmap, getTitle().toString());
                }
              }
            }
          });
    } catch (IllegalArgumentException e) {
      Log.e(
          LOGTAG, "IllegalArgumentException creating Bitmap. Most likely a zero-length bitmap.", e);
    } catch (NullPointerException e) {
      Log.e(LOGTAG, "NullPointerException creating Bitmap. Most likely a zero-length bitmap.", e);
    }
  }
Exemplo n.º 2
0
  /**
   * Display the thumbnail from a bitmap.
   *
   * @param thumbnail The bitmap to show as thumbnail.
   */
  public void displayThumbnail(Bitmap thumbnail) {
    if (thumbnail == null) {
      // Show a favicon based view instead.
      displayThumbnail(R.drawable.favicon);
      return;
    }
    mThumbnailSet = true;
    Favicons.cancelFaviconLoad(mLoadId);

    mThumbnailView.setScaleType(SCALE_TYPE_THUMBNAIL);
    mThumbnailView.setImageBitmap(thumbnail);
    mThumbnailView.setBackgroundDrawable(null);
  }
Exemplo n.º 3
0
  /**
   * Display the thumbnail from a favicon.
   *
   * @param favicon The favicon to show as thumbnail.
   */
  public void displayFavicon(Bitmap favicon, String faviconURL) {
    if (mThumbnailSet) {
      // Already showing a thumbnail; do nothing.
      return;
    }

    if (favicon == null) {
      // Should show default favicon.
      displayThumbnail(R.drawable.favicon);
      return;
    }

    if (faviconURL != null) {
      mFaviconURL = faviconURL;
    }

    mThumbnailView.setScaleType(SCALE_TYPE_FAVICON);
    mThumbnailView.setImageBitmap(favicon);

    if (mFaviconURL != null) {
      mThumbnailView.setBackgroundColor(Favicons.getFaviconColor(mFaviconURL));
    }
  }
Exemplo n.º 4
0
 public void setLoadId(int aLoadId) {
   Favicons.cancelFaviconLoad(mLoadId);
   mLoadId = aLoadId;
 }