// Path: sdk/src/main/java/io/kickflip/sdk/event/CameraOpenedEvent.java
// public class CameraOpenedEvent {
// 
//     public Parameters params;
// 
//     public CameraOpenedEvent(Parameters params) {
//         this.params = params;
//     }
// 
// }
// 
// Path: sdk/src/main/java/io/kickflip/sdk/view/GLCameraEncoderView.java
// public class GLCameraEncoderView extends GLCameraView {
//     private static final String TAG = "GLCameraEncoderView";
// 
//     protected CameraEncoder mCameraEncoder;
// 
//     public GLCameraEncoderView(Context context) {
//         super(context);
//     }
// 
//     public GLCameraEncoderView(Context context, AttributeSet attrs) {
//         super(context, attrs);
//     }
// 
//     public void setCameraEncoder(CameraEncoder encoder){
//         mCameraEncoder = encoder;
//         setCamera(mCameraEncoder.getCamera());
//     }
// 
//     @Override
//     public boolean onTouchEvent(MotionEvent ev) {
//         if(mScaleGestureDetector != null){
//             mScaleGestureDetector.onTouchEvent(ev);
//         }
//         if(mCameraEncoder != null && ev.getPointerCount() == 1 && (ev.getAction() == MotionEvent.ACTION_MOVE)){
//             mCameraEncoder.handleCameraPreviewTouchEvent(ev);
//         }else if(mCameraEncoder != null && ev.getPointerCount() == 1 && (ev.getAction() == MotionEvent.ACTION_DOWN)){
//             mCameraEncoder.handleCameraPreviewTouchEvent(ev);
//         }
//         return true;
//     }
// 
// 
// }
// 
// Path: sdk/src/main/java/io/kickflip/sdk/view/GLCameraView.java
// public class GLCameraView extends GLSurfaceView {
//     private static final String TAG = "GLCameraView";
// 
//     protected ScaleGestureDetector mScaleGestureDetector;
//     private Camera mCamera;
//     private int mMaxZoom;
// 
//     public GLCameraView(Context context) {
//         super(context);
//         init(context);
//     }
// 
//     public GLCameraView(Context context, AttributeSet attrs) {
//         super(context, attrs);
//         init(context);
//     }
// 
//     private void init(Context context){
//         mMaxZoom = 0;
// 
//     }
// 
//     public void setCamera(Camera camera){
//         mCamera = camera;
//         Camera.Parameters camParams = mCamera.getParameters();
//         if(camParams.isZoomSupported()){
//             mMaxZoom = camParams.getMaxZoom();
//             mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleListener);
//         }
//     }
// 
//     public void releaseCamera(){
//         mCamera = null;
//         mScaleGestureDetector = null;
//     }
// 
//     private ScaleGestureDetector.SimpleOnScaleGestureListener mScaleListener = new ScaleGestureDetector.SimpleOnScaleGestureListener(){
// 
//         int mZoomWhenScaleBegan = 0;
//         int mCurrentZoom = 0;
// 
//         @Override
//         public boolean onScale(ScaleGestureDetector detector) {
//             if(mCamera != null){
//                 Camera.Parameters params = mCamera.getParameters();
//                 mCurrentZoom = (int) (mZoomWhenScaleBegan + (mMaxZoom * (detector.getScaleFactor() - 1)));
//                 mCurrentZoom = Math.min(mCurrentZoom, mMaxZoom);
//                 mCurrentZoom = Math.max(0, mCurrentZoom);
//                 params.setZoom(mCurrentZoom);
//                 mCamera.setParameters(params);
//             }
// 
//             return false;
//         }
// 
//         @Override
//         public boolean onScaleBegin(ScaleGestureDetector detector) {
//             mZoomWhenScaleBegan =  mCamera.getParameters().getZoom();
//             return true;
//         }
// 
//         @Override
//         public void onScaleEnd(ScaleGestureDetector detector) {
//         }
//     };
// 
//     @Override
//     public boolean onTouchEvent(MotionEvent ev) {
//         if(mScaleGestureDetector != null){
//             if(!mScaleGestureDetector.onTouchEvent(ev)){
//                 // No scale gesture detected
// 
//             }
//         }
//         return true;
//     }
// 
// 
// }


