Better naming of shared barcode files and deal with case where SD card is mounted

git-svn-id: https://zxing.googlecode.com/svn/trunk@1306 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-04-13 16:32:12 +00:00
parent d85cd8f70e
commit aacdce8d7e
16 changed files with 54 additions and 10 deletions

View file

@ -81,7 +81,8 @@
<string name="msg_sbc_unknown_page">Neznámá stránka</string>
<string name="msg_sbc_searching_book">Hledání knihy\u2026</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">Here\'s the contents of a barcode I scanned</string>
<string name="msg_share_subject_line">Zde je obsah čárového kódu I naskenovaný</string>
<string name="msg_unmount_usb">Prosím, vypnout USB pokračovat.</string>
<string name="preferences_actions_title">Byl nalezen čárový kód.\u2026</string>
<string name="preferences_copy_to_clipboard_title">Kopírovat do schránky.</string>
<string name="preferences_decode_1D_title">Dekódovat 1D kódy</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Durchsuche Buch\u2026</string>
<string name="msg_share_explanation">Sie können Daten weitergeben, indem Sie einen Barcode auf Ihrem Bilschirm anzeigen und mit einem anderen Telefon einscannen.</string>
<string name="msg_share_subject_line">Hier ist der gescannte Barcode-Inhalt</string>
<string name="msg_unmount_usb">Bitte schalten Sie USB-Speicher, um fortzufahren.</string>
<string name="preferences_actions_title">Wenn ein Barcode erkannt wird\u2026</string>
<string name="preferences_copy_to_clipboard_title">In Zwischenablage kopieren</string>
<string name="preferences_decode_1D_title">Dekodiere 1D Barcodes</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Buscando libro\u2026</string>
<string name="msg_share_explanation">Usted puede compartir los datos mostrando un código de barras en su pantalla y escanear con otro teléfono.</string>
<string name="msg_share_subject_line">Aquí está el contenido de el código de barras que ha escaneado</string>
<string name="msg_unmount_usb">Por favor, apague de almacenamiento USB para continuar.</string>
<string name="preferences_actions_title">Cuando encuentra un código de barras\u2026</string>
<string name="preferences_copy_to_clipboard_title">Copiar al portapapeles</string>
<string name="preferences_decode_1D_title">Descodificar códigos de barras 1D</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">\u2026</string>
<string name="msg_share_explanation">Voit jakaa dataa asettamalla viivakoodin näytölle ja lukemalla sen toisella puhelimella.</string>
<string name="msg_share_subject_line">Tässä on viivakoodin skannattu sisältö</string>
<string name="msg_unmount_usb">Sammuttakaa USB jatkaa.</string>
<string name="preferences_actions_title">Kun viivakoodi löytyy\u2026</string>
<string name="preferences_copy_to_clipboard_title">Kopioi leikepöydälle</string>
<string name="preferences_decode_1D_title">Dekoodaa 1D viivakoodeja</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Recherche du livre\u2026</string>
<string name="msg_share_explanation">Vous pouvez partager des données en affichant un code barre sur votre écran et en le scannant avec un autre téléphone.</string>
<string name="msg_share_subject_line">Voici le contenu du code barre scanné</string>
<string name="msg_unmount_usb">S\'il vous plaît désactiver stockage USB pour continuer.</string>
<string name="preferences_actions_title">Quand un code barre est trouvé\u2026</string>
<string name="preferences_copy_to_clipboard_title">Copier dans le presse papier</string>
<string name="preferences_decode_1D_title">Décoder les codes barres 1D</string>

View file

