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

Add Picture-in-Picture support to keep the camera alive in the background

n8fr8b1b6d94e053b
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 8b11ebe..10d6566 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -64,10 +64,14 @@
android:screenOrientation="portrait" />
<activity
android:name=".MonitorActivity"
- android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
- android:launchMode="singleTop" />
+ android:launchMode="singleTop"
+ android:resizeableActivity="true"
+ android:supportsPictureInPicture="true"
+ android:configChanges=
+ "screenSize|smallestScreenSize|screenLayout|orientation"
+ />
<activity
android:name=".ui.VideoPlayerActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
diff --git a/src/main/java/org/havenapp/main/MonitorActivity.java b/src/main/java/org/havenapp/main/MonitorActivity.java
index a454169..7ed845e 100644
--- a/src/main/java/org/havenapp/main/MonitorActivity.java
+++ b/src/main/java/org/havenapp/main/MonitorActivity.java
@@ -19,6 +19,8 @@ package org.havenapp.main;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.content.res.Configuration;
+import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
@@ -209,6 +211,18 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
}
+ @Override
+ public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) {
+ if (isInPictureInPictureMode) {
+ // Hide the full-screen UI (controls, etc.) while in picture-in-picture mode.
+ findViewById(R.id.buttonBar).setVisibility(View.GONE);
+ } else {
+ // Restore the full-screen UI.
+ findViewById(R.id.buttonBar).setVisibility(View.VISIBLE);
+
+ }
+ }
+
private void showSettings() {
Intent i = new Intent(this, SettingsActivity.class);
@@ -288,21 +302,36 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
}
- /**
- * Closes the monitor activity and unset session properties
- */
- private void close() {
-
- finish();
+ @Override
+ public void onUserLeaveHint () {
+ if (mIsMonitoring) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ enterPictureInPictureMode();
+ }
+ }
}
-
/**
* When user closes the activity
*/
@Override
public void onBackPressed() {
- close();
+
+ if (mIsMonitoring) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ enterPictureInPictureMode();
+ }
+ else
+ {
+ finish();
+ }
+ }
+ else
+ {
+ finish();
+ }
+
+
}
private void showTimeDelayDialog() {
diff --git a/src/main/res/layout/activity_monitor.xml b/src/main/res/layout/activity_monitor.xml
index d4de969..9d58e9f 100644
--- a/src/main/res/layout/activity_monitor.xml
+++ b/src/main/res/layout/activity_monitor.xml
@@ -72,6 +72,7 @@
android:layout_height="match_parent"
android:gravity="center_horizontal|bottom"
android:orientation="horizontal"
+ android:id="@+id/buttonBar"
android:padding="10dp">
<ImageView