00001 /* 00002 * Copyright (C) 2010 ZXing authors 00003 * Copyright 2011 Robert Theis 00004 * Copyright 2012 Jaime Navarro Santapau 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00027 package edu.uoc.ocr; 00028 00029 import com.googlecode.tesseract.android.TessBaseAPI; 00030 00031 import edu.uoc.ocr.R; 00032 import edu.uoc.ocr.BeepManager; 00033 import edu.uoc.ocr.CaptureActivityForOcr; 00034 00035 import android.os.Handler; 00036 import android.os.Looper; 00037 import android.os.Message; 00038 00043 final class DecodeHandler extends Handler { 00044 00045 private final CaptureActivityForOcr activity; 00046 private boolean running = true; 00047 private final TessBaseAPI baseApi; 00048 private BeepManager beepManager; 00049 00050 DecodeHandler(CaptureActivityForOcr activity) { 00051 this.activity = activity; 00052 baseApi = activity.getBaseApi(); 00053 beepManager = new BeepManager(activity); 00054 beepManager.updatePrefs(); 00055 } 00056 00057 @Override 00058 public void handleMessage(Message message) { 00059 if (!running) { 00060 return; 00061 } 00062 switch (message.what) { 00063 case R.id.ocr_decode: 00064 ocrDecode((byte[]) message.obj, message.arg1, message.arg2); 00065 break; 00066 case R.id.quit: 00067 running = false; 00068 Looper.myLooper().quit(); 00069 break; 00070 } 00071 } 00072 00081 private void ocrDecode(byte[] data, int width, int height) { 00082 beepManager.playBeepSoundAndVibrate(); 00083 activity.displayProgressDialog(); 00084 00085 // Launch OCR asynchronously, so we get the dialog box displayed 00086 // immediately 00087 new OcrRecognizeAsyncTask(activity, baseApi, data, width, height) 00088 .execute(); 00089 } 00090 00091 } 00092 00093