X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=android%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fandroid%2Fencode%2FEncodeActivity.java;h=13fbe6f92dadc341cab959caba36785b805d17e5;hb=4850a108ddd277ae9e4e8cc1806c3f928f1d0776;hp=d0db91d9fd4e0355f8bbb91567b1f7c1c4afdd03;hpb=74fded6d793e4a8a44f98d83a09af1ce0b271838;p=zxing.git diff --git a/android/src/com/google/zxing/client/android/encode/EncodeActivity.java b/android/src/com/google/zxing/client/android/encode/EncodeActivity.java index d0db91d9..13fbe6f9 100755 --- a/android/src/com/google/zxing/client/android/encode/EncodeActivity.java +++ b/android/src/com/google/zxing/client/android/encode/EncodeActivity.java @@ -18,6 +18,7 @@ package com.google.zxing.client.android.encode; import com.google.zxing.BarcodeFormat; import com.google.zxing.WriterException; +import com.google.zxing.client.android.FinishListener; import com.google.zxing.client.android.Intents; import com.google.zxing.client.android.R; @@ -83,7 +84,7 @@ public final class EncodeActivity extends Activity { setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle()); qrCodeEncoder.requestBarcode(handler, smallerDimension); progressDialog = ProgressDialog.show(EncodeActivity.this, null, - getString(R.string.msg_encode_in_progress), true, true, cancelListener); + getString(R.string.msg_encode_in_progress), true, true, new FinishListener(EncodeActivity.this)); } catch (IllegalArgumentException e) { showErrorMessage(R.string.msg_encode_contents_failed); } @@ -114,18 +115,6 @@ public final class EncodeActivity extends Activity { } }; - private final OnClickListener clickListener = new OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - finish(); - } - }; - - private final OnCancelListener cancelListener = new OnCancelListener() { - public void onCancel(DialogInterface dialog) { - finish(); - } - }; - @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -158,46 +147,43 @@ public final class EncodeActivity extends Activity { String contents = qrCodeEncoder.getContents(); Bitmap bitmap; try { - bitmap = QRCodeEncoder.encodeAsBitmap(contents, - BarcodeFormat.QR_CODE, - SHARE_BARCODE_DIMENSION, - SHARE_BARCODE_DIMENSION); + bitmap = QRCodeEncoder.encodeAsBitmap(contents, BarcodeFormat.QR_CODE, + SHARE_BARCODE_DIMENSION, SHARE_BARCODE_DIMENSION); } catch (WriterException we) { - Log.w(TAG, we.toString()); + Log.w(TAG, we); return true; } - File barcodeFile; + File bsRoot = new File(Environment.getExternalStorageDirectory(), "BarcodeScanner"); + File barcodesRoot = new File(bsRoot, "Barcodes"); + if (!barcodesRoot.exists() && !barcodesRoot.mkdirs()) { + Log.w(TAG, "Couldn't make dir " + barcodesRoot); + showErrorMessage(R.string.msg_unmount_usb); + return true; + } + File barcodeFile = new File(barcodesRoot, makeBarcodeFileName(contents) + ".png"); + barcodeFile.delete(); + FileOutputStream fos = null; try { - File bsRoot = new File(Environment.getExternalStorageDirectory(), "BarcodeScanner"); - File barcodesRoot = new File(bsRoot, "Barcodes"); - if (!barcodesRoot.mkdirs()) { - Log.v(TAG, "Couldn't make dir " + barcodesRoot); - showErrorMessage(R.string.msg_unmount_usb); - return true; - } - barcodeFile = new File(barcodesRoot, makeBarcodeFileName(contents) + ".png"); - barcodeFile.delete(); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(barcodeFile); - bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos); - } catch (FileNotFoundException fnfe) { - Log.v(TAG, "Couldn't access file " + barcodeFile + " due to " + fnfe); - showErrorMessage(R.string.msg_unmount_usb); - return true; - } finally { - if (fos != null) { + fos = new FileOutputStream(barcodeFile); + bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos); + } catch (FileNotFoundException fnfe) { + Log.w(TAG, "Couldn't access file " + barcodeFile + " due to " + fnfe); + showErrorMessage(R.string.msg_unmount_usb); + return true; + } finally { + if (fos != null) { + try { fos.close(); + } catch (IOException ioe) { + // do nothing } } - } catch (IOException ioe) { - Log.w(TAG, ioe.toString()); - return true; } Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); - intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle()); + intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " - " + + qrCodeEncoder.getTitle()); intent.putExtra(Intent.EXTRA_TEXT, qrCodeEncoder.getContents()); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + barcodeFile.getAbsolutePath())); intent.setType("image/png"); @@ -236,7 +222,8 @@ public final class EncodeActivity extends Activity { } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(message); - builder.setPositiveButton(R.string.button_ok, clickListener); + builder.setPositiveButton(R.string.button_ok, new FinishListener(this)); + builder.setOnCancelListener(new FinishListener(this)); builder.show(); } }