Small updates and improvements to the Android client.

git-svn-id: https://zxing.googlecode.com/svn/trunk@577 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-09-11 14:02:28 +00:00
parent d45123da9e
commit db58d130a8
4 changed files with 19 additions and 5 deletions

View file

@ -21,6 +21,7 @@
<string name="button_cancel">Cancel</string> <string name="button_cancel">Cancel</string>
<string name="button_dial">Dial</string> <string name="button_dial">Dial</string>
<string name="button_email">Email</string> <string name="button_email">Email</string>
<string name="button_lookup_book">Look up book</string>
<string name="button_lookup_product">Look up product</string> <string name="button_lookup_product">Look up product</string>
<string name="button_ok">OK</string> <string name="button_ok">OK</string>
<string name="button_open_browser">Open browser</string> <string name="button_open_browser">Open browser</string>

View file

@ -22,6 +22,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnCompletionListener;
@ -169,6 +170,12 @@ public final class BarcodesCaptureActivity extends Activity implements SurfaceHo
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override
public void onConfigurationChanged(Configuration config) {
// Do nothing, this is to prevent the activity from being restarted when the keyboard opens.
super.onConfigurationChanged(config);
}
private final DialogInterface.OnClickListener mAboutListener = new DialogInterface.OnClickListener() { private final DialogInterface.OnClickListener mAboutListener = new DialogInterface.OnClickListener() {
public void onClick(android.content.DialogInterface dialogInterface, int i) { public void onClick(android.content.DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.zxing_url))); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.zxing_url)));

View file

@ -35,6 +35,7 @@ import java.net.URI;
public class QRCodeEncoder { public class QRCodeEncoder {
private static final String TAG = "QRCodeEncoder"; private static final String TAG = "QRCodeEncoder";
private static final String CHART_SERVER_URL = "//chart.apis.google.com/chart?cht=qr&chs=";
private Activity mActivity; private Activity mActivity;
private String mContents; private String mContents;
@ -151,12 +152,12 @@ public class QRCodeEncoder {
} }
public void run() { public void run() {
String url = "//chartserver.apis.google.com/chart?cht=qr&chs="; String url = CHART_SERVER_URL + mPixelResolution + "x" + mPixelResolution + "&chl=" +
url += mPixelResolution + "x" + mPixelResolution + "&chl=" + mContents; mContents;
try { try {
URI uri = new URI("http", url, null); URI uri = new URI("http", url, null);
HttpGet get = new HttpGet(uri); HttpGet get = new HttpGet(uri);
AndroidHttpClient client = AndroidHttpClient.newInstance("Android-BarcodeScanner/0.1"); AndroidHttpClient client = AndroidHttpClient.newInstance("Android-Barcodes/0.1");
HttpResponse response = client.execute(get); HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
Bitmap image = BitmapFactory.decodeStream(entity.getContent()); Bitmap image = BitmapFactory.decodeStream(entity.getContent());

View file

@ -25,6 +25,7 @@ import com.google.zxing.Result;
import com.google.zxing.client.result.AddressBookParsedResult; import com.google.zxing.client.result.AddressBookParsedResult;
import com.google.zxing.client.result.EmailAddressParsedResult; import com.google.zxing.client.result.EmailAddressParsedResult;
import com.google.zxing.client.result.GeoParsedResult; import com.google.zxing.client.result.GeoParsedResult;
import com.google.zxing.client.result.ISBNParsedResult;
import com.google.zxing.client.result.ParsedResult; import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ParsedResultType; import com.google.zxing.client.result.ParsedResultType;
import com.google.zxing.client.result.ResultParser; import com.google.zxing.client.result.ResultParser;
@ -90,6 +91,8 @@ final class ResultHandler implements Button.OnClickListener {
buttonText = R.string.button_dial; buttonText = R.string.button_dial;
} else if (type.equals(ParsedResultType.GEO)) { } else if (type.equals(ParsedResultType.GEO)) {
buttonText = R.string.button_show_map; buttonText = R.string.button_show_map;
} else if (type.equals(ParsedResultType.ISBN)) {
buttonText = R.string.button_lookup_book;
} else { } else {
buttonText = 0; buttonText = 0;
} }
@ -127,10 +130,12 @@ final class ResultHandler implements Button.OnClickListener {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoResult.getGeoURI())); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoResult.getGeoURI()));
} else if (type.equals(ParsedResultType.UPC)) { } else if (type.equals(ParsedResultType.UPC)) {
UPCParsedResult upcResult = (UPCParsedResult) result; UPCParsedResult upcResult = (UPCParsedResult) result;
// TODO: Add some UI to choose which product search to do
//Uri uri = Uri.parse("http://www.upcdatabase.com/item.asp?upc=" + upcResult.getUPC());
Uri uri = Uri.parse("http://www.google.com/products?q=" + upcResult.getUPC()); Uri uri = Uri.parse("http://www.google.com/products?q=" + upcResult.getUPC());
intent = new Intent(Intent.ACTION_VIEW, uri); intent = new Intent(Intent.ACTION_VIEW, uri);
} else if (type.equals(ParsedResultType.ISBN)) {
ISBNParsedResult isbnResult = (ISBNParsedResult) result;
Uri uri = Uri.parse("http://www.google.com/products?q=" + isbnResult.getISBN());
intent = new Intent(Intent.ACTION_VIEW, uri);
} else if (type.equals(ParsedResultType.URI)) { } else if (type.equals(ParsedResultType.URI)) {
URIParsedResult uriResult = (URIParsedResult) result; URIParsedResult uriResult = (URIParsedResult) result;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriResult.getURI())); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriResult.getURI()));