Added better Google Book Search URL detection and centralized it.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1815 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin@google.com 2011-06-08 18:23:35 +00:00
parent 127839b2b7
commit 0d8a49fa15
3 changed files with 16 additions and 9 deletions

View file

@ -110,6 +110,15 @@ public final class LocaleManager {
return doGetTLD(GOOGLE_BOOK_SEARCH_COUNTRY_TLD);
}
/**
* Does a given URL point to Google Book Search, regardless of domain.
*
* @param url The address to check.
* @return True if this is a Book Search URL.
*/
public static boolean isBookSearchUrl(String url) {
return url.startsWith("http://google.com/books") || url.startsWith("http://books.google.");
}
private static String doGetTLD(Map<Locale,String> map) {
Locale locale = Locale.getDefault();

View file

@ -48,6 +48,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import com.google.zxing.client.android.LocaleManager;
import com.google.zxing.client.android.R;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.AndroidHttpClient;
@ -58,7 +59,6 @@ import com.google.zxing.client.android.AndroidHttpClient;
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class SearchBookContentsActivity extends Activity {
private static final String TAG = SearchBookContentsActivity.class.getSimpleName();
private static final String USER_AGENT = "ZXing (Android)";
@ -126,8 +126,7 @@ public final class SearchBookContentsActivity extends Activity {
}
isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
// FIXME(dswitkin): Should not hardcode Books URL. Also does not handle books.google.ca etc.
if (isbn.startsWith("http://google.com/books?id=")) {
if (LocaleManager.isBookSearchUrl(isbn)) {
setTitle(getString(R.string.sbc_name));
} else {
setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);

View file

@ -16,6 +16,7 @@
package com.google.zxing.client.android.result;
import com.google.zxing.client.android.LocaleManager;
import com.google.zxing.client.android.R;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.URIParsedResult;
@ -47,7 +48,10 @@ public final class URIResultHandler extends ResultHandler {
@Override
public int getButtonCount() {
return isGoogleBooksURI() ? buttons.length : buttons.length - 1;
if (LocaleManager.isBookSearchUrl(((URIParsedResult) getResult()).getURI())) {
return buttons.length;
}
return buttons.length - 1;
}
@Override
@ -91,9 +95,4 @@ public final class URIResultHandler extends ResultHandler {
}
return false;
}
private boolean isGoogleBooksURI() {
// FIXME(dswitkin): Should not hardcode Books URL. Also does not handle books.google.ca etc.
return ((URIParsedResult) getResult()).getURI().startsWith("http://google.com/books?id=");
}
}