Example #1
0
 private static Vector<BarcodeFormat> parseDecodeFormats(
     Iterable<String> scanFormats, String decodeMode) {
   if (scanFormats != null) {
     Vector<BarcodeFormat> formats = new Vector<BarcodeFormat>();
     try {
       for (String format : scanFormats) {
         formats.add(BarcodeFormat.valueOf(format));
       }
       return formats;
     } catch (IllegalArgumentException iae) {
       // ignore it then
     }
   }
   if (decodeMode != null) {
     if (Intents.Scan.PRODUCT_MODE.equals(decodeMode)) {
       return PRODUCT_FORMATS;
     }
     if (Intents.Scan.QR_CODE_MODE.equals(decodeMode)) {
       return QR_CODE_FORMATS;
     }
     if (Intents.Scan.DATA_MATRIX_MODE.equals(decodeMode)) {
       return DATA_MATRIX_FORMATS;
     }
     if (Intents.Scan.ONE_D_MODE.equals(decodeMode)) {
       return ONE_D_FORMATS;
     }
   }
   return null;
 }
Example #2
0
 public List<HistoryItem> buildHistoryItems() {
   SQLiteOpenHelper helper = new DBHelper(activity);
   List<HistoryItem> items = new ArrayList<>();
   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;
 }
Example #3
0
 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);
   }
 }
Example #4
0
 // It would be nice if the string encoding lived in the core ZXing library,
 // but we use platform specific code like PhoneNumberUtils, so it can't.
 private boolean encodeContentsFromZXingIntent(Intent intent) {
   // Default to QR_CODE if no format given.
   String formatString = intent.getStringExtra(Intents.Encode.FORMAT);
   format = null;
   if (formatString != null) {
     try {
       format = BarcodeFormat.valueOf(formatString);
     } catch (IllegalArgumentException iae) {
       // Ignore it then
     }
   }
   if (format == null || format == BarcodeFormat.QR_CODE) {
     String type = intent.getStringExtra(Intents.Encode.TYPE);
     if (type == null || type.isEmpty()) {
       return false;
     }
     this.format = BarcodeFormat.QR_CODE;
     encodeQRCodeContents(intent, type);
   } else {
     String data = intent.getStringExtra(Intents.Encode.DATA);
     if (data != null && !data.isEmpty()) {
       contents = data;
       displayContents = data;
     }
   }
   return contents != null && !contents.isEmpty();
 }
 private static Set<BarcodeFormat> parseDecodeFormats(
     Iterable<String> scanFormats, String decodeMode) {
   if (scanFormats != null) {
     Set<BarcodeFormat> formats = EnumSet.noneOf(BarcodeFormat.class);
     try {
       for (String format : scanFormats) {
         formats.add(BarcodeFormat.valueOf(format));
       }
       return formats;
     } catch (IllegalArgumentException iae) {
       // ignore it then
     }
   }
   if (decodeMode != null) {
     return FORMATS_FOR_MODE.get(decodeMode);
   }
   return null;
 }
 private boolean encodeContents(String data, Bundle bundle, String type, String formatString) {
   // Default to QR_CODE if no format given.
   format = null;
   if (formatString != null) {
     try {
       format = BarcodeFormat.valueOf(formatString);
     } catch (IllegalArgumentException iae) {
       // Ignore it then
     }
   }
   if (format == null || format == BarcodeFormat.QR_CODE) {
     this.format = BarcodeFormat.QR_CODE;
     encodeQRCodeContents(data, bundle, type);
   } else if (data != null && data.length() > 0) {
     contents = data;
     displayContents = data;
     title = "Text";
   }
   return contents != null && contents.length() > 0;
 }