コード例 #1
0
ファイル: URIResultHandler.java プロジェクト: pythe/wristpass
 @Override
 public int getButtonCount() {
   if (LocaleManager.isBookSearchUrl(((URIParsedResult) getResult()).getURI())) {
     return buttons.length;
   }
   return buttons.length - 1;
 }
コード例 #2
0
 @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;
   }
 }
コード例 #3
0
ファイル: ResultHandler.java プロジェクト: q394304565/MSC
 final void openBookSearch(String isbn) {
   Uri uri =
       Uri.parse(
           "http://books.google."
               + LocaleManager.getBookSearchCountryTLD(activity)
               + "/books?vid=isbn"
               + isbn);
   launchIntent(new Intent(Intent.ACTION_VIEW, uri));
 }
コード例 #4
0
  @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>();
    maybeAddText(title, newTexts);
    maybeAddTextSeries(authors, newTexts);
    maybeAddText(pages == null || pages.length() == 0 ? 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);
  }
コード例 #5
0
ファイル: ResultHandler.java プロジェクト: q394304565/MSC
 // Uses the mobile-specific version of Product Search, which is formatted for small screens.
 final void openProductSearch(String upc) {
   Uri uri =
       Uri.parse(
           "http://www.google."
               + LocaleManager.getProductSearchCountryTLD(activity)
               + "/m/products?q="
               + upc
               + "&source=zxing");
   launchIntent(new Intent(Intent.ACTION_VIEW, uri));
 }
コード例 #6
0
ファイル: ResultHandler.java プロジェクト: q394304565/MSC
 final void getDirections(double latitude, double longitude) {
   launchIntent(
       new Intent(
           Intent.ACTION_VIEW,
           Uri.parse(
               "http://maps.google."
                   + LocaleManager.getCountryTLD(activity)
                   + "/maps?f=d&daddr="
                   + latitude
                   + ','
                   + longitude)));
 }
コード例 #7
0
 AmazonInfoRetriever(
     TextView textView,
     String type,
     String productID,
     HistoryManager historyManager,
     Context context) {
   super(textView, historyManager);
   String country = LocaleManager.getCountry(context);
   if ("ISBN".equals(type) && !Locale.US.getCountry().equals(country)) {
     type = "EAN";
   }
   this.type = type;
   this.productID = productID;
   this.country = country;
 }
コード例 #8
0
final class ProductResultInfoRetriever extends SupplementalInfoRetriever {

  private static final String BASE_PRODUCT_URI =
      "http://www.google."
          + LocaleManager.getProductSearchCountryTLD()
          + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=";
  private static final Pattern PRODUCT_NAME_PRICE_PATTERN =
      Pattern.compile("owb63p\">([^<]+).+zdi3pb\">([^<]+)");

  private final String productID;
  private final String source;

  ProductResultInfoRetriever(
      TextView textView,
      String productID,
      Handler handler,
      HistoryManager historyManager,
      Context context) {
    super(textView, handler, historyManager);
    this.productID = productID;
    this.source = context.getString(R.string.msg_google_product);
  }

  @Override
  void retrieveSupplementalInfo() throws IOException, InterruptedException {

    String encodedProductID = URLEncoder.encode(productID, "UTF-8");
    String uri = BASE_PRODUCT_URI + 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);
    }
  }

  private static String unescapeHTML(String raw) {
    return Html.fromHtml(raw).toString();
  }
}
コード例 #9
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Make sure that expired cookies are removed on launch.
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().removeExpiredCookie();

    Intent intent = getIntent();
    if (intent == null || !intent.getAction().equals(Intents.SearchBookContents.ACTION)) {
      finish();
      return;
    }

    isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    if (LocaleManager.isBookSearchUrl(isbn)) {
      setTitle(getString(R.string.sbc_name));
    } else {
      setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);
    }

    setContentView(R.layout.search_book_contents);
    queryTextView = (EditText) findViewById(R.id.query_text_view);

    String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
    if (initialQuery != null && !initialQuery.isEmpty()) {
      // Populate the search box but don't trigger the search
      queryTextView.setText(initialQuery);
    }
    queryTextView.setOnKeyListener(keyListener);

    queryButton = findViewById(R.id.query_button);
    queryButton.setOnClickListener(buttonListener);

    resultListView = (ListView) findViewById(R.id.result_list_view);
    LayoutInflater factory = LayoutInflater.from(this);
    headerView =
        (TextView) factory.inflate(R.layout.search_book_contents_header, resultListView, false);
    resultListView.addHeaderView(headerView);
  }
コード例 #10
0
  @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;
      }
    }
  }