From 17f454ad04cb4ba62a3c3010743220c4d3683151 Mon Sep 17 00:00:00 2001 From: Rory Glynn Date: Sun, 10 May 2015 16:23:06 +0100 Subject: [PATCH] Changes to address issue #40 and to prevent crashes when no cameras are available at all. (That could be caused by another application not releasing the camera or there simply not being any) --- mobile/build.gradle | 2 +- mobile/src/main/AndroidManifest.xml | 18 +++++++++----- .../yesequality/CameraFragment.java | 24 ++++++++++--------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/mobile/build.gradle b/mobile/build.gradle index c4f8811..e181266 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -8,7 +8,7 @@ android { applicationId "ie.yesequality.yesequality" minSdkVersion 15 targetSdkVersion 22 - versionCode 1 + versionCode 2 versionName "1.0.0" } diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index 9b9ef7d..5641345 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -1,12 +1,18 @@ - + - - + + + - + diff --git a/mobile/src/main/java/ie/yesequality/yesequality/CameraFragment.java b/mobile/src/main/java/ie/yesequality/yesequality/CameraFragment.java index 6a0bf6a..3204329 100644 --- a/mobile/src/main/java/ie/yesequality/yesequality/CameraFragment.java +++ b/mobile/src/main/java/ie/yesequality/yesequality/CameraFragment.java @@ -41,7 +41,6 @@ public class CameraFragment extends Fragment implements TextureView.SurfaceTextu private int mCameraId; - /** * Determine the current display orientation and rotate the mCamera preview * accordingly. @@ -133,13 +132,14 @@ public void onResume() { */ public void takePicture() { orientationListener.rememberOrientation(); - - mCamera.takePicture(null, null, this); + if (mCamera != null) { + mCamera.takePicture(null, null, this); + } else { + Toast.makeText(getActivity(), "Unable to take a picture because the camera is not connected. :(", Toast.LENGTH_LONG).show(); + } } - - private Bitmap overlay(Bitmap bmp1, Bitmap bmp2, float left, float top, int parentWidth, int parentHeight) { //Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1 @@ -175,10 +175,10 @@ private Bitmap bitmapScaler(Bitmap bitmap, int newWidth, int newHeight) { Canvas canvas = new Canvas(scaledBitmap); canvas.setMatrix(scaleMatrix); - Paint paint =new Paint(Paint.FILTER_BITMAP_FLAG); + Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); paint.setAntiAlias(true); canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / - 2,paint ); + 2, paint); return scaledBitmap; } @@ -306,19 +306,21 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { -// Ignored, Camera does all the work for us + // Ignored, Camera does all the work for us } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { - mCamera.stopPreview(); - mCamera.release(); + if (mCamera != null) { + mCamera.stopPreview(); + mCamera.release(); + } return true; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { -// Invoked every time there's a new Camera preview frame + // Invoked every time there's a new Camera preview frame }