Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package com.google.zxing.client.android.history;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/* loaded from: classes.dex */
final class DBHelper extends SQLiteOpenHelper {
DBHelper(Context context) {
super(context, "barcode_scanner_history.db", (SQLiteDatabase.CursorFactory) null, 5);
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onCreate(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("CREATE TABLE history (id INTEGER PRIMARY KEY, text TEXT, format TEXT, display TEXT, timestamp INTEGER, details TEXT);");
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS history");
onCreate(sQLiteDatabase);
}
}

View File

@@ -0,0 +1,138 @@
package com.google.zxing.client.android.history;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.client.android.R$id;
import com.google.zxing.client.android.R$menu;
import com.google.zxing.client.android.R$string;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public final class HistoryActivity extends ListActivity {
private static final String d = HistoryActivity.class.getSimpleName();
private HistoryManager a;
private ArrayAdapter<HistoryItem> b;
private CharSequence c;
@Override // android.app.Activity
public boolean onContextItemSelected(MenuItem menuItem) {
this.a.b(menuItem.getItemId());
a();
return true;
}
@Override // android.app.Activity
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
this.a = new HistoryManager(this);
this.b = new HistoryItemAdapter(this);
setListAdapter(this.b);
registerForContextMenu(getListView());
this.c = getTitle();
}
@Override // android.app.Activity, android.view.View.OnCreateContextMenuListener
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
int i = ((AdapterView.AdapterContextMenuInfo) contextMenuInfo).position;
if (i >= this.b.getCount() || this.b.getItem(i).b() != null) {
contextMenu.add(0, i, i, R$string.history_clear_one_history_text);
}
}
@Override // android.app.Activity
public boolean onCreateOptionsMenu(Menu menu) {
if (this.a.d()) {
getMenuInflater().inflate(R$menu.history, menu);
}
return super.onCreateOptionsMenu(menu);
}
@Override // android.app.ListActivity
protected void onListItemClick(ListView listView, View view, int i, long j) {
if (this.b.getItem(i).b() != null) {
Intent intent = new Intent(this, (Class<?>) CaptureActivity.class);
intent.putExtra("ITEM_NUMBER", i);
setResult(-1, intent);
finish();
}
}
@Override // android.app.Activity
public boolean onOptionsItemSelected(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == R$id.menu_history_send) {
Uri c = HistoryManager.c(this.a.a().toString());
if (c == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R$string.msg_unmount_usb);
builder.setPositiveButton(R$string.button_ok, (DialogInterface.OnClickListener) null);
builder.show();
} else {
Intent intent = new Intent("android.intent.action.SEND", Uri.parse("mailto:"));
intent.addFlags(524288);
String string = getResources().getString(R$string.history_email_title);
intent.putExtra("android.intent.extra.SUBJECT", string);
intent.putExtra("android.intent.extra.TEXT", string);
intent.putExtra("android.intent.extra.STREAM", c);
intent.setType("text/csv");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(d, e.toString());
}
}
} else {
if (itemId != R$id.menu_history_clear_text) {
return super.onOptionsItemSelected(menuItem);
}
AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
builder2.setMessage(R$string.msg_sure);
builder2.setCancelable(true);
builder2.setPositiveButton(R$string.button_ok, new DialogInterface.OnClickListener() { // from class: com.google.zxing.client.android.history.HistoryActivity.1
@Override // android.content.DialogInterface.OnClickListener
public void onClick(DialogInterface dialogInterface, int i) {
HistoryActivity.this.a.c();
dialogInterface.dismiss();
HistoryActivity.this.finish();
}
});
builder2.setNegativeButton(R$string.button_cancel, (DialogInterface.OnClickListener) null);
builder2.show();
}
return true;
}
@Override // android.app.Activity
protected void onResume() {
super.onResume();
a();
}
private void a() {
List<HistoryItem> b = this.a.b();
this.b.clear();
Iterator<T> it = b.iterator();
while (it.hasNext()) {
this.b.add((HistoryItem) it.next());
}
setTitle(((Object) this.c) + " (" + this.b.getCount() + ')');
if (this.b.isEmpty()) {
this.b.add(new HistoryItem(null, null, null));
}
}
}

View File

@@ -0,0 +1,36 @@
package com.google.zxing.client.android.history;
import com.google.zxing.Result;
/* loaded from: classes.dex */
public final class HistoryItem {
private final Result a;
private final String b;
private final String c;
HistoryItem(Result result, String str, String str2) {
this.a = result;
this.b = str;
this.c = str2;
}
public String a() {
StringBuilder sb = new StringBuilder();
String str = this.b;
if (str == null || str.isEmpty()) {
sb.append(this.a.e());
} else {
sb.append(this.b);
}
String str2 = this.c;
if (str2 != null && !str2.isEmpty()) {
sb.append(" : ");
sb.append(this.c);
}
return sb.toString();
}
public Result b() {
return this.a;
}
}