import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.opengl.EGLContext;
import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Trace;
import android.util.Log;
import android.view.MotionEvent;
import com.google.common.eventbus.EventBus;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.List;
import io.kickflip.sdk.event.CameraOpenedEvent;
import io.kickflip.sdk.view.GLCameraEncoderView;
import io.kickflip.sdk.view.GLCameraView;
import static com.google.common.base.Preconditions.checkNotNull;
        } else {
            previewFacts += " @" + (fpsRange[0] / 1000.0) + " - " + (fpsRange[1] / 1000.0) + "fps";
        }
        if (VERBOSE) Log.i(TAG, "Camera preview set: " + previewFacts);
    }

    public Camera getCamera() {
        return mCamera;
    }

    /**
     * Stops camera preview, and releases the camera to the system.
     */
    private void releaseCamera() {
        if (mDisplayView != null)
            releaseDisplayView();
        if (mCamera != null) {
            if (VERBOSE) Log.d(TAG, "releasing camera");
            mCamera.stopPreview();
            mCamera.release();
            mCamera = null;
        }
    }

    /**
     * Communicate camera-ready state to our display view.
     * This method allows us to handle custom subclasses
     */
    private void configureDisplayView() {
        if (mDisplayView instanceof GLCameraEncoderView)
// Path: sdk/src/main/java/io/kickflip/sdk/event/CameraOpenedEvent.java
// public class CameraOpenedEvent {
// 
//     public Parameters params;
// 
//     public CameraOpenedEvent(Parameters params) {
//         this.params = params;
//     }
// 
// }
// 
// Path: sdk/src/main/java/io/kickflip/sdk/view/GLCameraEncoderView.java
// public class GLCameraEncoderView extends GLCameraView {
//     private static final String TAG = "GLCameraEncoderView";
// 
//     protected CameraEncoder mCameraEncoder;
// 
//     public GLCameraEncoderView(Context context) {
//         super(context);
//     }
// 
//     public GLCameraEncoderView(Context context, AttributeSet attrs) {
//         super(context, attrs);
//     }
// 
//     public void setCameraEncoder(CameraEncoder encoder){
//         mCameraEncoder = encoder;
//         setCamera(mCameraEncoder.getCamera());
//     }
// 
//     @Override
//     public boolean onTouchEvent(MotionEvent ev) {
//         if(mScaleGestureDetector != null){
//             mScaleGestureDetector.onTouchEvent(ev);
//         }
//         if(mCameraEncoder != null && ev.getPointerCount() == 1 && (ev.getAction() == MotionEvent.ACTION_MOVE)){
//             mCameraEncoder.handleCameraPreviewTouchEvent(ev);
//         }else if(mCameraEncoder != null && ev.getPointerCount() == 1 && (ev.getAction() == MotionEvent.ACTION_DOWN)){
//             mCameraEncoder.handleCameraPreviewTouchEvent(ev);
//         }
//         return true;
//     }
// 
// 
// }
// 
// Path: sdk/src/main/java/io/kickflip/sdk/view/GLCameraView.java
// public class GLCameraView extends GLSurfaceView {
//     private static final String TAG = "GLCameraView";
// 
//     protected ScaleGestureDetector mScaleGestureDetector;
//     private Camera mCamera;
//     private int mMaxZoom;
// 
//     public GLCameraView(Context context) {
//         super(context);
//         init(context);
//     }
// 
//     public GLCameraView(Context context, AttributeSet attrs) {
//         super(context, attrs);
//         init(context);
//     }
// 
//     private void init(Context context){
//         mMaxZoom = 0;
// 
//     }
// 
//     public void setCamera(Camera camera){
//         mCamera = camera;
//         Camera.Parameters camParams = mCamera.getParameters();
//         if(camParams.isZoomSupported()){
//             mMaxZoom = camParams.getMaxZoom();
//             mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleListener);
//         }
//     }
// 
//     public void releaseCamera(){
//         mCamera = null;
//         mScaleGestureDetector = null;
//     }
// 
//     private ScaleGestureDetector.SimpleOnScaleGestureListener mScaleListener = new ScaleGestureDetector.SimpleOnScaleGestureListener(){
// 
//         int mZoomWhenScaleBegan = 0;
//         int mCurrentZoom = 0;
// 
//         @Override
//         public boolean onScale(ScaleGestureDetector detector) {
//             if(mCamera != null){
//                 Camera.Parameters params = mCamera.getParameters();
//                 mCurrentZoom = (int) (mZoomWhenScaleBegan + (mMaxZoom * (detector.getScaleFactor() - 1)));
//                 mCurrentZoom = Math.min(mCurrentZoom, mMaxZoom);
//                 mCurrentZoom = Math.max(0, mCurrentZoom);
//                 params.setZoom(mCurrentZoom);
//                 mCamera.setParameters(params);
//             }
// 
//             return false;
//         }
// 
//         @Override
//         public boolean onScaleBegin(ScaleGestureDetector detector) {
//             mZoomWhenScaleBegan =  mCamera.getParameters().getZoom();
//             return true;
//         }
// 
//         @Override
//         public void onScaleEnd(ScaleGestureDetector detector) {
//         }
//     };
// 
//     @Override
//     public boolean onTouchEvent(MotionEvent ev) {
//         if(mScaleGestureDetector != null){
//             if(!mScaleGestureDetector.onTouchEvent(ev)){
//                 // No scale gesture detected
// 
//             }
//         }
//         return true;
//     }
// 
// 
// }


// Path: sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.opengl.EGLContext;
import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Trace;
import android.util.Log;
import android.view.MotionEvent;
import com.google.common.eventbus.EventBus;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.List;
import io.kickflip.sdk.event.CameraOpenedEvent;
import io.kickflip.sdk.view.GLCameraEncoderView;
import io.kickflip.sdk.view.GLCameraView;
import static com.google.common.base.Preconditions.checkNotNull;

        } else {
            previewFacts += " @" + (fpsRange[0] / 1000.0) + " - " + (fpsRange[1] / 1000.0) + "fps";
        }
        if (VERBOSE) Log.i(TAG, "Camera preview set: " + previewFacts);
    }

    public Camera getCamera() {
        return mCamera;
    }

    /**
     * Stops camera preview, and releases the camera to the system.
     */
    private void releaseCamera() {
        if (mDisplayView != null)
            releaseDisplayView();
        if (mCamera != null) {
            if (VERBOSE) Log.d(TAG, "releasing camera");
            mCamera.stopPreview();
            mCamera.release();
            mCamera = null;
        }
    }

    /**
     * Communicate camera-ready state to our display view.
     * This method allows us to handle custom subclasses
     */
    private void configureDisplayView() {
        if (mDisplayView instanceof GLCameraEncoderView)
            ((GLCameraEncoderView) mDisplayView).setCameraEncoder(this);