Skip to content

Commit

Permalink
v60 (3.5.3) (#3)
Browse files Browse the repository at this point in the history
* Base Fixes

* Bug #1

* try/catch added for bug

* Attempting to fix

* Crash fixing attempt

* seems to be good to go!

* Try/Catch implementation
  • Loading branch information
andrewcross authored Dec 20, 2017
1 parent c23f8b7 commit 8f7133d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
15 changes: 7 additions & 8 deletions camerakit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ ext {
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 27

defaultConfig {
minSdkVersion 18
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"

Expand All @@ -35,12 +34,12 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile "com.android.support:exifinterface:25.3.1"
compile 'com.android.support:appcompat-v7:27.0.2'
compile "com.android.support:exifinterface:27.0.2"

compile 'android.arch.lifecycle:runtime:1.0.0-alpha1'
compile 'android.arch.lifecycle:extensions:1.0.0-alpha1'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha1'
compile 'android.arch.lifecycle:runtime:1.0.3'
compile 'android.arch.lifecycle:extensions:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
}

apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
Expand Down
59 changes: 44 additions & 15 deletions camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.Log;
Expand Down Expand Up @@ -235,7 +234,11 @@ public void onPictureTaken(byte[] data, Camera camera) {
// Reset capturing state to allow photos to be taken
capturingImage = false;

camera.startPreview();
// Wrapping in a try catch to try and avoid crashes.
// https://fabric.io/goosechase/android/apps/com.goosechaseadventures.goosechase/issues/59aed6cfbe077a4dcc2822fc
try {
camera.startPreview();
} catch(Exception e){}
}
});
}
Expand Down Expand Up @@ -270,10 +273,26 @@ void startVideo() {

@Override
void endVideo() {
mMediaRecorder.stop();
mMediaRecorder.release();
mMediaRecorder = null;
mCameraListener.onVideoTaken(mVideoFile);
// Try to fix this bug:
// https://fabric.io/goosechase/android/apps/com.goosechaseadventures.goosechase/issues/59aee2b5be077a4dcc28a5bd
try {
mMediaRecorder.stop();
mMediaRecorder.release();
mMediaRecorder = null;
mCameraListener.onVideoTaken(mVideoFile);
} catch (Exception e) {
if(mMediaRecorder != null){
mMediaRecorder.release();
}

mMediaRecorder = null;
if(mVideoFile != null){
mVideoFile.delete();
mVideoFile = null;
}

mCameraListener.onVideoFailed(e);
}
}

// Code from SandriosCamera library
Expand Down Expand Up @@ -331,7 +350,7 @@ List<Size> sizesFromList(List<Camera.Size> sizes) {
// https://github.com/sandrios/sandriosCamera/blob/master/sandriosCamera/src/main/java/com/sandrios/sandriosCamera/internal/manager/impl/Camera1Manager.java#L212
void initResolutions() {
List<Size> previewSizes = sizesFromList(mCameraParameters.getSupportedPreviewSizes());
List<Size> videoSizes = (Build.VERSION.SDK_INT > 10) ? sizesFromList(mCameraParameters.getSupportedVideoSizes()) : previewSizes;
List<Size> videoSizes = sizesFromList(mCameraParameters.getSupportedVideoSizes());

CamcorderProfile camcorderProfile = getCamcorderProfile(mVideoQuality);

Expand Down Expand Up @@ -440,6 +459,13 @@ private int calculateCaptureRotation() {
}

private void adjustCameraParameters() {
// Try and fix the following bug:
// https://fabric.io/goosechase/android/apps/com.goosechaseadventures.goosechase/issues/59aed6dabe077a4dcc282396
if(mCameraParameters == null){
// mCamera should also be valid here since you can only call this method after mCamera has been set or checked.
mCameraParameters = mCamera.getParameters();
}

initResolutions();

boolean invertPreviewSizes = (mCameraInfo.orientation + mDisplayOrientation) % 180 == 0;
Expand All @@ -459,11 +485,10 @@ private void adjustCameraParameters() {
);
int rotation = calculateCaptureRotation();
mCameraParameters.setRotation(rotation);
mCamera.setParameters(mCameraParameters);

setFocus(mFocus);
setFlash(mFlash);

mCamera.setParameters(mCameraParameters);
}

private void collectCameraProperties() {
Expand Down Expand Up @@ -667,12 +692,16 @@ private void resetFocus(final boolean success, final Camera camera) {
public void run() {
if (camera != null) {
camera.cancelAutoFocus();
Camera.Parameters params = camera.getParameters();
if (params.getFocusMode() != Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) {
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
params.setFocusAreas(null);
params.setMeteringAreas(null);
camera.setParameters(params);
try {
Camera.Parameters params = camera.getParameters();
if (params.getFocusMode() != Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) {
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
params.setFocusAreas(null);
params.setMeteringAreas(null);
camera.setParameters(params);
}
} catch (Exception e) {
Log.i(TAG, "Couldn't set parameters for focus");
}

if (mAutofocusCallback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public void onVideoTaken(File video) {

}

public void onVideoFailed(Exception e) {

}
}
6 changes: 6 additions & 0 deletions camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ public void onVideoTaken(File video) {
getCameraListener().onVideoTaken(video);
}

@Override
public void onVideoFailed(Exception e) {
super.onVideoFailed(e);
getCameraListener().onVideoFailed(e);
}

public void setCameraListener(@Nullable CameraListener cameraListener) {
this.mCameraListener = cameraListener;
}
Expand Down

0 comments on commit 8f7133d

Please sign in to comment.