Skip to content

armgit / haven

Public Imported from GitHub
0

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors

switch to new CameraView: https://github.com/natario1/CameraView

n8fr8f906d5ce3490
diff --git a/build.gradle b/build.gradle
index f53a0ed..0c47054 100644
--- a/build.gradle
+++ b/build.gradle
@@ -149,7 +149,7 @@ dependencies {
implementation 'me.angrybyte.picker:picker:1.3.1'
implementation 'com.github.stfalcon:frescoimageviewer:0.5.0'
implementation 'com.facebook.fresco:fresco:1.10.0'
- // implementation 'com.github.derlio.waveform:library:1.0.3@aar'
+
implementation 'com.github.derlio:audio-waveform:v1.0.1'
implementation 'org.firezenk:audiowaves:1.1@aar'
implementation 'com.maxproj.simplewaveform:app:1.0.0'
@@ -157,7 +157,7 @@ dependencies {
implementation('com.mikepenz:aboutlibraries:6.1.1@aar') {
transitive = true
}
- implementation 'com.asksira.android:cameraviewplus:0.9.5'
+
implementation 'com.github.halilozercan:BetterVideoPlayer:1.1.0'
implementation 'io.github.silvaren:easyrs:0.5.3'
implementation 'org.jcodec:jcodec:0.2.3'
@@ -171,13 +171,16 @@ dependencies {
implementation "android.arch.lifecycle:extensions:1.1.1"
testImplementation "junit:junit:4.12"
- androidTestImplementation 'androidx.test:runner:1.1.0'
- androidTestImplementation 'androidx.test:core:1.0.0'
- androidTestImplementation 'androidx.test:rules:1.1.0'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
- androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
+ androidTestImplementation 'androidx.test:runner:1.1.1'
+ androidTestImplementation 'androidx.test:core:1.1.0'
+ androidTestImplementation 'androidx.test:rules:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation "android.arch.persistence.room:testing:1.1.1"
// android-job
implementation 'com.evernote:android-job:1.2.6'
+
+ // new camera view: https://github.com/natario1/CameraView
+ implementation 'com.otaliastudios:cameraview:2.0.0-beta02'
}
diff --git a/src/main/java/org/havenapp/main/sensors/motion/CameraViewHolder.java b/src/main/java/org/havenapp/main/sensors/motion/CameraViewHolder.java
index 3baf74b..51fe280 100644
--- a/src/main/java/org/havenapp/main/sensors/motion/CameraViewHolder.java
+++ b/src/main/java/org/havenapp/main/sensors/motion/CameraViewHolder.java
@@ -25,7 +25,11 @@ import android.os.RemoteException;
import android.util.Log;
import android.view.Surface;
-import com.google.android.cameraview.CameraView;
+import com.otaliastudios.cameraview.CameraView;
+import com.otaliastudios.cameraview.Facing;
+import com.otaliastudios.cameraview.Frame;
+import com.otaliastudios.cameraview.FrameProcessor;
+import com.otaliastudios.cameraview.Size;
import org.havenapp.main.PreferenceManager;
import org.havenapp.main.Utils;
@@ -46,6 +50,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import androidx.annotation.NonNull;
import androidx.renderscript.RenderScript;
import io.github.silvaren.easyrs.tools.Nv21Image;
@@ -202,28 +207,37 @@ public class CameraViewHolder {
* (preferred is 640x480)
* in order to minimize CPU usage
*/
- public synchronized void startCamera() {
+ public void startCamera() {
updateCamera();
- cameraView.start();
+ cameraView.open();
- cameraView.setOnFrameListener((data, width, height, rotationDegrees) -> {
+ cameraView.addFrameProcessor(new FrameProcessor() {
+ @Override
+ public void process(@NonNull Frame frame) {
- long now = System.currentTimeMillis();
- if (now < CameraViewHolder.this.lastTimestamp + PREVIEW_INTERVAL)
- return;
+ long now = System.currentTimeMillis();
+ if (now < CameraViewHolder.this.lastTimestamp + PREVIEW_INTERVAL)
+ return;
- CameraViewHolder.this.lastTimestamp = now;
+ CameraViewHolder.this.lastTimestamp = now;
- if (!doingVideoProcessing) {
+ if (frame.getData() != null && frame.getSize() != null) {
- Log.i("CameraViewHolder", "Processing new image");
+ byte[] data = frame.getData();
+ Size size = frame.getSize();
+ int width = size.getWidth();
+ int height = size.getHeight();
+ int rot = getCorrectCameraOrientation(cameraView.getFacing(),frame.getRotation());
- mDecodeThreadPool.execute(() -> processNewFrame(data, width, height, rotationDegrees));
- } else {
- mEncodeVideoThreadPool.execute(() -> recordNewFrame(data, width, height, rotationDegrees));
+ if (!doingVideoProcessing) {
+ mDecodeThreadPool.execute(() -> processNewFrame(data, width, height, rot));
+ } else {
+ mEncodeVideoThreadPool.execute(() -> recordNewFrame(data, width, height, rot));
+ }
+ }
}
});
@@ -234,12 +248,10 @@ public class CameraViewHolder {
{
switch (prefs.getCamera()) {
case PreferenceManager.FRONT:
- if (cameraView.getFacing() != CameraView.FACING_FRONT)
- cameraView.setFacing(CameraView.FACING_FRONT);
+ cameraView.setFacing(Facing.FRONT);
break;
case PreferenceManager.BACK:
- if (cameraView.getFacing() != CameraView.FACING_BACK)
- cameraView.setFacing(CameraView.FACING_BACK);
+ cameraView.setFacing(Facing.BACK);
break;
default:
// camera = null;
@@ -321,8 +333,8 @@ public class CameraViewHolder {
data,
width,
height,
- cameraView.getDefaultOrientation(),
- cameraView.getFacing());
+ rotationDegrees,
+ cameraView.getFacing()==Facing.FRONT);
lastPic = data;
@@ -349,12 +361,12 @@ public class CameraViewHolder {
mtxVideoRotate = new Matrix();
- if (cameraView.getFacing() == CameraView.FACING_FRONT) {
- mtxVideoRotate.postRotate(-cameraView.getDefaultOrientation());
+ if (cameraView.getFacing() == Facing.FRONT) {
+ mtxVideoRotate.postRotate(-cameraView.getRotation());
mtxVideoRotate.postScale(-1, 1, cameraView.getWidth() / 2, cameraView.getHeight() / 2);
}
else
- mtxVideoRotate.postRotate(cameraView.getDefaultOrientation());
+ mtxVideoRotate.postRotate(cameraView.getRotation());
doingVideoProcessing = true;
@@ -374,13 +386,10 @@ public class CameraViewHolder {
public synchronized void stopCamera ()
{
if (cameraView != null) {
- cameraView.stop();
+ cameraView.close();
}
}
- public int getCameraFacing() {
- return cameraView.getFacing();
- }
public void destroy ()
{
@@ -391,7 +400,7 @@ public class CameraViewHolder {
stopCamera();
}
- public int getCorrectCameraOrientation(int facing, int orientation) {
+ public int getCorrectCameraOrientation(Facing facing, int orientation) {
int rotation = context.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
@@ -416,7 +425,7 @@ public class CameraViewHolder {
}
int result;
- if(facing == CameraView.FACING_FRONT){
+ if(facing == Facing.FRONT){
result = (orientation + degrees) % 360;
result = (360 - result) % 360;
}else{
diff --git a/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java b/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
index 0fdac73..6dbf8dd 100644
--- a/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
+++ b/src/main/java/org/havenapp/main/sensors/motion/MotionDetector.java
@@ -12,7 +12,6 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Handler;
-import com.google.android.cameraview.CameraView;
import org.havenapp.main.sensors.media.ImageCodec;
@@ -84,7 +83,7 @@ public class MotionDetector {
int width,
int height,
int rotationDegrees,
- int cameraFacing) {
+ boolean facingFront) {
int[] newPicLuma = ImageCodec.N21toLuma(rawNewPic, width, height);
if (rawOldPic != null) {
@@ -118,7 +117,7 @@ public class MotionDetector {
Matrix mtx = new Matrix();
- if (cameraFacing == CameraView.FACING_FRONT) {
+ if (facingFront) {
mtx.postRotate(-rotationDegrees);
mtx.postScale(-1, 1, width / 2, height / 2);
}
diff --git a/src/main/java/org/havenapp/main/ui/CameraFragment.java b/src/main/java/org/havenapp/main/ui/CameraFragment.java
index 90698b8..b60dd5b 100644
--- a/src/main/java/org/havenapp/main/ui/CameraFragment.java
+++ b/src/main/java/org/havenapp/main/ui/CameraFragment.java
@@ -16,7 +16,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
-import com.google.android.cameraview.CameraView;
+import com.otaliastudios.cameraview.CameraView;
import org.havenapp.main.PreferenceManager;
import org.havenapp.main.R;
@@ -84,13 +84,6 @@ public final class CameraFragment extends Fragment {
}
}
- /**
- public void resetCamera ()
- {
- stopCamera();
- initCamera();
- }**/
-
public void initCamera ()
{
diff --git a/src/main/res/layout/camera_fragment.xml b/src/main/res/layout/camera_fragment.xml
index 083abd9..12a6711 100644
--- a/src/main/res/layout/camera_fragment.xml
+++ b/src/main/res/layout/camera_fragment.xml
@@ -5,7 +5,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:foreground="@color/translucentOverlay25">
- <com.google.android.cameraview.CameraView
+ <!--
+ <com.google.android.cameraview.CameraView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -18,7 +19,27 @@
app:flash="off"
app:maximumWidth="1080"
app:maximumPreviewWidth="1080"
- app:useHighResPicture="false"/>
+ app:useHighResPicture="false"/>-->
+
+ <!-- Camera -->
+ <com.otaliastudios.cameraview.CameraView
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/camera_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:keepScreenOn="true"
+ app:cameraExperimental="true"
+ app:cameraPlaySounds="false"
+ app:cameraGrid="off"
+ app:cameraFlash="off"
+ app:cameraAudio="on"
+ app:cameraGestureTap="none"
+ app:cameraGestureLongTap="none"
+ app:cameraGesturePinch="none"
+ app:cameraGestureScrollHorizontal="none"
+ app:cameraGestureScrollVertical="none"
+ app:cameraMode="picture" />
<ImageView
android:id="@+id/new_image"