mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Noticed we should just use BarcodeFormat constants in the client for simplicity
git-svn-id: https://zxing.googlecode.com/svn/trunk@1295 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ad1e585a23
commit
c7d5c2af5a
|
@ -28,21 +28,6 @@ public final class Contents {
|
|||
private Contents() {
|
||||
}
|
||||
|
||||
/**
|
||||
* All the formats we know about.
|
||||
*/
|
||||
public static final class Format {
|
||||
public static final String UPC_A = "UPC_A";
|
||||
public static final String UPC_E = "UPC_E";
|
||||
public static final String EAN_8 = "EAN_8";
|
||||
public static final String EAN_13 = "EAN_13";
|
||||
public static final String CODE_39 = "CODE_39";
|
||||
public static final String CODE_128 = "CODE_128";
|
||||
public static final String QR_CODE = "QR_CODE";
|
||||
private Format() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Type {
|
||||
/**
|
||||
* Plain text. Use Intent.putExtra(DATA, string). This can be used for URLs too, but string
|
||||
|
|
|
@ -106,9 +106,15 @@ final class QRCodeEncoder {
|
|||
// 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 format = intent.getStringExtra(Intents.Encode.FORMAT);
|
||||
if (format == null || format.length() == 0 ||
|
||||
format.equals(Contents.Format.QR_CODE)) {
|
||||
String formatString = intent.getStringExtra(Intents.Encode.FORMAT);
|
||||
try {
|
||||
format = BarcodeFormat.valueOf(formatString);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// Ignore it then
|
||||
format = null;
|
||||
formatString = null;
|
||||
}
|
||||
if (format == null || BarcodeFormat.QR_CODE.equals(format)) {
|
||||
String type = intent.getStringExtra(Intents.Encode.TYPE);
|
||||
if (type == null || type.length() == 0) {
|
||||
return false;
|
||||
|
@ -121,19 +127,6 @@ final class QRCodeEncoder {
|
|||
contents = data;
|
||||
displayContents = data;
|
||||
title = activity.getString(R.string.contents_text);
|
||||
if (format.equals(Contents.Format.CODE_128)) {
|
||||
this.format = BarcodeFormat.CODE_128;
|
||||
} else if (format.equals(Contents.Format.CODE_39)) {
|
||||
this.format = BarcodeFormat.CODE_39;
|
||||
} else if (format.equals(Contents.Format.EAN_8)) {
|
||||
this.format = BarcodeFormat.EAN_8;
|
||||
} else if (format.equals(Contents.Format.EAN_13)) {
|
||||
this.format = BarcodeFormat.EAN_13;
|
||||
} else if (format.equals(Contents.Format.UPC_A)) {
|
||||
this.format = BarcodeFormat.UPC_A;
|
||||
} else if (format.equals(Contents.Format.UPC_E)) {
|
||||
this.format = BarcodeFormat.UPC_E;
|
||||
}
|
||||
}
|
||||
}
|
||||
return contents != null && contents.length() > 0;
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.provider.BaseColumns;
|
|||
import android.text.ClipboardManager;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.client.android.Contents;
|
||||
import com.google.zxing.client.android.R;
|
||||
|
@ -98,7 +99,7 @@ public final class ShareActivity extends Activity {
|
|||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
|
||||
intent.putExtra(Intents.Encode.DATA, clipboard.getText().toString());
|
||||
intent.putExtra(Intents.Encode.FORMAT, Contents.Format.QR_CODE);
|
||||
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +152,7 @@ public final class ShareActivity extends Activity {
|
|||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
|
||||
intent.putExtra(Intents.Encode.DATA, text);
|
||||
intent.putExtra(Intents.Encode.FORMAT, Contents.Format.QR_CODE);
|
||||
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
@ -220,7 +221,7 @@ public final class ShareActivity extends Activity {
|
|||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Intents.Encode.TYPE, Contents.Type.CONTACT);
|
||||
intent.putExtra(Intents.Encode.DATA, bundle);
|
||||
intent.putExtra(Intents.Encode.FORMAT, Contents.Format.QR_CODE);
|
||||
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,9 @@ public final class BarcodeFormat {
|
|||
}
|
||||
|
||||
public static BarcodeFormat valueOf(String name) {
|
||||
if (name == null || name.length() == 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
BarcodeFormat format = (BarcodeFormat) VALUES.get(name);
|
||||
if (format == null) {
|
||||
throw new IllegalArgumentException();
|
||||
|
|
Loading…
Reference in a new issue