Reimplement History as a simple activity instead of dialog; add ability to delete one entry with a long press

git-svn-id: https://zxing.googlecode.com/svn/trunk@2106 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-01-09 20:12:59 +00:00
parent 7eb68cb75a
commit 5cc9295451
38 changed files with 471 additions and 140 deletions

View file

@ -137,6 +137,14 @@
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".history.HistoryActivity"
android:label="@string/history_title"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".share.BookmarkPickerActivity"
android:label="@string/bookmark_picker_name"
android:stateNotNeeded="true">

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dip">
<TextView android:id="@+id/history_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:singleLine="true"/>
<TextView android:id="@+id/history_detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="false"/>
</LinearLayout>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">رقم الهاتف</string>
<string name="contents_sms">عنوان SMS</string>
<string name="contents_text">نص عادي</string>
<string name="history_clear_one_history_text">حذف</string>
<string name="history_clear_text">مسح السجل</string>
<string name="history_email_title">سجل ماسح الرموز الشريطية</string>
<string name="history_empty">فارغ</string>
<string name="history_empty_detail">لم تسجل حتى الآن بمسح الباركود</string>
<string name="history_send">إرسال السجل</string>
<string name="history_title">سجل</string>
<string name="menu_about">حول</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Телефон</string>
<string name="contents_sms">SMS адрес</string>
<string name="contents_text">Чист текст</string>
<string name="history_clear_one_history_text">Изчисти</string>
<string name="history_clear_text">Изчисти историята</string>
<string name="history_email_title">История на Баркод Скенера</string>
<string name="history_empty">Празен</string>
<string name="history_empty_detail">Не баркод сканиране са записани още</string>
<string name="history_send">Изпрати историята</string>
<string name="history_title">История</string>
<string name="menu_about">Относно</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Número de telèfon</string>
<string name="contents_sms">Adreça SMS</string>
<string name="contents_text">Text pla</string>
<string name="history_clear_one_history_text">Neteja</string>
<string name="history_clear_text">Neteja l\'historial</string>
<string name="history_email_title">Historial del Barcode Scanner</string>
<string name="history_empty">Buit</string>
<string name="history_empty_detail">No escaneja codis de barres s\'han registrat encara</string>
<string name="history_send">Envia l\'historial</string>
<string name="history_title">Historial</string>
<string name="menu_about">Quant a</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefonní číslo</string>
<string name="contents_sms">SMS číslo</string>
<string name="contents_text">Ostatní</string>
<string name="history_clear_one_history_text">Vyčistit</string>
<string name="history_clear_text">Vyčistit historii</string>
<string name="history_email_title">Barcode Scanner historie</string>
<string name="history_empty">Prázdný</string>
<string name="history_empty_detail">Žádný čárový kód vyšetření byly zaznamenány ještě</string>
<string name="history_send">Poslat historii</string>
<string name="history_title">Historie</string>
<string name="menu_about">O</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefonnummer</string>
<string name="contents_sms">SMS-adresse</string>
<string name="contents_text">Almindelig tekst</string>
<string name="history_clear_one_history_text">Ryd</string>
<string name="history_clear_text">Ryd historik</string>
<string name="history_email_title">Barcode Scanner-historik</string>
<string name="history_empty">Tomme</string>
<string name="history_empty_detail">Ingen stregkode scanninger er blevet registreret endnu</string>
<string name="history_send">Send historik</string>
<string name="history_title">Historik</string>
<string name="menu_about">Om</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefonnummer</string>
<string name="contents_sms">SMS Adresse</string>
<string name="contents_text">Text</string>
<string name="history_clear_one_history_text">Löschen</string>
<string name="history_clear_text">Historie löschen</string>
<string name="history_email_title">Barcode Scanner Historie</string>
<string name="history_empty">Leer</string>
<string name="history_empty_detail">Kein Barcode-Scans wurden aufgezeichnet</string>
<string name="history_send">Historie senden</string>
<string name="history_title">Historie</string>
<string name="menu_about">Info</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Τηλέφωνο</string>
<string name="contents_sms">Διεύθνση SMS</string>
<string name="contents_text">Απλό κείμενο</string>
<string name="history_clear_one_history_text">Διαγραφή</string>
<string name="history_clear_text">Διαγραφή ιστορικού</string>
<string name="history_email_title">Ιστορικό Barcode Scanner</string>
<string name="history_empty">Κενό</string>
<string name="history_empty_detail">Δεν έχουν σαρώνει barcode έχουν καταγραφεί</string>
<string name="history_send">Αποστολή ιστορικού</string>
<string name="history_title">Ιστορικό</string>
<string name="menu_about">Σχετικά</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Número de teléfono</string>
<string name="contents_sms">Dirección SMS</string>
<string name="contents_text">Texto</string>
<string name="history_clear_one_history_text">Borrar</string>
<string name="history_clear_text">Borrar historial</string>
<string name="history_email_title">Historial de Escáner de código de barras</string>
<string name="history_empty">Vacío</string>
<string name="history_empty_detail">Ningún escanea de códigos de barras se han registrado aún</string>
<string name="history_send">Enviar historial</string>
<string name="history_title">Historial</string>
<string name="menu_about">Acerca de</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Puhelin numero</string>
<string name="contents_sms">Tekstiviestin osoite</string>
<string name="contents_text">Teksti</string>
<string name="history_clear_one_history_text">Tyhjennä</string>
<string name="history_clear_text">Tyhjennä historia</string>
<string name="history_email_title">Viivakoodin skanneri historia</string>
<string name="history_empty">Tyhjä</string>
<string name="history_empty_detail">Ei viivakoodi skannaa on kirjattu vielä</string>
<string name="history_send">Lähetä historia</string>
<string name="history_title">Historia</string>
<string name="menu_about">Tietoja</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Numéro de téléphone</string>
<string name="contents_sms">Adresse SMS</string>
<string name="contents_text">Texte</string>
<string name="history_clear_one_history_text">Effacer</string>
<string name="history_clear_text">Vider l\'historique</string>
<string name="history_email_title">Historique de Barcode Scanner</string>
<string name="history_empty">Vide</string>
<string name="history_empty_detail">Pas de code à barres scanne ont encore été enregistrées</string>
<string name="history_send">Envoyer historique</string>
<string name="history_title">Historique</string>
<string name="menu_about">A propos</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">מספר טלפון</string>
<string name="contents_sms">כתובת SMS</string>
<string name="contents_text">טקסט רגיל</string>
<string name="history_clear_one_history_text">נקה</string>
<string name="history_clear_text">נקה היסטוריה</string>
<string name="history_email_title">היסטוריית סורק הברקודים</string>
<string name="history_empty">ריק</string>
<string name="history_empty_detail">ברקודים לא נרשמו</string>
<string name="history_send">שלח היסטוריה</string>
<string name="history_title">היסטוריה</string>
<string name="menu_about">אודות</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">फ़ोन नंबर</string>
<string name="contents_sms">एसएमएस पता</string>
<string name="contents_text">सादा पाठ</string>
<string name="history_clear_text">सुस्पष्ट इतिहास</string>
<string name="history_clear_one_history_text">हटाएँ</string>
<string name="history_clear_text">इतिहास हटाएँ</string>
<string name="history_email_title">बारकोड स्कैनर इतिहास</string>
<string name="history_empty">खाली</string>
<string name="history_empty_detail">अभी तक कोई बारकोड स्कैन दर्ज किया गया है</string>
<string name="history_send">इतिहास भेजें</string>
<string name="history_title">इतिहास</string>
<string name="menu_about">के बारे में</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefonszám</string>
<string name="contents_sms">SMS szám</string>
<string name="contents_text">Egyszerű szöveg</string>
<string name="history_clear_one_history_text">Törlése</string>
<string name="history_clear_text">Előzmények törlése</string>
<string name="history_email_title">Barcode Scanner előzmények</string>
<string name="history_empty">Üres</string>
<string name="history_empty_detail">Nem vonalkód szkennelés lett felvéve még</string>
<string name="history_send">Előzmények küldése</string>
<string name="history_title">Előzmények</string>
<string name="menu_about">Rólunk</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Nomor telepon</string>
<string name="contents_sms">Alamat SMS</string>
<string name="contents_text">Teks biasa</string>
<string name="history_clear_one_history_text">Hapus</string>
<string name="history_clear_text">Hapus riwayat</string>
<string name="history_email_title">Riwayat Barcode Scanner</string>
<string name="history_empty">Kosong</string>
<string name="history_empty_detail">Tidak ada scan barcode telah dicatat belum</string>
<string name="history_send">Kirim riwayat</string>
<string name="history_title">Riwayat</string>
<string name="menu_about">Tentang</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Numero di telefono</string>
<string name="contents_sms">Numero SMS</string>
<string name="contents_text">Testo puro</string>
<string name="history_clear_one_history_text">Cancella</string>
<string name="history_clear_text">Cancella cronologia</string>
<string name="history_email_title">Cronologia scansioni codici a barre</string>
<string name="history_empty">Vuoto</string>
<string name="history_empty_detail">Nessun scansioni di codici a barre sono stati registrati</string>
<string name="history_send">Invia cronologia</string>
<string name="history_title">Cronologia</string>
<string name="menu_about">Info</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">מספר טלפון</string>
<string name="contents_sms">כתובת SMS</string>
<string name="contents_text">טקסט רגיל</string>
<string name="history_clear_one_history_text">נקה</string>
<string name="history_clear_text">נקה היסטוריה</string>
<string name="history_email_title">היסטוריית סורק הברקודים</string>
<string name="history_empty">ריק</string>
<string name="history_empty_detail">ברקודים לא נרשמו</string>
<string name="history_send">שלח היסטוריה</string>
<string name="history_title">היסטוריה</string>
<string name="menu_about">אודות</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">電話番号</string>
<string name="contents_sms">SMSアドレス</string>
<string name="contents_text">テキストデータ</string>
<string name="history_clear_one_history_text">削除</string>
<string name="history_clear_text">履歴の削除</string>
<string name="history_email_title">QRコードスキャナー歴史</string>
<string name="history_empty">空っぽ</string>
<string name="history_empty_detail">にバーコードスキャンが記録されていない</string>
<string name="history_send">履歴を送信</string>
<string name="history_title">履歴</string>
<string name="menu_about">詳細</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">전화번호</string>
<string name="contents_sms">전화번호</string>
<string name="contents_text">단문</string>
<string name="history_clear_one_history_text">삭제</string>
<string name="history_clear_text">기록 삭제</string>
<string name="history_email_title">바코드 스캐너 기록</string>
<string name="history_empty"></string>
<string name="history_empty_detail">아무 바코드 스캔이 기록되지 않았습니다</string>
<string name="history_send">기록 보내기</string>
<string name="history_title">기록</string>
<string name="menu_about">정보</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefoonnummer</string>
<string name="contents_sms">SMSnummer</string>
<string name="contents_text">Tekst</string>
<string name="history_clear_one_history_text">Leeg</string>
<string name="history_clear_text">Leeg geschiedenis</string>
<string name="history_email_title">Barcode Scanner geschiedenis</string>
<string name="history_empty">Leeg</string>
<string name="history_empty_detail">Geen barcode scans zijn opgenomen</string>
<string name="history_send">Verzend geschiedenis</string>
<string name="history_title">Geschiedenis</string>
<string name="menu_about">Over</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Numer telefonu</string>
<string name="contents_sms">Adres SMS</string>
<string name="contents_text">Zwykły tekst</string>
<string name="history_clear_one_history_text">Wyczyść</string>
<string name="history_clear_text">Wyczyść historię</string>
<string name="history_email_title">Historia Skanera Kodów Paskowych</string>
<string name="history_empty">Pusty</string>
<string name="history_empty_detail">Brak skanowania kodów kreskowych zostały zarejestrowane</string>
<string name="history_send">Wyślij historię</string>
<string name="history_title">Historia</string>
<string name="menu_about">O aplikacji</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Número de telefone</string>
<string name="contents_sms">Endereço SMS</string>
<string name="contents_text">Texto simples</string>
<string name="history_clear_one_history_text">Limpar</string>
<string name="history_clear_text">Limpar histórico</string>
<string name="history_email_title">Histórico do Barcode Scanner</string>
<string name="history_empty">Vazio</string>
<string name="history_empty_detail">Não código de barras foram registrados</string>
<string name="history_send">Enviar histórico</string>
<string name="history_title">Histórico</string>
<string name="menu_about">Sobre</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Номер телефона</string>
<string name="contents_sms">Адрес для SMS</string>
<string name="contents_text">Текст</string>
<string name="history_clear_one_history_text">Очистить</string>
<string name="history_clear_text">Очистить историю</string>
<string name="history_email_title">История сканирования</string>
<string name="history_empty">Пустой</string>
<string name="history_empty_detail">Нет штрих-код сканирования были записаны</string>
<string name="history_send">Отправить историю</string>
<string name="history_title">История</string>
<string name="menu_about">О программе</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefónne číslo</string>
<string name="contents_sms">SMS adresa</string>
<string name="contents_text">Obyčajný text</string>
<string name="history_clear_one_history_text">Vymazať</string>
<string name="history_clear_text">Vymazať históriu</string>
<string name="history_email_title">História Barcode Scanneru</string>
<string name="history_empty">Prázdny</string>
<string name="history_empty_detail">Žiadny čiarový kód vyšetrení boli zaznamenané</string>
<string name="history_send">Poslať históriu</string>
<string name="history_title">História</string>
<string name="menu_about">O programe</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefonska številka</string>
<string name="contents_sms">SMS naslov</string>
<string name="contents_text">Tekst</string>
<string name="history_clear_one_history_text">Pobriši</string>
<string name="history_clear_text">Pobriši zgodovino</string>
<string name="history_email_title">Barcode Scanner zgodovina</string>
<string name="history_empty">Prazne</string>
<string name="history_empty_detail">Št črtne kode scans so bile zabeležene</string>
<string name="history_send">Pošlji zgodovino</string>
<string name="history_title">Zgodovina</string>
<string name="menu_about">O programu</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefonnummer</string>
<string name="contents_sms">SMS-adress</string>
<string name="contents_text">Ren text</string>
<string name="history_clear_one_history_text">Rensa</string>
<string name="history_clear_text">Rensa historik</string>
<string name="history_email_title">Streckkodsläsarens historik</string>
<string name="history_empty">Tomma</string>
<string name="history_empty_detail">Ingen streckkod skannar har registrerats</string>
<string name="history_send">Skicka historik</string>
<string name="history_title">Historik</string>
<string name="menu_about">Om</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">Telefon numarası</string>
<string name="contents_sms">SMS adresi</string>
<string name="contents_text">Düz metin</string>
<string name="history_clear_one_history_text">Temizle</string>
<string name="history_clear_text">Geçmişi temizle</string>
<string name="history_email_title">Barkod Tarayıcı geçmişi</string>
<string name="history_empty">Boş</string>
<string name="history_empty_detail">Yok barkod taramaları kaydedildi</string>
<string name="history_send">Geçmişi gönder</string>
<string name="history_title">Geçmiş</string>
<string name="menu_about">Hakkında</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">电话号码</string>
<string name="contents_sms">短信地址</string>
<string name="contents_text">纯文本</string>
<string name="history_clear_one_history_text">删除</string>
<string name="history_clear_text">删除历史</string>
<string name="history_email_title">条码扫描器历史</string>
<string name="history_empty">空的</string>
<string name="history_empty_detail">没有条码扫描已记录</string>
<string name="history_send">发送历史</string>
<string name="history_title">历史</string>
<string name="menu_about">关于</string>

