/**
   * 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);
    }
  }