@ -85,6 +85,7 @@
<string name="msg_sbc_searching_book">Könyv keresése\u2026</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 tartalma a vonalkódnak, amit beolvastam</string>
<string name="msg_unmount_usb">Kérem, kapcsolja ki USB tároló is.</string>
<string name="preferences_actions_title">Amikor a vonalkód megvan\u2026</string>
<string name="preferences_copy_to_clipboard_title">Másolás a vágólapra</string>
<string name="preferences_decode_1D_title">1D vonalkódok megfejtése</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Ricerca libro\u2026</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_unmount_usb">Si prega di disattivare la memorizzazione USB per continuare.</string>
<string name="preferences_actions_title">Quando viene trovato un codice a barre\u2026</string>
<string name="preferences_copy_to_clipboard_title">Copia negli appunti</string>
<string name="preferences_decode_1D_title">Decodifica codice a barre 1D</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">書籍を検索中\u2026</string>
<string name="msg_share_explanation">画面にバーコードを表示させ、別の端末でスキャンすれば データを共有することができます。</string>
<string name="msg_share_subject_line">スキャンしたバーコードの内容を送信します。</string>
<string name="msg_unmount_usb">続行するには、USBストレージをオフにします。</string>
<string name="preferences_actions_title">バーコード発見時\u2026</string>
<string name="preferences_copy_to_clipboard_title">クリップボードにコピーする</string>
<string name="preferences_decode_1D_title">1Dバーコードを読み取る</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Zoekt naar boek\u2026</string>
<string name="msg_share_explanation">Je kan data delen door een barcode op je scherm te laten zien, en deze door een andere telefoon te scannen.</string>
<string name="msg_share_subject_line">Hier is de barcode die ik gescand heb</string>
<string name="msg_unmount_usb">Schakel USB-opslagapparaat te blijven.</string>
<string name="preferences_actions_title">Als een barcode is gevonden\u2026</string>
<string name="preferences_copy_to_clipboard_title">Kopieer naar plakbord</string>
<string name="preferences_decode_1D_title">Decodeer 1D barcodes</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Przeszukiwanie książki\u2026</string>
<string name="msg_share_explanation">Możesz udostępniać dane wyświetlając kod paskowy na swoim ekranie, skanując go innym telefonem.</string>
<string name="msg_share_subject_line">Oto zawartość kodu paskowego który został zeskanowany</string>
<string name="msg_unmount_usb">Należy wyłączyć pamięć USB, aby kontynuować.</string>
<string name="preferences_actions_title">Kiedy kod paskowy zostaje odnaleziony\u2026</string>
<string name="preferences_copy_to_clipboard_title">Kopiuj do schowka</string>
<string name="preferences_decode_1D_title">Dekoduj kody 1D</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Поиск книги\u2026</string>
<string name="msg_share_explanation">Вы можете поделиться данными, сканировав штрих-код с вашего экрана другим телефоном.</string>
<string name="msg_share_subject_line">Тут содержимое отсканированных Вами штрих-кодов</string>
<string name="msg_unmount_usb">Пожалуйста, отключите USB хранения, чтобы продолжить.</string>
<string name="preferences_actions_title">Когда штрих-код найден\u2026</string>
<string name="preferences_copy_to_clipboard_title">Копировать в буфер обмена</string>
<string name="preferences_decode_1D_title">Распознавать линейные штрих-коды</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Söker bok\u2026</string>
<string name="msg_share_explanation">Di kan dela data genom att visa en streckkod på din skärm och läsa den med en annan telefon.</string>
<string name="msg_share_subject_line">Detta är vad en streckod jag skannade innehöll</string>
<string name="msg_unmount_usb">Stäng av USB-minnen för att fortsätta.</string>
<string name="preferences_actions_title">När en streckkod hittats\u2026</string>
<string name="preferences_copy_to_clipboard_title">Kopiera till klippbordet</string>
<string name="preferences_decode_1D_title">Avkoda 1D steckkod</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">搜索图书\u2026</string>
<string name="msg_share_explanation">你可以在你的手机屏幕上显示条码,并使用其他手机扫描此条码方式进行分享</string>
<string name="msg_share_subject_line">这是我所扫描条码的内容</string>
<string name="msg_unmount_usb">请关闭USB存储继续。</string>
<string name="preferences_actions_title">找到条码时\u2026</string>
<string name="preferences_copy_to_clipboard_title">复制到剪切板</string>
<string name="preferences_decode_1D_title">解码一维条码</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">搜索圖書\u2026</string>
<string name="msg_share_explanation">你可以在你的手機屏幕上顯示條碼,并使用其他手機掃描此條碼方式進行分享</string>
<string name="msg_share_subject_line">這是我所掃描條碼的內容</string>
<string name="msg_unmount_usb">請關閉 USB存儲繼續。</string>
<string name="preferences_actions_title">找到條碼時\u2026</string>
<string name="preferences_copy_to_clipboard_title">復制到剪切板</string>
<string name="preferences_decode_1D_title">解碼一維條碼</string>

View file

@ -82,6 +82,7 @@
<string name="msg_sbc_searching_book">Searching book\u2026</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\'s the contents of a barcode I scanned</string>
<string name="msg_unmount_usb">Please turn off USB storage to continue.</string>
<string name="preferences_actions_title">When a barcode is found\u2026</string>
<string name="preferences_copy_to_clipboard_title">Copy to clipboard</string>
<string name="preferences_decode_1D_title">Decode 1D barcodes</string>

View file

@ -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();