2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.android.encode;
19 import android.graphics.Bitmap;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.util.Log;
23 import com.google.zxing.BarcodeFormat;
24 import com.google.zxing.WriterException;
25 import com.google.zxing.client.android.R;
27 final class EncodeThread extends Thread {
29 private static final String TAG = EncodeThread.class.getSimpleName();
31 private final String contents;
32 private final Handler handler;
33 private final int pixelResolution;
34 private final BarcodeFormat format;
36 EncodeThread(String contents, Handler handler, int pixelResolution, BarcodeFormat format) {
37 this.contents = contents;
38 this.handler = handler;
39 this.pixelResolution = pixelResolution;
46 Bitmap bitmap = QRCodeEncoder.encodeAsBitmap(contents, format, pixelResolution, pixelResolution);
47 Message message = Message.obtain(handler, R.id.encode_succeeded);
49 message.sendToTarget();
50 } catch (WriterException e) {
51 Log.e(TAG, "Could not encode barcode", e);
52 Message message = Message.obtain(handler, R.id.encode_failed);
53 message.sendToTarget();
54 } catch (IllegalArgumentException e) {
55 Log.e(TAG, "Could not encode barcode", e);
56 Message message = Message.obtain(handler, R.id.encode_failed);
57 message.sendToTarget();