类com.google.zxing.client.android.HttpHelper源码实例Demo

下面列出了怎么用com.google.zxing.client.android.HttpHelper的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
源代码2 项目: ZXing-Standalone-library   文件: TitleRetriever.java
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        title = Html.fromHtml(title).toString();
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "https://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        title = Html.fromHtml(title).toString();
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "https://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
源代码7 项目: weex   文件: SearchBookContentsActivity.java
@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
源代码8 项目: weex   文件: TitleRetriever.java
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        title = Html.fromHtml(title).toString();
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
源代码9 项目: weex   文件: ProductResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "https://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
源代码11 项目: Study_Android_Demo   文件: TitleRetriever.java
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        title = Html.fromHtml(title).toString();
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "https://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
源代码14 项目: barcodescanner-lib-aar   文件: TitleRetriever.java
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        title = Html.fromHtml(title).toString();
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "https://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
源代码16 项目: reacteu-app   文件: SearchBookContentsActivity.java
@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
源代码17 项目: reacteu-app   文件: TitleRetriever.java
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && title.length() > 0) {
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
源代码18 项目: reacteu-app   文件: ProductResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "http://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
源代码19 项目: android-apps   文件: ProductResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException, InterruptedException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "http://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  String content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  Matcher matcher = PRODUCT_NAME_PRICE_PATTERN.matcher(content);
  if (matcher.find()) {
    append(productID,
           source,
           new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
           uri);
  }
}
 
@Override
protected JSONObject doInBackground(String... args) {
  try {
    // These return a JSON result which describes if and where the query was found. This API may
    // break or disappear at any time in the future. Since this is an API call rather than a
    // website, we don't use LocaleManager to change the TLD.
    String theQuery = args[0];
    String theIsbn = args[1];
    String uri;
    if (LocaleManager.isBookSearchUrl(theIsbn)) {
      int equals = theIsbn.indexOf('=');
      String volumeId = theIsbn.substring(equals + 1);
      uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    } else {
      uri = "http://www.google.com/books?vid=isbn" + theIsbn + "&jscmd=SearchWithinVolume2&q=" + theQuery;
    }
    CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
    return new JSONObject(content.toString());
  } catch (IOException ioe) {
    Log.w(TAG, "Error accessing book search", ioe);
    return null;
  } catch (JSONException je) {
    Log.w(TAG, "Error accessing book search", je);
    return null;
  }
}
 
源代码21 项目: zxingfragmentlib   文件: TitleRetriever.java
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  String encodedProductID = URLEncoder.encode(productID, "UTF-8");
  String uri = "https://www.google." + LocaleManager.getProductSearchCountryTLD(context)
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + encodedProductID;
  CharSequence content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.HTML);

  for (Pattern p : PRODUCT_NAME_PRICE_PATTERNS) {
    Matcher matcher = p.matcher(content);
    if (matcher.find()) {
      append(productID,
             source,
             new String[] { unescapeHTML(matcher.group(1)), unescapeHTML(matcher.group(2)) },
             uri);
      break;
    }
  }
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
源代码25 项目: weex   文件: BookResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
源代码28 项目: reacteu-app   文件: BookResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<String>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e.toString());
  }

  Collection<String> newTexts = new ArrayList<String>();

  if (title != null && title.length() > 0) {
    newTexts.add(title);
  }

  if (authors != null && !authors.isEmpty()) {
    boolean first = true;
    StringBuilder authorsText = new StringBuilder();
    for (String author : authors) {
      if (first) {
        first = false;
      } else {
        authorsText.append(", ");
      }
      authorsText.append(author);
    }
    newTexts.add(authorsText.toString());
  }

  if (pages != null && pages.length() > 0) {
    newTexts.add(pages + "pp.");
  }
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
源代码29 项目: android-apps   文件: BookResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException, InterruptedException {

  String contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                               HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<String>();
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e.toString());
  }

  Collection<String> newTexts = new ArrayList<String>();

  if (title != null && title.length() > 0) {
    newTexts.add(title);
  }

  if (authors != null && !authors.isEmpty()) {
    boolean first = true;
    StringBuilder authorsText = new StringBuilder();
    for (String author : authors) {
      if (first) {
        first = false;
      } else {
        authorsText.append(", ");
      }
      authorsText.append(author);
    }
    newTexts.add(authorsText.toString());
  }

  if (pages != null && pages.length() > 0) {
    newTexts.add(pages + "pp.");
  }

  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
源代码30 项目: zxingfragmentlib   文件: BookResultInfoRetriever.java
@Override
void retrieveSupplementalInfo() throws IOException {

  CharSequence contents = HttpHelper.downloadViaHttp("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn,
                                                     HttpHelper.ContentType.JSON);

  if (contents.length() == 0) {
    return;
  }

  String title;
  String pages;
  Collection<String> authors = null;

  try {

    JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue();
    JSONArray items = topLevel.optJSONArray("items");
    if (items == null || items.isNull(0)) {
      return;
    }

    JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo");
    if (volumeInfo == null) {
      return;
    }

    title = volumeInfo.optString("title");
    pages = volumeInfo.optString("pageCount");

    JSONArray authorsArray = volumeInfo.optJSONArray("authors");
    if (authorsArray != null && !authorsArray.isNull(0)) {
      authors = new ArrayList<>(authorsArray.length());
      for (int i = 0; i < authorsArray.length(); i++) {
        authors.add(authorsArray.getString(i));
      }
    }

  } catch (JSONException e) {
    throw new IOException(e);
  }

  Collection<String> newTexts = new ArrayList<>();
  maybeAddText(title, newTexts);
  maybeAddTextSeries(authors, newTexts);
  maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
  
  String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
      + "/search?tbm=bks&source=zxing&q=";

  append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
}
 
 类所在包
 类方法
 同包方法