mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
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:
parent
127839b2b7
commit
0d8a49fa15
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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=");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue