Fix handling of book search snippets without page number

git-svn-id: https://zxing.googlecode.com/svn/trunk@2835 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-07-01 19:29:10 +00:00
parent e8a23d5085
commit 8e1b1a3bb4
33 changed files with 32 additions and 58 deletions

View file

@ -16,8 +16,8 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.zxing.client.android"
android:versionName="4.4"
android:versionCode="91"
android:versionName="4.4.1"
android:versionCode="92"
android:installLocation="auto">
<uses-permission android:name="android.permission.CAMERA"/>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">النتائج</string>
<string name="msg_sbc_searching_book">البحث في الكتاب</string>
<string name="msg_sbc_snippet_unavailable">الأجزاء غير متاحة</string>
<string name="msg_sbc_unknown_page">صفحة غير معروفة</string>
<string name="msg_share_explanation">يمكنك مشاركة البيانات عن طريق عرض رمز شريطي على الشاشة ومسحه من خلال هاتف آخر.</string>
<string name="msg_share_subject_line">توجد هنا محتويات الرمز الشريطي الذي قمت بمسحه</string>
<string name="msg_share_text">أو اكتب بعض النص</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Резултати</string>
<string name="msg_sbc_searching_book">Търсене на книга\u2026</string>
<string name="msg_sbc_snippet_unavailable">Изрезката не е достъпна</string>
<string name="msg_sbc_unknown_page">Непозната страница</string>
<string name="msg_share_explanation">Можете да споделяте информация като покажете баркод на екрана, и го сканирате от друг телефон.</string>
<string name="msg_share_subject_line">Ето съдържанието на един баркод, който сканирах</string>
<string name="msg_share_text">Или въведете някакъв текст</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Resultats</string>
<string name="msg_sbc_searching_book">S\'està cercant el llibre\u2026</string>
<string name="msg_sbc_snippet_unavailable">Fragment no disponible</string>
<string name="msg_sbc_unknown_page">Pàgina desconeguda</string>
<string name="msg_share_explanation">Podeu compartir dades mostrant un codi de barres a la pantalla i escanejant-lo amb un altre dispositiu.</string>
<string name="msg_share_subject_line">Aquí hi ha el contingut d\'un codi de barres que he escanejat</string>
<string name="msg_share_text">O escriviu un text i pitgeu Retorn</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Výsledky</string>
<string name="msg_sbc_searching_book">Hledání knihy\u2026</string>
<string name="msg_sbc_snippet_unavailable">Snippet není k dispozici</string>
<string name="msg_sbc_unknown_page">Neznámá stránka</string>
<string name="msg_share_explanation">Můžete sdílet čárový kód na vaší obrazovce a skenování, s jiným telefonem.</string>
<string name="msg_share_subject_line">Zde je obsah čárového kódu I naskenovaný</string>
<string name="msg_share_text">Nebo zadejte nějaký text</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Resultater</string>
<string name="msg_sbc_searching_book">Søger bog\u2026</string>
<string name="msg_sbc_snippet_unavailable">Uddragsvisning ikke tilgængelig</string>
<string name="msg_sbc_unknown_page">Ukendt side</string>
<string name="msg_share_explanation">Du kan dele data ved at vise en stregkode på denne skærm, og derefter scanne den med en anden telefon.</string>
<string name="msg_share_subject_line">Her er indholdet af en stregkode, jeg har scannet.</string>
<string name="msg_share_text">Eller skriv noget tekst</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Ergebnisse</string>
<string name="msg_sbc_searching_book">Durchsuche Buch\u2026</string>
<string name="msg_sbc_snippet_unavailable">Textschnipsel nicht verfügbar.</string>
<string name="msg_sbc_unknown_page">Unbekannte Seite</string>
<string name="msg_share_explanation">Sie können Daten weitergeben, indem Sie einen Barcode auf Ihrem Bilschirm erzeugen und mit einem anderen Handy einscannen.</string>
<string name="msg_share_subject_line">Hier ist der gescannte Barcode-Inhalt</string>
<string name="msg_share_text">Oder geben Sie einen Text hier</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Αποτελέσματα</string>
<string name="msg_sbc_searching_book">Άναζήτηση βιβλίου\u2026</string>
<string name="msg_sbc_snippet_unavailable">Απόσπασμα μη διαθέσιμο</string>
<string name="msg_sbc_unknown_page">Άγνωστη σελίδα</string>
<string name="msg_share_explanation">Μπορείς να μοιραστείς δεδομένα εμφανίζοντας ένα barcode στην οθόνη σου και σκανάροντάς το με ένα άλλο κινητό.</string>
<string name="msg_share_subject_line">Αυτά είναι τα περιεχόμενα ενός barcode που σκάναρα</string>
<string name="msg_share_text">Ή πληκτολογήστε εδώ κείμενο και πατήστε Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Resultados</string>
<string name="msg_sbc_searching_book">Buscando libro\u2026</string>
<string name="msg_sbc_snippet_unavailable">Fragmentos no están disponibles</string>
<string name="msg_sbc_unknown_page">Página desconocida</string>
<string name="msg_share_explanation">Usted puede compartir los datos mostrando un código de barras en su pantalla y escanearlo con otro teléfono.</string>
<string name="msg_share_subject_line">Estos son los contenidos del código de barras que he escaneado</string>
<string name="msg_share_text">O escriba algún texto y presione Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Emaitzak</string>
<string name="msg_sbc_searching_book">Liburua arakatzen\u2026</string>
<string name="msg_sbc_snippet_unavailable">Lagina ez dago eskuragarri</string>
<string name="msg_sbc_unknown_page">Orri ezezaguna</string>
<string name="msg_share_explanation">Datuak parteka ditzakezu zure pantailan barra-kode bat bistaratu eta beste telefono batekin eskaneatuz.</string>
<string name="msg_share_subject_line">Hemen daude eskaneatu dudan barra-kodearen edukiak</string>
<string name="msg_share_text">Edo idatzi zerbait eta sakatu Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Tulokset</string>
<string name="msg_sbc_searching_book">Haetaan kirjaa\u2026</string>
<string name="msg_sbc_snippet_unavailable">Kappaletta ei saatavilla</string>
<string name="msg_sbc_unknown_page">Tuntematon sivu</string>
<string name="msg_share_explanation">Voit jakaa dataa näyttämällä viivakoodin laitteesi näytöllä ja lukemalla sen toisella laitteella.</string>
<string name="msg_share_subject_line">Tässä on viivakoodin skannattu sisältö</string>
<string name="msg_share_text">Tai kirjoita tekstiä</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Résultats</string>
<string name="msg_sbc_searching_book">Recherche du livre\u2026</string>
<string name="msg_sbc_snippet_unavailable">Extrait non disponible</string>
<string name="msg_sbc_unknown_page">Page inconnue</string>
<string name="msg_share_explanation">Vous pouvez partager des données en affichant un code-barres sur votre écran et en le scannant avec un autre téléphone.</string>
<string name="msg_share_subject_line">Voici le contenu d\'un code-barres que j\'ai scanné</string>
<string name="msg_share_text">Ou tapez du texte</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">תוצאות</string>
<string name="msg_sbc_searching_book">מחפש ספר\u2026</string>
<string name="msg_sbc_snippet_unavailable">גזיר לא זמין</string>
<string name="msg_sbc_unknown_page">דף לא ידוע</string>
<string name="msg_share_explanation">באפשרותך לשתף נתונים על-ידי הצגת ברקוד על המסך וסריקתו עם טלפון אחר.</string>
<string name="msg_share_subject_line">הנה התוכן של הברקוד שסרקתי</string>
<string name="msg_share_text">או הקלד טקסט כלשהו</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">परिणाम</string>
<string name="msg_sbc_searching_book">खोज पुस्तक\u2026</string>
<string name="msg_sbc_snippet_unavailable">उपलब्ध स्निपेट नहीं</string>
<string name="msg_sbc_unknown_page">अज्ञात पृष्ठ</string>
<string name="msg_share_explanation">आप अपनी स्क्रीन पर प्रदर्शित बारकोड और यह अन्य फोन के साथ स्कैनिंग द्वारा डेटा साझा कर सकते हैं.</string>
<string name="msg_share_subject_line">यहाँ मैं एक बारकोड स्कैन की सामग्री</string>
<string name="msg_share_text">या कुछ पाठ टाइप करें और प्रेस दर्ज करें</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Eredmények</string>
<string name="msg_sbc_searching_book">Könyv keresése\u2026</string>
<string name="msg_sbc_snippet_unavailable">Kódrészlet nem elérhető</string>
<string name="msg_sbc_unknown_page">Ismeretlen oldal</string>
<string name="msg_share_explanation">Meg tud osztani adatot úgy, hogy egy vonalkódot jelenít meg a képernyőjén, melyet egy másik telefon beszkennel.</string>
<string name="msg_share_subject_line">Itt a beolvasott vonalkód tartalma</string>
<string name="msg_share_text">Vagy írja be a szöveget és nyomjon Enter-t</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Hasil</string>
<string name="msg_sbc_searching_book">Mencari buku\u2026</string>
<string name="msg_sbc_snippet_unavailable">Snippet tidak tersedia</string>
<string name="msg_sbc_unknown_page">Halaman tidak dikenal</string>
<string name="msg_share_explanation">Anda dapat berbagi data dengan menampilkan barcode di layar Anda dan dapat dipindai oleh phone lain.</string>
<string name="msg_share_subject_line">Ini adalah isi barcode yang saya pindai</string>
<string name="msg_share_text">Atau masukkan beberapa kata dan tekan Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Risultati</string>
<string name="msg_sbc_searching_book">Ricerca libro\u2026</string>
<string name="msg_sbc_snippet_unavailable">Ritaglio non disponibile</string>
<string name="msg_sbc_unknown_page">Pagina sconosciuta</string>
<string name="msg_share_explanation">Puoi condividere i dati mostrando un codice a barre sullo schermo e facendo la scansione con un altro telefono.</string>
<string name="msg_share_subject_line">Questo è il contenuto di un codice a barre di prova</string>
<string name="msg_share_text">O digitare un testo</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">תוצאות</string>
<string name="msg_sbc_searching_book">מחפש ספר\u2026</string>
<string name="msg_sbc_snippet_unavailable">גזיר לא זמין</string>
<string name="msg_sbc_unknown_page">דף לא ידוע</string>
<string name="msg_share_explanation">באפשרותך לשתף נתונים על-ידי הצגת ברקוד על המסך וסריקתו עם טלפון אחר.</string>
<string name="msg_share_subject_line">הנה התוכן של הברקוד שסרקתי</string>
<string name="msg_share_text">או הקלד טקסט כלשהו</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">結果</string>
<string name="msg_sbc_searching_book">書籍を検索中</string>
<string name="msg_sbc_snippet_unavailable">要約文はありません</string>
<string name="msg_sbc_unknown_page">不明なページ</string>
<string name="msg_share_explanation">画面にQRコードを表示させて別の端末でスキャンすれば、データを共有することができます。</string>
<string name="msg_share_subject_line">スキャンしたQRコードの内容を送信します。</string>
<string name="msg_share_text">またはテキストを入力してください</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">결과</string>
<string name="msg_sbc_searching_book">책 검색중\u2026</string>
<string name="msg_sbc_snippet_unavailable">내용이 열람되지 않습니다.</string>
<string name="msg_sbc_unknown_page">알수 없는 페이지</string>
<string name="msg_share_explanation">해당 기기의 바코드를 다른 기기로 스캔해서 데이터를 공유할 수 있습니다.</string>
<string name="msg_share_subject_line">제가 스캔한 바코드 목록입니다.</string>
<string name="msg_share_text">입력하거나 텍스트</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Resultaten</string>
<string name="msg_sbc_searching_book">Boek doorzoeken\u2026</string>
<string name="msg_sbc_snippet_unavailable">Fragment niet beschikbaar</string>
<string name="msg_sbc_unknown_page">Onbekende pagina</string>
<string name="msg_share_explanation">Je kunt gegevens delen door een barcode op je scherm te laten zien en deze met een andere telefoon te scannen.</string>
<string name="msg_share_subject_line">Hier is de inhoud van een barcode die ik heb gescand</string>
<string name="msg_share_text">Of typ wat tekst en druk op Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Wyniki</string>
<string name="msg_sbc_searching_book">Przeszukiwanie książki\u2026</string>
<string name="msg_sbc_snippet_unavailable">Wycinek niedostępny</string>
<string name="msg_sbc_unknown_page">Nieznana strona</string>
<string name="msg_share_explanation">Możesz udostępniać dane wyświetlając kod paskowy na swoim ekranie i skanując go innym telefonem.</string>
<string name="msg_share_subject_line">Oto zawartość kodu paskowego który został zeskanowany</string>
<string name="msg_share_text">Albo wpisz tekst</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Resultados</string>
<string name="msg_sbc_searching_book">A procurar livro\u2026</string>
<string name="msg_sbc_snippet_unavailable">Trecho não disponível</string>
<string name="msg_sbc_unknown_page">Página desconhecida</string>
<string name="msg_share_explanation">Pode partilhar dados exibindo um código de barras no seu ecrã e lendo-o com outro telemóvel</string>
<string name="msg_share_subject_line">Aqui estão os conteúdos do código de barras lido</string>
<string name="msg_share_text">Ou introduza algum texto e pressione Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Rezultate</string>
<string name="msg_sbc_searching_book">Caută cartea\u2026</string>
<string name="msg_sbc_snippet_unavailable">Fragment indisponibil</string>
<string name="msg_sbc_unknown_page">Pagină necunoscută</string>
<string name="msg_share_explanation">Poți distribui datele afișând codul pe ecran și scanându-l cu alt aparat</string>
<string name="msg_share_subject_line">Conținutul codului de bare scanat</string>
<string name="msg_share_text">Sau introdu textul și tastează Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Результаты</string>
<string name="msg_sbc_searching_book">Поиск книги\u2026</string>
<string name="msg_sbc_snippet_unavailable">Фрагмент недоступен</string>
<string name="msg_sbc_unknown_page">Неизвестная страница</string>
<string name="msg_share_explanation">Вы можете поделиться данными, сканируя штрих-код с вашего экрана другим телефоном.</string>
<string name="msg_share_subject_line">Данные отсканированных Вами штрих-кодов</string>
<string name="msg_share_text">Или введите текст</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Výsledky</string>
<string name="msg_sbc_searching_book">Vyhľadáva sa kniha\u2026</string>
<string name="msg_sbc_snippet_unavailable">Úryvok nie je k dispozícii</string>
<string name="msg_sbc_unknown_page">Neznáma stránka</string>
<string name="msg_share_explanation">Môžete zdieľať dáta zobrazením čiarového kódu na displeji vášho zariadenia a jeho zoskenovaním iným zariadením</string>
<string name="msg_share_subject_line">Tu je obsah naskenovaného čiarového kódu</string>
<string name="msg_share_text">Alebo zadajte nejaký text</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Rezultati</string>
<string name="msg_sbc_searching_book">Iščem knjigo\u2026</string>
<string name="msg_sbc_snippet_unavailable">Košček ni na voljo</string>
<string name="msg_sbc_unknown_page">Neznana stran</string>
<string name="msg_share_explanation">Lahko delite podatke s prikazom črtne kode na vašem zaslonu in branju le-te z drugim mobilnim telefonom.</string>
<string name="msg_share_subject_line">Tu je vsebina prebrane črtne kode</string>
<string name="msg_share_text">Ali vnesite nekaj besedila</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Resultat</string>
<string name="msg_sbc_searching_book">Söker bok\u2026</string>
<string name="msg_sbc_snippet_unavailable">Utdrag ej tillgängligt</string>
<string name="msg_sbc_unknown_page">Okänd sida</string>
<string name="msg_share_explanation">Du kan dela information genom att visa en streckkod på din skärm och sedan skanna in den med en annan telefon.</string>
<string name="msg_share_subject_line">Här är innehållet i en streckkod som jag har skannat in</string>
<string name="msg_share_text">Eller skriv in text och tryck Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Sonuçlar</string>
<string name="msg_sbc_searching_book">Kitap aranıyor\u2026</string>
<string name="msg_sbc_snippet_unavailable">Parçacık yok</string>
<string name="msg_sbc_unknown_page">Bilinmeyen sayfa</string>
<string name="msg_share_explanation">Ekranınızda görüntülediğiniz barkodu başka bir telefonla tarayarak veri paylaşabilirsiniz.</string>
<string name="msg_share_subject_line">Taranan barkodun içeriği</string>
<string name="msg_share_text">Veya yazın bazı metin</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">结果</string>
<string name="msg_sbc_searching_book">搜索图书…</string>
<string name="msg_sbc_snippet_unavailable">摘录不可用</string>
<string name="msg_sbc_unknown_page">未知页面</string>
<string name="msg_share_explanation">您可以通过在自己的手机上显示条码,并使用其它手机扫描此条码的方式进行分享</string>
<string name="msg_share_subject_line">这是我所扫描条码的内容</string>
<string name="msg_share_text">或键入一些文字</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">結果</string>
<string name="msg_sbc_searching_book">搜尋圖書中\u2026</string>
<string name="msg_sbc_snippet_unavailable">無法取得摘要</string>
<string name="msg_sbc_unknown_page">未知的頁面</string>
<string name="msg_share_explanation">你可以在你的手機螢幕上顯示條碼,並使用其他手機掃描此條碼藉此分享給朋友</string>
<string name="msg_share_subject_line">這是我所掃描的條碼的內容</string>
<string name="msg_share_text">或輸入一些文字並按 Enter</string>

