Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Recording implementation using CameraX lib #419

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2e94d58
Call cameraview destroy() instead of close() on Fragment onDestroy()
archie94 Apr 21, 2019
9f54d45
Set LifecyclerOwner to the CameraView
archie94 Apr 21, 2019
9ef9908
Set listener to null while canceling task
archie94 Apr 25, 2019
aac0f96
Add LeakCanary dependency
archie94 Apr 26, 2019
99eded9
Keep application context in Signal Sender
archie94 Apr 26, 2019
0a99b02
Remove redundant methods
archie94 Apr 26, 2019
ba89c2d
Update dependencies
archie94 May 5, 2019
e8e972b
Remove Leak Canary dependency
archie94 May 14, 2019
2179d56
Merge branch 'master' of github.com:guardianproject/haven into leak_c…
archie94 Apr 17, 2020
25581c4
Update dependencies
archie94 Apr 16, 2020
8716256
Add leak canary in debug builds
archie94 Apr 17, 2020
b891062
Use HavenCameraView instead of CameraView
archie94 Apr 18, 2020
07b9aa4
Update deps
archie94 Jun 9, 2020
5b09e9f
Adding CameraX dependencies
archie94 Jun 9, 2020
626bdc7
Remove unused codes
archie94 Jun 9, 2020
13944af
Add coroutines lib for concurrent tasks
archie94 Jun 12, 2020
ef6c1a2
Initial implementation using CameraX
archie94 Jun 12, 2020
e8c2825
Enable camera switching + use Events for notifying motion
archie94 Jun 13, 2020
dc0734a
Introduce a detection buffer
archie94 Jun 13, 2020
23e89e6
Introduce Video Monitoring
archie94 Jun 13, 2020
b68e306
Honor video monitoring length
archie94 Jun 17, 2020
492774d
Stop monitoring and close activity after a delay
archie94 Jun 17, 2020
9da31d4
Remove unused code
archie94 Jun 17, 2020
54df268
Set up analyser while configuring camera
archie94 Jun 17, 2020
0593cd7
Camera configuration activity cleanup
archie94 Jun 18, 2020
1c13cea
Code cleanup
archie94 Jun 18, 2020
f09ce95
Annotate methods with thread of execution
archie94 Jun 18, 2020
74e00f2
Version bump
archie94 Jun 28, 2020
67e494b
Simultaneous video monitoring
archie94 Jul 10, 2020
2e096f3
Remove deps
archie94 Jul 11, 2020
edf2f0c
Update dependencies
archie94 Aug 7, 2020
a90c92a
Add more helpers
archie94 Dec 5, 2020
2509938
Add helpers
archie94 Jul 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

Expand Down Expand Up @@ -44,7 +44,7 @@ allprojects {
version_number = getVersionName()
group_info = "haven"
buildToolsVersion = "29.0.2"
minSdkVersion = 16
minSdkVersion = 21
targetSdkVersion = 29
}