View File

@@ -0,0 +1,47 @@
package com.google.zxing.client.android.history;
import android.content.Context;
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$id;
import com.google.zxing.client.android.R$layout;
import com.google.zxing.client.android.R$string;
import java.util.ArrayList;
/* loaded from: classes.dex */
final class HistoryItemAdapter extends ArrayAdapter<HistoryItem> {
private final Context a;
HistoryItemAdapter(Context context) {
super(context, R$layout.history_list_item, new ArrayList());
this.a = context;
}
@Override // android.widget.ArrayAdapter, android.widget.Adapter
public View getView(int i, View view, ViewGroup viewGroup) {
String string;
String string2;
if (!(view instanceof LinearLayout)) {
view = LayoutInflater.from(this.a).inflate(R$layout.history_list_item, viewGroup, false);
}
HistoryItem item = getItem(i);
Result b = item.b();
if (b != null) {
string = b.e();
string2 = item.a();
} else {
Resources resources = getContext().getResources();
string = resources.getString(R$string.history_empty);
string2 = resources.getString(R$string.history_empty_detail);
}
((TextView) view.findViewById(R$id.history_title)).setText(string);
((TextView) view.findViewById(R$id.history_detail)).setText(string2);
return view;
}
}

View File

@@ -0,0 +1,358 @@
package com.google.zxing.client.android.history;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.client.android.result.ResultHandler;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/* loaded from: classes.dex */
public final class HistoryManager {
private static final String c = "HistoryManager";
private static final String[] d = {"text", "display", "format", "timestamp", "details"};
private static final String[] e = {"COUNT(1)"};
private static final String[] f = {JockstickDataConverter.ID};
private static final String[] g = {JockstickDataConverter.ID, "details"};
private static final Pattern h = Pattern.compile("\"", 16);
private final Activity a;
private final boolean b;
public HistoryManager(Activity activity) {
this.a = activity;
this.b = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("preferences_history", true);
}
public HistoryItem a(int i) {
SQLiteDatabase readableDatabase = new DBHelper(this.a).getReadableDatabase();
try {
Cursor query = readableDatabase.query("history", d, null, null, null, null, "timestamp DESC");
try {
query.move(i + 1);
String string = query.getString(0);
String string2 = query.getString(1);
String string3 = query.getString(2);
long j = query.getLong(3);
HistoryItem historyItem = new HistoryItem(new Result(string, null, null, BarcodeFormat.valueOf(string3), j), string2, query.getString(4));
if (query != null) {
query.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
return historyItem;
} finally {
}
} catch (Throwable th) {
try {
throw th;
} catch (Throwable th2) {
if (readableDatabase != null) {
try {
readableDatabase.close();
} catch (Throwable th3) {
th.addSuppressed(th3);
}
}
throw th2;
}
}
}
public List<HistoryItem> b() {
DBHelper dBHelper = new DBHelper(this.a);
ArrayList arrayList = new ArrayList();
try {
SQLiteDatabase readableDatabase = dBHelper.getReadableDatabase();
try {
Cursor query = readableDatabase.query("history", d, null, null, null, null, "timestamp DESC");
while (query.moveToNext()) {
try {
String string = query.getString(0);
String string2 = query.getString(1);
String string3 = query.getString(2);
long j = query.getLong(3);
arrayList.add(new HistoryItem(new Result(string, null, null, BarcodeFormat.valueOf(string3), j), string2, query.getString(4)));
} finally {
}
}
if (query != null) {
query.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
} finally {
}
} catch (CursorIndexOutOfBoundsException e2) {
Log.w(c, e2);
}
return arrayList;
}
void c() {
try {
SQLiteDatabase writableDatabase = new DBHelper(this.a).getWritableDatabase();
try {
writableDatabase.delete("history", null, null);
if (writableDatabase != null) {
writableDatabase.close();
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
}
public boolean d() {
try {
SQLiteDatabase readableDatabase = new DBHelper(this.a).getReadableDatabase();
try {
Cursor query = readableDatabase.query("history", e, null, null, null, null, null);
try {
query.moveToFirst();
boolean z = query.getInt(0) > 0;
if (query != null) {
query.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
return z;
} finally {
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
return false;
}
}
public void e() {
try {
SQLiteDatabase writableDatabase = new DBHelper(this.a).getWritableDatabase();
try {
Cursor query = writableDatabase.query("history", f, null, null, null, null, "timestamp DESC");
try {
query.move(2000);
while (query.moveToNext()) {
String string = query.getString(0);
Log.i(c, "Deleting scan history ID " + string);
writableDatabase.delete("history", "id=" + string, null);
}
if (query != null) {
query.close();
}
if (writableDatabase != null) {
writableDatabase.close();
}
} finally {
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
}
static Uri c(String str) {
File file = new File(new File(Environment.getExternalStorageDirectory(), "BarcodeScanner"), "History");
if (!file.mkdirs() && !file.isDirectory()) {
Log.w(c, "Couldn't make dir " + file);
return null;
}
File file2 = new File(file, "history-" + System.currentTimeMillis() + ".csv");
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file2), StandardCharsets.UTF_8);
try {
outputStreamWriter.write(str);
outputStreamWriter.close();
Uri parse = Uri.parse("file://" + file2.getAbsolutePath());
outputStreamWriter.close();
return parse;
} finally {
}
} catch (IOException e2) {
Log.w(c, "Couldn't access file " + file2 + " due to " + e2);
return null;
}
}
public void a(Result result, ResultHandler resultHandler) {
if (!this.a.getIntent().getBooleanExtra("SAVE_HISTORY", true) || resultHandler.a() || !this.b) {
return;
}
if (!PreferenceManager.getDefaultSharedPreferences(this.a).getBoolean("preferences_remember_duplicates", false)) {
a(result.e());
}
ContentValues contentValues = new ContentValues();
contentValues.put("text", result.e());
contentValues.put("format", result.a().toString());
contentValues.put("display", resultHandler.e().toString());
contentValues.put("timestamp", Long.valueOf(System.currentTimeMillis()));
try {
SQLiteDatabase writableDatabase = new DBHelper(this.a).getWritableDatabase();
try {
writableDatabase.insert("history", "timestamp", contentValues);
if (writableDatabase != null) {
writableDatabase.close();
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
}
public void b(int i) {
try {
SQLiteDatabase writableDatabase = new DBHelper(this.a).getWritableDatabase();
try {
Cursor query = writableDatabase.query("history", f, null, null, null, null, "timestamp DESC");
try {
query.move(i + 1);
writableDatabase.delete("history", "id=" + query.getString(0), null);
if (query != null) {
query.close();
}
if (writableDatabase != null) {
writableDatabase.close();
}
} finally {
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
}
private static String b(String str) {
return str == null ? "" : h.matcher(str).replaceAll("\"\"");
}
public void a(String str, String str2) {
String str3;
String str4;
try {
SQLiteDatabase writableDatabase = new DBHelper(this.a).getWritableDatabase();
try {
Cursor query = writableDatabase.query("history", g, "text=?", new String[]{str}, null, null, "timestamp DESC", "1");
try {
if (query.moveToNext()) {
str3 = query.getString(0);
str4 = query.getString(1);
} else {
str3 = null;
str4 = null;
}
if (str3 != null) {
if (str4 != null) {
if (str4.contains(str2)) {
str2 = null;
} else {
str2 = str4 + " : " + str2;
}
}
if (str2 != null) {
ContentValues contentValues = new ContentValues();
contentValues.put("details", str2);
writableDatabase.update("history", contentValues, "id=?", new String[]{str3});
}
}
if (query != null) {
query.close();
}
if (writableDatabase != null) {
writableDatabase.close();
}
} finally {
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
}
private void a(String str) {
try {
SQLiteDatabase writableDatabase = new DBHelper(this.a).getWritableDatabase();
try {
writableDatabase.delete("history", "text=?", new String[]{str});
if (writableDatabase != null) {
writableDatabase.close();
}
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
}
CharSequence a() {
SQLiteDatabase readableDatabase;
Cursor query;
StringBuilder sb = new StringBuilder(1000);
try {
readableDatabase = new DBHelper(this.a).getReadableDatabase();
try {
query = readableDatabase.query("history", d, null, null, null, null, "timestamp DESC");
} finally {
}
} catch (SQLException e2) {
Log.w(c, e2);
}
try {
DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(2, 2);
while (query.moveToNext()) {
sb.append('\"');
sb.append(b(query.getString(0)));
sb.append("\",");
sb.append('\"');
sb.append(b(query.getString(1)));
sb.append("\",");
sb.append('\"');
sb.append(b(query.getString(2)));
sb.append("\",");
sb.append('\"');
sb.append(b(query.getString(3)));
sb.append("\",");
long j = query.getLong(3);
sb.append('\"');
sb.append(b(dateTimeInstance.format(Long.valueOf(j))));
sb.append("\",");
sb.append('\"');
sb.append(b(query.getString(4)));
sb.append("\"\r\n");
}
if (query != null) {
query.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
return sb;
} finally {
}
}
}