Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2010 ZXing authors
      3  *
      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
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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.
     15  */
     16 
     17 package com.google.zxing.client.android.camera;
     18 
     19 import android.graphics.Point;
     20 import android.hardware.Camera;
     21 import android.os.Handler;
     22 import android.os.Message;
     23 import android.util.Log;
     24 
     25 final class PreviewCallback implements Camera.PreviewCallback {
     26 
     27   private static final String TAG = PreviewCallback.class.getSimpleName();
     28 
     29   private final CameraConfigurationManager configManager;
     30   private Handler previewHandler;
     31   private int previewMessage;
     32 
     33   PreviewCallback(CameraConfigurationManager configManager) {
     34     this.configManager = configManager;
     35   }
     36 
     37   void setHandler(Handler previewHandler, int previewMessage) {
     38     this.previewHandler = previewHandler;
     39     this.previewMessage = previewMessage;
     40   }
     41 
     42   public void onPreviewFrame(byte[] data, Camera camera) {
     43     Point cameraResolution = configManager.getCameraResolution();
     44     Handler thePreviewHandler = previewHandler;
     45     if (thePreviewHandler != null) {
     46       Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
     47           cameraResolution.y, data);
     48       message.sendToTarget();
     49       previewHandler = null;
     50     } else {
     51       Log.d(TAG, "Got preview callback, but no handler for it");
     52     }
     53   }
     54 
     55 }
     56