Expand All @@ -59,7 +59,7 @@ allprojects {

android {
compileSdkVersion 29
buildToolsVersion = '29.0.2'
buildToolsVersion = '29.0.3'

packagingOptions {
exclude 'META-INF/LICENSE.txt'
Expand All @@ -82,7 +82,7 @@ android {
versionCode 2001
versionName getVersionName()
archivesBaseName = "Haven-$versionName"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 29
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -122,7 +122,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}
Expand All @@ -142,13 +142,13 @@ configurations {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-alpha1'
implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'com.google.android.material:material:1.3.0-alpha04'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.wdullaer:materialdatetimepicker:4.2.3'
implementation 'com.github.guardianproject:signal-cli-android:v0.6.0-android-beta-1'
Expand All @@ -169,29 +169,38 @@ dependencies {
implementation 'com.github.halilozercan:BetterVideoPlayer:1.1.0'
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
implementation 'io.github.silvaren:easyrs:0.5.3'
implementation 'org.jcodec:jcodec:0.2.5'
implementation 'org.jcodec:jcodec-android:0.2.5'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

// Room
implementation "android.arch.persistence.room:runtime:2.1.0"
kapt "android.arch.persistence.room:compiler:2.1.0"
implementation "android.arch.lifecycle:runtime:2.1.0"
implementation "android.arch.lifecycle:extensions:2.1.0"

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0"

testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.3.0'
androidTestImplementation "android.arch.persistence.room:testing:2.1.0"

// android-job
implementation 'com.evernote:android-job:1.4.2'

// new camera view: https://github.com/natario1/CameraView
implementation 'com.otaliastudios:cameraview:2.4.0'
// CameraX core library using camera2 implementation
implementation "androidx.camera:camera-camera2:1.0.0-beta12"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:1.0.0-beta12"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha19"

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.7'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.9'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#Sat Dec 07 05:36:14 EST 2019
#Fri Dec 04 23:39:04 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-rc-3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
android.useAndroidX=true
android.enableD8=true
60 changes: 32 additions & 28 deletions src/main/java/org/havenapp/main/MonitorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package org.havenapp.main;

import android.Manifest;
import android.animation.ValueAnimator;
import android.app.PictureInPictureParams;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
Expand All @@ -40,7 +39,11 @@
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;

Expand All @@ -55,11 +58,6 @@
import java.io.FileOutputStream;
import java.io.IOException;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import static org.havenapp.main.Utils.getTimerText;

public class MonitorActivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener {
Expand All @@ -83,6 +81,8 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
private Animation mAnimShake;
private TextView txtStatus;

private ProgressDialog progressDialog;

private int lastEventType = -1;

/**
Expand Down Expand Up @@ -134,11 +134,14 @@ public void handleMessage(Message msg) {
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

int eventType = intent.getIntExtra("type",-1);
boolean detected = intent.getBooleanExtra("detected",true);
if (detected)
handler.sendEmptyMessage(eventType);
if (eventType == MonitorService.MSG_STOP_SELF) {
notifyMonitoringEnded();
} else {
boolean detected = intent.getBooleanExtra("detected", true);
if (detected)
handler.sendEmptyMessage(eventType);
}
}
};

Expand Down Expand Up @@ -177,8 +180,7 @@ private void initSetupLayout() {
preferences = new PreferenceManager(getApplicationContext());
setContentView(R.layout.activity_monitor);

txtTimer = (TextView) findViewById(R.id.timer_text);
View viewTimer = findViewById(R.id.timer_container);
txtTimer = findViewById(R.id.timer_text);

int timeM = preferences.getTimerDelay() * 1000;

Expand Down Expand Up @@ -233,8 +235,6 @@ private void initSetupLayout() {
}

private void configCamera() {

mFragmentCamera.stopCamera();
startActivityForResult(new Intent(this, CameraConfigureActivity.class),REQUEST_CAMERA);
}

Expand All @@ -259,8 +259,8 @@ private void doCancel() {

if (mIsMonitoring) {
mIsMonitoring = false;
stopService(new Intent(this, MonitorService.class));
finish();
showAlertDialog();
mFragmentCamera.stopMonitoring();
} else {

findViewById(R.id.btnStartNow).setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -313,17 +313,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
else if (requestCode == REQUEST_CAMERA)
{
mFragmentCamera.initCamera();
}
}

@Override
protected void onDestroy() {
if (!mIsMonitoring)
{
mFragmentCamera.stopCamera();
// mFragmentCamera.initCamera();
}
super.onDestroy();
}

private void initTimer() {
Expand Down Expand Up @@ -475,4 +466,17 @@ public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int seco
updateTimerValue(delaySeconds);
}

private void showAlertDialog() {
progressDialog = new ProgressDialog(this);
progressDialog.setMessage(getString(R.string.finishing_up));
progressDialog.setCancelable(false);
progressDialog.show();
}

private void notifyMonitoringEnded() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
finish();
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/havenapp/main/PreferenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.appcompat.app.AppCompatActivity;

import org.havenapp.main.sensors.motion.LuminanceMotionDetector;
import org.havenapp.main.storage.SharedPreferenceStringLiveData;

import java.io.File;
import java.util.Date;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class PreferenceManager {
public static final String VERIFY_SIGNAL = "verify_signal";
public static final String VOICE_VERIFY_SIGNAL = "voice_verify_signal";
public static final String RESET_SIGNAL_CONFIG = "reset_signal_config";
public static final String SIMULTANEOUS_IMAGE_MONITORING = "simultaneous_image_monitoring";
private static final String UNLOCK_CODE="unlock_code";

private static final String ACCESS_TOKEN="access_token";
Expand Down Expand Up @@ -237,6 +239,15 @@ public boolean getVideoMonitoringActive() {
return appSharedPrefs.getBoolean(context.getResources().getString(R.string.video_active_preference_key), false);
}

public void setSimultaneousImageMonitoring(boolean active) {
prefsEditor.putBoolean(SIMULTANEOUS_IMAGE_MONITORING, active);
prefsEditor.commit();
}

public boolean isSimultaneousImageMonitoring() {
return appSharedPrefs.getBoolean(SIMULTANEOUS_IMAGE_MONITORING, false);
}

public void activateCamera(boolean active) {
prefsEditor.putBoolean(CAMERA_ACTIVE, active);
prefsEditor.commit();
Expand All @@ -254,6 +265,11 @@ public void setCamera(String camera) {
public String getCamera() {
return appSharedPrefs.getString(CAMERA, FRONT);
}

@NonNull
public SharedPreferenceStringLiveData getCameraLiveData() {
return new SharedPreferenceStringLiveData(appSharedPrefs, CAMERA, FRONT);
}

public void setCameraSensitivity(int sensitivity) {
prefsEditor.putInt(CAMERA_SENSITIVITY, sensitivity);
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/org/havenapp/main/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
Expand All @@ -25,6 +24,17 @@
import android.widget.Switch;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;

import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;

Expand All @@ -38,16 +48,6 @@
import java.io.File;
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import info.guardianproject.netcipher.proxy.OrbotHelper;


Expand Down Expand Up @@ -309,6 +309,11 @@ protected void save() {

preferences.setActivateVideoMonitoring(videoMonitoringActive);

boolean simultaneousImageMonitoring = ((SwitchPreference) findPreference(
PreferenceManager.SIMULTANEOUS_IMAGE_MONITORING)).isChecked();

preferences.setSimultaneousImageMonitoring(simultaneousImageMonitoring);

boolean remoteNotificationActive =
((SwitchPreference) findPreference(PreferenceManager.REMOTE_NOTIFICATION_ACTIVE)).isChecked();
preferences.setRemoteNotificationActive(remoteNotificationActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void stop (Context context)
{
context.unbindService(mConnection);
if (microphone != null)
microphone.cancel(true);
microphone.cancelTask();
}


Expand Down
Loading