View file

@ -51,8 +51,11 @@
<string name="contents_phone">電話號碼</string>
<string name="contents_sms">簡訊地址</string>
<string name="contents_text">純文字</string>
<string name="history_clear_one_history_text">刪除</string>
<string name="history_clear_text">刪除紀錄</string>
<string name="history_email_title">條碼掃描器紀錄</string>
<string name="history_empty">空的</string>
<string name="history_empty_detail">沒有條碼掃描已記錄</string>
<string name="history_send">發送紀錄</string>
<string name="history_title">紀錄</string>
<string name="menu_about">關於</string>

View file

@ -52,7 +52,10 @@
<string name="contents_sms">SMS address</string>
<string name="contents_text">Plain text</string>
<string name="history_clear_text">Clear history</string>
<string name="history_clear_one_history_text">Clear</string>
<string name="history_email_title">Barcode Scanner history</string>
<string name="history_empty">Empty</string>
<string name="history_empty_detail">No barcode scans have been recorded</string>
<string name="history_send">Send history</string>
<string name="history_title">History</string>
<string name="menu_about">About</string>

View file

@ -21,6 +21,7 @@ import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.CameraManager;
import com.google.zxing.client.android.history.HistoryActivity;
import com.google.zxing.client.android.history.HistoryManager;
import com.google.zxing.client.android.result.ResultButtonListener;
import com.google.zxing.client.android.result.ResultHandler;
@ -99,6 +100,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private static final String RETURN_CODE_PLACEHOLDER = "{CODE}";
private static final String RETURN_URL_PARAM = "ret";
public static final int HISTORY_REQUEST_CODE = 0x0000bacc;
private static final Set<ResultMetadataType> DISPLAYABLE_METADATA_TYPES =
EnumSet.of(ResultMetadataType.ISSUE_NUMBER,
ResultMetadataType.SUGGESTED_PRICE,
@ -347,8 +350,10 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
startActivity(intent);
break;
case HISTORY_ID:
AlertDialog historyAlert = historyManager.buildAlert();
historyAlert.show();
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.setClassName(this, HistoryActivity.class.getName());
startActivityForResult(intent, HISTORY_REQUEST_CODE);
break;
case SETTINGS_ID:
intent.setClassName(this, PreferencesActivity.class.getName());

View file

@ -150,6 +150,14 @@ public final class Intents {
}
}
public static final class History {
public static final String ITEM_NUMBER = "ITEM_NUMBER";
private History() {
}
}
public static final class Encode {
/**
* Send this intent to encode a piece of data as a QR code and display it full screen, so

View file

@ -0,0 +1,149 @@
/*
* Copyright 2012 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.android.history;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.R;
import java.util.List;
public final class HistoryActivity extends ListActivity {
private static final int SEND_ID = Menu.FIRST;
private static final int CLEAR_ID = Menu.FIRST + 1;
private HistoryManager historyManager;
private HistoryItemAdapter adapter;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.historyManager = new HistoryManager(this);
adapter = new HistoryItemAdapter(this);
setListAdapter(adapter);
ListView listview = getListView();
registerForContextMenu(listview);
}
@Override
protected void onResume() {
super.onResume();
List<HistoryItem> items = historyManager.buildHistoryItems();
adapter.clear();
for (HistoryItem item : items) {
adapter.add(item);
}
if (adapter.isEmpty()) {
adapter.add(new HistoryItem(null, null, null));
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
if (adapter.getItem(position).getResult() != null) {
Intent intent = new Intent(this, CaptureActivity.class);
intent.putExtra(Intents.History.ITEM_NUMBER, position);
setResult(Activity.RESULT_OK, intent);
finish();
}
}
@Override
public void onCreateContextMenu(ContextMenu menu,
View v,
ContextMenu.ContextMenuInfo menuInfo) {
int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
menu.add(Menu.NONE, position, position, R.string.history_clear_one_history_text);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
int position = item.getItemId();
historyManager.deleteHistoryItem(position);
finish();
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
if (historyManager.hasHistoryItems()) {
menu.add(0, SEND_ID, 0, R.string.history_send).setIcon(android.R.drawable.ic_menu_share);
menu.add(0, CLEAR_ID, 0, R.string.history_clear_text).setIcon(android.R.drawable.ic_menu_delete);
return true;
}
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case SEND_ID:
CharSequence history = historyManager.buildHistory();
Uri historyFile = HistoryManager.saveHistory(history.toString());
if (historyFile == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.msg_unmount_usb);
builder.setPositiveButton(R.string.button_ok, null);
builder.show();
} else {
Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
String subject = getResources().getString(R.string.history_email_title);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, subject);
intent.putExtra(Intent.EXTRA_STREAM, historyFile);
intent.setType("text/csv");
startActivity(intent);
}
break;
case CLEAR_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.msg_sure);
builder.setCancelable(true);
builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i2) {
historyManager.clearHistory();
dialog.dismiss();
finish();
}
});
builder.setNegativeButton(R.string.button_cancel, null);
builder.show();
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
}

View file

@ -1,90 +0,0 @@
/*
* Copyright (C) 2009 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.android.history;
import com.google.zxing.Result;
import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.client.android.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Message;
import java.util.List;
final class HistoryClickListener implements DialogInterface.OnClickListener {
private final HistoryManager historyManager;
private final CaptureActivity activity;
private final List<Result> items;
/**
* Handles clicks in the History dialog.
*
* @author dswitkin@google.com (Daniel Switkin)
* @author Sean Owen
*/
HistoryClickListener(HistoryManager historyManager, CaptureActivity activity, List<Result> items) {
this.historyManager = historyManager;
this.activity = activity;
this.items = items;
}
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == items.size()) {
// Share history.
CharSequence history = historyManager.buildHistory();
Uri historyFile = HistoryManager.saveHistory(history.toString());
if (historyFile == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.msg_unmount_usb);
builder.setPositiveButton(R.string.button_ok, null);
builder.show();
return;
}
Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
String subject = activity.getResources().getString(R.string.history_email_title);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, subject);
intent.putExtra(Intent.EXTRA_STREAM, historyFile);
intent.setType("text/csv");
activity.startActivity(intent);
} else if (i == items.size() + 1) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.msg_sure);
builder.setCancelable(true);
builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface2, int i2) {
historyManager.clearHistory();
}
});
builder.setNegativeButton(R.string.button_cancel, null);
builder.show();
} else {
// Display a single history entry.
Result result = items.get(i);
Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, result);
message.sendToTarget();
}
}
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2012 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.android.history;
import com.google.zxing.Result;
public final class HistoryItem {
private final Result result;
private final String display;
private final String details;
HistoryItem(Result result, String display, String details) {
this.result = result;
this.display = display;
this.details = details;
}
public Result getResult() {
return result;
}
public String getDisplayAndDetails() {
StringBuilder displayResult = new StringBuilder();
if (display == null || display.length() == 0) {
displayResult.append(result.getText());
} else {
displayResult.append(display);
}
if (details != null && details.length() > 0) {
displayResult.append(" : ").append(details);
}
return displayResult.toString();
}
}

