// Path: app/src/main/java/com/oakzmm/demoapp/utils/DensityUtil.java
// public class DensityUtil {
// 
// 	public static int dip2px(Context context, float dpValue) {
// 		final float scale = context.getResources().getDisplayMetrics().density;
// 		return (int) (dpValue * scale + 0.5f);
// 	}
// 
// 	public static int px2dip(Context context, float pxValue) {
// 		final float scale = context.getResources().getDisplayMetrics().density;
// 		return (int) (pxValue / scale + 0.5f);
// 	}
// 
// 	/**
// 	 * 获取控件的高度，如果获取的高度为0，则重新计算尺寸后再返回高度
// 	 * 
// 	 * @param view
// 	 * @return
// 	 */
// 	public static int getViewMeasuredHeight(View view) {
// 		// int height = view.getMeasuredHeight();
// 		// if(0 < height){
// 		// return height;
// 		// }
// 		calcViewMeasure(view);
// 		return view.getMeasuredHeight();
// 	}
// 
// 	/**
// 	 * 获取控件的宽度，如果获取的宽度为0，则重新计算尺寸后再返回宽度
// 	 * 
// 	 * @param view
// 	 * @return
// 	 */
// 	public static int getViewMeasuredWidth(View view) {
// 		// int width = view.getMeasuredWidth();
// 		// if(0 < width){
// 		// return width;
// 		// }
// 		calcViewMeasure(view);
// 		return view.getMeasuredWidth();
// 	}
// 
// 	/**
// 	 * 测量控件的尺寸
// 	 * 
// 	 * @param view
// 	 */
// 	public static void calcViewMeasure(View view) {
// 		int width = View.MeasureSpec.makeMeasureSpec(0,
// 				View.MeasureSpec.UNSPECIFIED);
// 		int height = View.MeasureSpec.makeMeasureSpec(0,
// 				View.MeasureSpec.UNSPECIFIED);
// 		view.measure(width, height);
// 	}
// }


import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.Camera;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceHolder;
import com.oakzmm.demoapp.utils.DensityUtil;
import java.io.IOException;
/*
 * Copyright (C) 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oakzmm.demoapp.zxing.camera;




/**
 * This object wraps the Camera service object and expects to be the only one talking to it. The
 * implementation encapsulates the steps needed to take preview-sized images, which are used for
 * both preview and decoding.
 */
public final class CameraManager {

    static final int SDK_INT; // Later we can use Build.VERSION.SDK_INT
    private static final String TAG = CameraManager.class.getSimpleName();
    private static int MIN_FRAME_WIDTH = 200;
    private static int MIN_FRAME_HEIGHT = 200;
    private static int MAX_FRAME_WIDTH = 480;
    private static int MAX_FRAME_HEIGHT = 360;
    private static CameraManager cameraManager;

    static {
        int sdkInt;
        try {
            sdkInt = Integer.parseInt(Build.VERSION.SDK);
        } catch (NumberFormatException nfe) {
            // Just to be safe
            sdkInt = 10000;
        }
        SDK_INT = sdkInt;
    }

    private final Context context;
    private final CameraConfigurationManager configManager;
    private final boolean useOneShotPreviewCallback;
    /**
     * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
     * clear the handler so it will only receive one message.
     */
    private final PreviewCallback previewCallback;
    /**
     * Autofocus callbacks arrive here, and are dispatched to the Handler which requested them.
     */
    private final AutoFocusCallback autoFocusCallback;
    private Camera camera;
    private Rect framingRect;
    private Rect framingRectInPreview;
    private boolean initialized;
    private boolean previewing;

    private CameraManager(Context context) {
// Path: app/src/main/java/com/oakzmm/demoapp/utils/DensityUtil.java
// public class DensityUtil {
// 
// 	public static int dip2px(Context context, float dpValue) {
// 		final float scale = context.getResources().getDisplayMetrics().density;
// 		return (int) (dpValue * scale + 0.5f);
// 	}
// 
// 	public static int px2dip(Context context, float pxValue) {
// 		final float scale = context.getResources().getDisplayMetrics().density;
// 		return (int) (pxValue / scale + 0.5f);
// 	}
// 
// 	/**
// 	 * 获取控件的高度，如果获取的高度为0，则重新计算尺寸后再返回高度
// 	 * 
// 	 * @param view
// 	 * @return
// 	 */
// 	public static int getViewMeasuredHeight(View view) {
// 		// int height = view.getMeasuredHeight();
// 		// if(0 < height){
// 		// return height;
// 		// }
// 		calcViewMeasure(view);
// 		return view.getMeasuredHeight();
// 	}
// 
// 	/**
// 	 * 获取控件的宽度，如果获取的宽度为0，则重新计算尺寸后再返回宽度
// 	 * 
// 	 * @param view
// 	 * @return
// 	 */
// 	public static int getViewMeasuredWidth(View view) {
// 		// int width = view.getMeasuredWidth();
// 		// if(0 < width){
// 		// return width;
// 		// }
// 		calcViewMeasure(view);
// 		return view.getMeasuredWidth();
// 	}
// 
// 	/**
// 	 * 测量控件的尺寸
// 	 * 
// 	 * @param view
// 	 */
// 	public static void calcViewMeasure(View view) {
// 		int width = View.MeasureSpec.makeMeasureSpec(0,
// 				View.MeasureSpec.UNSPECIFIED);
// 		int height = View.MeasureSpec.makeMeasureSpec(0,
// 				View.MeasureSpec.UNSPECIFIED);
// 		view.measure(width, height);
// 	}
// }


// Path: app/src/main/java/com/oakzmm/demoapp/zxing/camera/CameraManager.java
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.Camera;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceHolder;
import com.oakzmm.demoapp.utils.DensityUtil;
import java.io.IOException;

/*
 * Copyright (C) 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oakzmm.demoapp.zxing.camera;




/**
 * This object wraps the Camera service object and expects to be the only one talking to it. The
 * implementation encapsulates the steps needed to take preview-sized images, which are used for
 * both preview and decoding.
 */
public final class CameraManager {

    static final int SDK_INT; // Later we can use Build.VERSION.SDK_INT
    private static final String TAG = CameraManager.class.getSimpleName();
    private static int MIN_FRAME_WIDTH = 200;
    private static int MIN_FRAME_HEIGHT = 200;
    private static int MAX_FRAME_WIDTH = 480;
    private static int MAX_FRAME_HEIGHT = 360;
    private static CameraManager cameraManager;

    static {
        int sdkInt;
        try {
            sdkInt = Integer.parseInt(Build.VERSION.SDK);
        } catch (NumberFormatException nfe) {
            // Just to be safe
            sdkInt = 10000;
        }
        SDK_INT = sdkInt;
    }

    private final Context context;
    private final CameraConfigurationManager configManager;
    private final boolean useOneShotPreviewCallback;
    /**
     * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
     * clear the handler so it will only receive one message.
     */
    private final PreviewCallback previewCallback;
    /**
     * Autofocus callbacks arrive here, and are dispatched to the Handler which requested them.
     */
    private final AutoFocusCallback autoFocusCallback;
    private Camera camera;
    private Rect framingRect;
    private Rect framingRectInPreview;
    private boolean initialized;
    private boolean previewing;

    private CameraManager(Context context) {
        MIN_FRAME_WIDTH = DensityUtil.dip2px(context, MIN_FRAME_WIDTH);