| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -54,7 +54,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    final static boolean DEFAULT_PLAY_SOUNDS = true; | 
					 | 
					 | 
					 | 
					    final static boolean DEFAULT_PLAY_SOUNDS = true; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // Self managed parameters
 | 
					 | 
					 | 
					 | 
					    // Self managed parameters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private boolean mCropOutput; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private boolean mPlaySounds; | 
					 | 
					 | 
					 | 
					    private boolean mPlaySounds; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); | 
					 | 
					 | 
					 | 
					    private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -98,7 +97,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); | 
					 | 
					 | 
					 | 
					        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // Self managed
 | 
					 | 
					 | 
					 | 
					        // Self managed
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        boolean cropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, DEFAULT_CROP_OUTPUT); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); | 
					 | 
					 | 
					 | 
					        boolean playSounds = a.getBoolean(R.styleable.CameraView_cameraPlaySounds, DEFAULT_PLAY_SOUNDS); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // Camera controller params
 | 
					 | 
					 | 
					 | 
					        // Camera controller params
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -171,7 +169,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        addView(mScrollGestureLayout); | 
					 | 
					 | 
					 | 
					        addView(mScrollGestureLayout); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // Apply self managed
 | 
					 | 
					 | 
					 | 
					        // Apply self managed
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        setCropOutput(cropOutput); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        setPlaySounds(playSounds); | 
					 | 
					 | 
					 | 
					        setPlaySounds(playSounds); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // Apply camera controller params
 | 
					 | 
					 | 
					 | 
					        // Apply camera controller params
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -1070,31 +1067,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * Whether we should crop the picture output to match CameraView aspect ratio. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * This is only relevant if CameraView dimensions were somehow constrained | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * (e.g. by fixed value or MATCH_PARENT) and do not match internal aspect ratio. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * Please note that this requires additional computations after the picture is taken. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @param cropOutput whether to crop | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     */ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public void setCropOutput(boolean cropOutput) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        this.mCropOutput = cropOutput; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * Returns whether we should crop the picture output to match CameraView aspect ratio. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @see #setCropOutput(boolean) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * @return whether we crop | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     */ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public boolean getCropOutput() { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return mCropOutput; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					    /** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * Sets a {@link CameraListener} instance to be notified of all | 
					 | 
					 | 
					 | 
					     * Sets a {@link CameraListener} instance to be notified of all | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * interesting events that will happen during the camera lifecycle. | 
					 | 
					 | 
					 | 
					     * interesting events that will happen during the camera lifecycle. | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -1550,23 +1522,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        @Override | 
					 | 
					 | 
					 | 
					        @Override | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        public void processImage(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) { | 
					 | 
					 | 
					 | 
					        public void processImage(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            mLogger.i("processImage"); | 
					 | 
					 | 
					 | 
					            mLogger.i("processImage"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            mWorkerHandler.post(new Runnable() { | 
					 | 
					 | 
					 | 
					            dispatchOnPictureTaken(jpeg); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                @Override | 
					 | 
					 | 
					 | 
					            // TODO: remove.
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                public void run() { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    byte[] jpeg2 = jpeg; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    if (mCropOutput && mCameraPreview.isCropping()) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        // If consistent, dimensions of the jpeg Bitmap and dimensions of getWidth(), getHeight()
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        // Live in the same reference system.
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        int w = consistentWithView ? getWidth() : getHeight(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        int h = consistentWithView ? getHeight() : getWidth(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        AspectRatio targetRatio = AspectRatio.of(w, h); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        mLogger.i("processImage", "is consistent?", consistentWithView); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        mLogger.i("processImage", "viewWidth?", getWidth(), "viewHeight?", getHeight()); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        jpeg2 = CropHelper.cropToJpeg(jpeg, targetRatio, 100); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    dispatchOnPictureTaken(jpeg2); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            }); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        @Override | 
					 | 
					 | 
					 | 
					        @Override | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -1576,16 +1533,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                @Override | 
					 | 
					 | 
					 | 
					                @Override | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                public void run() { | 
					 | 
					 | 
					 | 
					                public void run() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    byte[] jpeg; | 
					 | 
					 | 
					 | 
					                    byte[] jpeg; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    if (mCropOutput && mCameraPreview.isCropping()) { | 
					 | 
					 | 
					 | 
					                    if (mCameraPreview.isCropping()) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        int w = consistentWithView ? getWidth() : getHeight(); | 
					 | 
					 | 
					 | 
					                        int w = consistentWithView ? getWidth() : getHeight(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        int h = consistentWithView ? getHeight() : getWidth(); | 
					 | 
					 | 
					 | 
					                        int h = consistentWithView ? getHeight() : getWidth(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        AspectRatio targetRatio = AspectRatio.of(w, h); | 
					 | 
					 | 
					 | 
					                        AspectRatio targetRatio = AspectRatio.of(w, h); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        mLogger.i("processSnapshot", "is consistent?", consistentWithView); | 
					 | 
					 | 
					 | 
					                        mLogger.i("processSnapshot", "is consistent?", consistentWithView); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight()); | 
					 | 
					 | 
					 | 
					                        mLogger.i("processSnapshot", "viewWidth?", getWidth(), "viewHeight?", getHeight()); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 100); | 
					 | 
					 | 
					 | 
					                        jpeg = CropHelper.cropToJpeg(yuv, targetRatio, 90); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    } else { | 
					 | 
					 | 
					 | 
					                    } else { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        ByteArrayOutputStream out = new ByteArrayOutputStream(); | 
					 | 
					 | 
					 | 
					                        ByteArrayOutputStream out = new ByteArrayOutputStream(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        yuv.compressToJpeg(new Rect(0, 0, yuv.getWidth(), yuv.getHeight()), 100, out); | 
					 | 
					 | 
					 | 
					                        yuv.compressToJpeg(new Rect(0, 0, yuv.getWidth(), yuv.getHeight()), 90, out); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        jpeg = out.toByteArray(); | 
					 | 
					 | 
					 | 
					                        jpeg = out.toByteArray(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    } | 
					 | 
					 | 
					 | 
					                    } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    dispatchOnPictureTaken(jpeg); | 
					 | 
					 | 
					 | 
					                    dispatchOnPictureTaken(jpeg); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |