From 74fded6d793e4a8a44f98d83a09af1ce0b271838 Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 13 Apr 2010 16:32:12 +0000 Subject: [PATCH] Better naming of shared barcode files and deal with case where SD card is mounted git-svn-id: http://zxing.googlecode.com/svn/trunk@1306 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- android/res/values-cs/strings.xml | 3 +- android/res/values-de/strings.xml | 1 + android/res/values-es/strings.xml | 1 + android/res/values-fi/strings.xml | 1 + android/res/values-fr/strings.xml | 1 + android/res/values-hu/strings.xml | 1 + android/res/values-it/strings.xml | 1 + android/res/values-ja-rJP/strings.xml | 1 + android/res/values-nl/strings.xml | 1 + android/res/values-pl/strings.xml | 1 + android/res/values-ru/strings.xml | 1 + android/res/values-sv/strings.xml | 1 + android/res/values-zh-rCN/strings.xml | 1 + android/res/values-zh-rTW/strings.xml | 1 + android/res/values/strings.xml | 1 + .../client/android/encode/EncodeActivity.java | 47 +++++++++++++++---- 16 files changed, 54 insertions(+), 10 deletions(-) diff --git a/android/res/values-cs/strings.xml b/android/res/values-cs/strings.xml index 9fd80a17..8c21ca30 100644 --- a/android/res/values-cs/strings.xml +++ b/android/res/values-cs/strings.xml @@ -81,7 +81,8 @@ Neznámá stránka Hledání knihy\u2026 Můžete sdílet čárový kód na vaší obrazovce a skenování, s jiným telefonem. - Here\'s the contents of a barcode I scanned + Zde je obsah čárového kódu I naskenovaný + Prosím, vypnout USB pokračovat. Byl nalezen čárový kód.\u2026 Kopírovat do schránky. Dekódovat 1D kódy diff --git a/android/res/values-de/strings.xml b/android/res/values-de/strings.xml index 21e217ff..bde63b9b 100644 --- a/android/res/values-de/strings.xml +++ b/android/res/values-de/strings.xml @@ -82,6 +82,7 @@ Durchsuche Buch\u2026 Sie können Daten weitergeben, indem Sie einen Barcode auf Ihrem Bilschirm anzeigen und mit einem anderen Telefon einscannen. Hier ist der gescannte Barcode-Inhalt + Bitte schalten Sie USB-Speicher, um fortzufahren. Wenn ein Barcode erkannt wird\u2026 In Zwischenablage kopieren Dekodiere 1D Barcodes diff --git a/android/res/values-es/strings.xml b/android/res/values-es/strings.xml index 2af8684d..a57d1cb4 100644 --- a/android/res/values-es/strings.xml +++ b/android/res/values-es/strings.xml @@ -82,6 +82,7 @@ Buscando libro\u2026 Usted puede compartir los datos mostrando un código de barras en su pantalla y escanear con otro teléfono. Aquí está el contenido de el código de barras que ha escaneado + Por favor, apague de almacenamiento USB para continuar. Cuando encuentra un código de barras\u2026 Copiar al portapapeles Descodificar códigos de barras 1D diff --git a/android/res/values-fi/strings.xml b/android/res/values-fi/strings.xml index 7921e5c3..5af8596a 100644 --- a/android/res/values-fi/strings.xml +++ b/android/res/values-fi/strings.xml @@ -82,6 +82,7 @@ \u2026 Voit jakaa dataa asettamalla viivakoodin näytölle ja lukemalla sen toisella puhelimella. Tässä on viivakoodin skannattu sisältö + Sammuttakaa USB jatkaa. Kun viivakoodi löytyy\u2026 Kopioi leikepöydälle Dekoodaa 1D viivakoodeja diff --git a/android/res/values-fr/strings.xml b/android/res/values-fr/strings.xml index bed2cc40..88411c49 100644 --- a/android/res/values-fr/strings.xml +++ b/android/res/values-fr/strings.xml @@ -82,6 +82,7 @@ Recherche du livre\u2026 Vous pouvez partager des données en affichant un code barre sur votre écran et en le scannant avec un autre téléphone. Voici le contenu du code barre scanné + S\'il vous plaît désactiver stockage USB pour continuer. Quand un code barre est trouvé\u2026 Copier dans le presse papier Décoder les codes barres 1D diff --git a/android/res/values-hu/strings.xml b/android/res/values-hu/strings.xml index 36bd9659..bbccac34 100644 --- a/android/res/values-hu/strings.xml +++ b/android/res/values-hu/strings.xml @@ -85,6 +85,7 @@ Könyv keresése\u2026 Meg tud osztani adatot úgy, hogy egy vonalkódot jelenít meg a képernyőjén, melyet egy másik telefon beszkennel. Itt a tartalma a vonalkódnak, amit beolvastam + Kérem, kapcsolja ki USB tároló is. Amikor a vonalkód megvan\u2026 Másolás a vágólapra 1D vonalkódok megfejtése diff --git a/android/res/values-it/strings.xml b/android/res/values-it/strings.xml index 30da38ee..f9acc2a4 100644 --- a/android/res/values-it/strings.xml +++ b/android/res/values-it/strings.xml @@ -82,6 +82,7 @@ Ricerca libro\u2026 Puoi condividere i dati mostrando un codice a barre sullo schermo e facendo la scansione con un altro telefono. Questo è il contenuto di un codice a barre di prova + Si prega di disattivare la memorizzazione USB per continuare. Quando viene trovato un codice a barre\u2026 Copia negli appunti Decodifica codice a barre 1D diff --git a/android/res/values-ja-rJP/strings.xml b/android/res/values-ja-rJP/strings.xml index 7e09ee95..514b41b0 100644 --- a/android/res/values-ja-rJP/strings.xml +++ b/android/res/values-ja-rJP/strings.xml @@ -82,6 +82,7 @@ 書籍を検索中\u2026 画面にバーコードを表示させ、別の端末でスキャンすれば データを共有することができます。 スキャンしたバーコードの内容を送信します。 + 続行するには、USBストレージをオフにします。 バーコード発見時\u2026 クリップボードにコピーする 1Dバーコードを読み取る diff --git a/android/res/values-nl/strings.xml b/android/res/values-nl/strings.xml index de6ba7e7..cb9192f1 100644 --- a/android/res/values-nl/strings.xml +++ b/android/res/values-nl/strings.xml @@ -82,6 +82,7 @@ Zoekt naar boek\u2026 Je kan data delen door een barcode op je scherm te laten zien, en deze door een andere telefoon te scannen. Hier is de barcode die ik gescand heb + Schakel USB-opslagapparaat te blijven. Als een barcode is gevonden\u2026 Kopieer naar plakbord Decodeer 1D barcodes diff --git a/android/res/values-pl/strings.xml b/android/res/values-pl/strings.xml index 0a8f11db..71f03fa4 100644 --- a/android/res/values-pl/strings.xml +++ b/android/res/values-pl/strings.xml @@ -82,6 +82,7 @@ Przeszukiwanie książki\u2026 Możesz udostępniać dane wyświetlając kod paskowy na swoim ekranie, skanując go innym telefonem. Oto zawartość kodu paskowego który został zeskanowany + Należy wyłączyć pamięć USB, aby kontynuować. Kiedy kod paskowy zostaje odnaleziony\u2026 Kopiuj do schowka Dekoduj kody 1D diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml index 474429fd..c27b8c5c 100644 --- a/android/res/values-ru/strings.xml +++ b/android/res/values-ru/strings.xml @@ -82,6 +82,7 @@ Поиск книги\u2026 Вы можете поделиться данными, сканировав штрих-код с вашего экрана другим телефоном. Тут содержимое отсканированных Вами штрих-кодов + Пожалуйста, отключите USB хранения, чтобы продолжить. Когда штрих-код найден\u2026 Копировать в буфер обмена Распознавать линейные штрих-коды diff --git a/android/res/values-sv/strings.xml b/android/res/values-sv/strings.xml index 109160ed..cf1b0249 100644 --- a/android/res/values-sv/strings.xml +++ b/android/res/values-sv/strings.xml @@ -82,6 +82,7 @@ Söker bok\u2026 Di kan dela data genom att visa en streckkod på din skärm och läsa den med en annan telefon. Detta är vad en streckod jag skannade innehöll + Stäng av USB-minnen för att fortsätta. När en streckkod hittats\u2026 Kopiera till klippbordet Avkoda 1D steckkod diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml index 0ddf4aa1..f58af701 100644 --- a/android/res/values-zh-rCN/strings.xml +++ b/android/res/values-zh-rCN/strings.xml @@ -82,6 +82,7 @@ 搜索图书\u2026 你可以在你的手机屏幕上显示条码,并使用其他手机扫描此条码方式进行分享 这是我所扫描条码的内容 + 请关闭USB存储继续。 找到条码时\u2026 复制到剪切板 解码一维条码 diff --git a/android/res/values-zh-rTW/strings.xml b/android/res/values-zh-rTW/strings.xml index 94fe9dc3..89fc320d 100644 --- a/android/res/values-zh-rTW/strings.xml +++ b/android/res/values-zh-rTW/strings.xml @@ -82,6 +82,7 @@ 搜索圖書\u2026 你可以在你的手機屏幕上顯示條碼,并使用其他手機掃描此條碼方式進行分享 這是我所掃描條碼的內容 + 請關閉 USB存儲繼續。 找到條碼時\u2026 復制到剪切板 解碼一維條碼 diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index b91ffc6a..4dce2cb7 100755 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -82,6 +82,7 @@ Searching book\u2026 You can share data by displaying a barcode on your screen and scanning it with another phone. Here\'s the contents of a barcode I scanned + Please turn off USB storage to continue. When a barcode is found\u2026 Copy to clipboard Decode 1D barcodes diff --git a/android/src/com/google/zxing/client/android/encode/EncodeActivity.java b/android/src/com/google/zxing/client/android/encode/EncodeActivity.java index 3f9771f3..d0db91d9 100755 --- a/android/src/com/google/zxing/client/android/encode/EncodeActivity.java +++ b/android/src/com/google/zxing/client/android/encode/EncodeActivity.java @@ -43,6 +43,7 @@ import android.widget.ImageView; import android.widget.TextView; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -57,6 +58,7 @@ public final class EncodeActivity extends Activity { private static final String TAG = EncodeActivity.class.getSimpleName(); private static final int SHARE_BARCODE_DIMENSION = 300; + private static final int MAX_BARCODE_FILENAME_LENGTH = 24; private QRCodeEncoder qrCodeEncoder; private ProgressDialog progressDialog; @@ -153,10 +155,10 @@ public final class EncodeActivity extends Activity { return true; } - + String contents = qrCodeEncoder.getContents(); Bitmap bitmap; try { - bitmap = QRCodeEncoder.encodeAsBitmap(qrCodeEncoder.getContents(), + bitmap = QRCodeEncoder.encodeAsBitmap(contents, BarcodeFormat.QR_CODE, SHARE_BARCODE_DIMENSION, SHARE_BARCODE_DIMENSION); @@ -168,14 +170,27 @@ public final class EncodeActivity extends Activity { File barcodeFile; try { File bsRoot = new File(Environment.getExternalStorageDirectory(), "BarcodeScanner"); - bsRoot.mkdir(); - File barcodesRoot = new File(bsRoot, "barcodes"); - barcodesRoot.mkdir(); - barcodeFile = new File(barcodesRoot, "barcode-" + System.currentTimeMillis() + ".png"); + File barcodesRoot = new File(bsRoot, "Barcodes"); + if (!barcodesRoot.mkdirs()) { + Log.v(TAG, "Couldn't make dir " + barcodesRoot); + showErrorMessage(R.string.msg_unmount_usb); + return true; + } + barcodeFile = new File(barcodesRoot, makeBarcodeFileName(contents) + ".png"); barcodeFile.delete(); - FileOutputStream fos = new FileOutputStream(barcodeFile); - bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos); - fos.close(); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(barcodeFile); + bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos); + } catch (FileNotFoundException fnfe) { + Log.v(TAG, "Couldn't access file " + barcodeFile + " due to " + fnfe); + showErrorMessage(R.string.msg_unmount_usb); + return true; + } finally { + if (fos != null) { + fos.close(); + } + } } catch (IOException ioe) { Log.w(TAG, ioe.toString()); return true; @@ -191,6 +206,20 @@ public final class EncodeActivity extends Activity { return true; } + private static CharSequence makeBarcodeFileName(CharSequence contents) { + int fileNameLength = Math.min(MAX_BARCODE_FILENAME_LENGTH, contents.length()); + StringBuilder fileName = new StringBuilder(fileNameLength); + for (int i = 0; i < fileNameLength; i++) { + char c = contents.charAt(i); + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { + fileName.append(c); + } else { + fileName.append('_'); + } + } + return fileName; + } + @Override protected void onResume() { super.onResume(); -- 2.20.1