View file

@ -85,7 +85,6 @@
<string name="msg_sbc_results">Results</string>
<string name="msg_sbc_searching_book">Searching book\u2026</string>
<string name="msg_sbc_snippet_unavailable">Snippet not available</string>
<string name="msg_sbc_unknown_page">Unknown page</string>
<string name="msg_share_explanation">You can share data by displaying a barcode on your screen and scanning it with another phone.</string>
<string name="msg_share_subject_line">Here are the contents of a barcode I scanned</string>
<string name="msg_share_text">Or type some text and press Enter</string>

View file

@ -239,38 +239,43 @@ public final class SearchBookContentsActivity extends Activity {
}
}
// Available fields: page_id, page_number, page_url, snippet_text
// Available fields: page_id, page_number, snippet_text
private SearchBookContentsResult parseResult(JSONObject json) {
try {
String pageId = json.getString("page_id");
String pageNumber = json.getString("page_number");
if (pageNumber.isEmpty()) {
// This can happen for text on the jacket, and possibly other reasons.
pageNumber = getString(R.string.msg_sbc_unknown_page);
} else {
pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber;
}
// Remove all HTML tags and encoded characters. Ideally the server would do this.
String snippet = json.optString("snippet_text");
boolean valid = true;
if (snippet.isEmpty()) {
snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')';
valid = false;
} else {
snippet = TAG_PATTERN.matcher(snippet).replaceAll("");
snippet = LT_ENTITY_PATTERN.matcher(snippet).replaceAll("<");
snippet = GT_ENTITY_PATTERN.matcher(snippet).replaceAll(">");
snippet = QUOTE_ENTITY_PATTERN.matcher(snippet).replaceAll("'");
snippet = QUOT_ENTITY_PATTERN.matcher(snippet).replaceAll("\"");
}
return new SearchBookContentsResult(pageId, pageNumber, snippet, valid);
String pageId;
String pageNumber;
String snippet;
try {
pageId = json.getString("page_id");
pageNumber = json.optString("page_number");
snippet = json.optString("snippet_text");
} catch (JSONException e) {
Log.w(TAG, e);
// Never seen in the wild, just being complete.
return new SearchBookContentsResult(getString(R.string.msg_sbc_no_page_returned), "", "", false);
}
}
if (pageNumber == null || pageNumber.isEmpty()) {
// This can happen for text on the jacket, and possibly other reasons.
pageNumber = "";
} else {
pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber;
}
boolean valid = snippet != null && !snippet.isEmpty();
if (valid) {
// Remove all HTML tags and encoded characters.
snippet = TAG_PATTERN.matcher(snippet).replaceAll("");
snippet = LT_ENTITY_PATTERN.matcher(snippet).replaceAll("<");
snippet = GT_ENTITY_PATTERN.matcher(snippet).replaceAll(">");
snippet = QUOTE_ENTITY_PATTERN.matcher(snippet).replaceAll("'");
snippet = QUOT_ENTITY_PATTERN.matcher(snippet).replaceAll("\"");
} else {
snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')';
}
return new SearchBookContentsResult(pageId, pageNumber, snippet, valid);
}
}