View file

@ -0,0 +1,71 @@
/*
* Copyright 2012 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.android.history;
import android.app.Activity;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.zxing.Result;
import com.google.zxing.client.android.R;
import java.util.ArrayList;
final class HistoryItemAdapter extends ArrayAdapter<HistoryItem> {
private final Activity activity;
HistoryItemAdapter(Activity activity) {
super(activity, R.layout.history_list_item, new ArrayList<HistoryItem>());
this.activity = activity;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
LinearLayout layout;
if (view instanceof LinearLayout) {
layout = (LinearLayout) view;
} else {
LayoutInflater factory = LayoutInflater.from(activity);
layout = (LinearLayout) factory.inflate(R.layout.history_list_item, viewGroup, false);
}
HistoryItem item = getItem(position);
Result result = item.getResult();
String title;
String detail;
if (result != null) {
title = result.getText();
detail = item.getDisplayAndDetails();
} else {
Resources resources = getContext().getResources();
title = resources.getString(R.string.history_empty);
detail = resources.getString(R.string.history_empty_detail);
}
((TextView) layout.findViewById(R.id.history_title)).setText(title);
((TextView) layout.findViewById(R.id.history_detail)).setText(detail);
return layout;
}
}

View file

@ -18,17 +18,13 @@ package com.google.zxing.client.android.history;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.PreferencesActivity;
import com.google.zxing.client.android.R;
import com.google.zxing.client.android.result.ResultHandler;
import android.app.AlertDialog;
import android.app.Activity;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@ -66,65 +62,90 @@ public final class HistoryManager {
DBHelper.DETAILS_COL,
};
private static final String[] COUNT_COLUMN = { "COUNT(1)" };
private static final String[] ID_COL_PROJECTION = { DBHelper.ID_COL };
private static final String[] ID_DETAIL_COL_PROJECTION = { DBHelper.ID_COL, DBHelper.DETAILS_COL };
private static final DateFormat EXPORT_DATE_TIME_FORMAT = DateFormat.getDateTimeInstance();
private final CaptureActivity activity;
private final Activity activity;
public HistoryManager(CaptureActivity activity) {
public HistoryManager(Activity activity) {
this.activity = activity;
}
public AlertDialog buildAlert() {
public boolean hasHistoryItems() {
SQLiteOpenHelper helper = new DBHelper(activity);
List<Result> items = new ArrayList<Result>();
List<String> dialogItems = new ArrayList<String>();
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getReadableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
while (cursor.moveToNext()) {
String text = cursor.getString(0);
String format = cursor.getString(2);
long timestamp = cursor.getLong(3);
Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
items.add(result);
StringBuilder displayResult = new StringBuilder();
String display = cursor.getString(1);
if (display == null || display.length() == 0) {
display = result.getText();
}
displayResult.append(display);
String details = cursor.getString(4);
if (details != null && details.length() > 0) {
displayResult.append(" : ").append(details);
}
dialogItems.add(displayResult.toString());
}
cursor = db.query(DBHelper.TABLE_NAME, COUNT_COLUMN, null, null, null, null, null);
cursor.moveToFirst();
return cursor.getInt(0) > 0;
} finally {
close(cursor, db);
}
}
Resources res = activity.getResources();
dialogItems.add(res.getString(R.string.history_send));
dialogItems.add(res.getString(R.string.history_clear_text));
DialogInterface.OnClickListener clickListener = new HistoryClickListener(this, activity, items);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.history_title);
builder.setItems(dialogItems.toArray(new String[dialogItems.size()]), clickListener);
return builder.create();
public List<HistoryItem> buildHistoryItems() {
SQLiteOpenHelper helper = new DBHelper(activity);
List<HistoryItem> items = new ArrayList<HistoryItem>();
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getReadableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
while (cursor.moveToNext()) {
String text = cursor.getString(0);
String display = cursor.getString(1);
String format = cursor.getString(2);
long timestamp = cursor.getLong(3);
String details = cursor.getString(4);
Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
items.add(new HistoryItem(result, display, details));
}
} finally {
close(cursor, db);
}
return items;
}
public HistoryItem buildHistoryItem(int number) {
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getReadableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
cursor.move(number + 1);
String text = cursor.getString(0);
String display = cursor.getString(1);
String format = cursor.getString(2);
long timestamp = cursor.getLong(3);
String details = cursor.getString(4);
Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
return new HistoryItem(result, display, details);
} finally {
close(cursor, db);
}
}
public void deleteHistoryItem(int number) {
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getWritableDatabase();
cursor = db.query(DBHelper.TABLE_NAME,
ID_COL_PROJECTION,
null, null, null, null,
DBHelper.TIMESTAMP_COL + " DESC");
cursor.move(number + 1);
db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
} finally {
close(cursor, db);
}
}
public void addHistoryItem(Result result, ResultHandler handler) {