Skip to content

Commit

Permalink
Add Picture-in-Picture support to keep the camera alive in the backgr…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
n8fr8 committed Jul 3, 2018
1 parent 201dccf commit b1b6d94
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 37 additions & 8 deletions src/main/java/org/havenapp/main/MonitorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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;
Expand Down Expand Up @@ -209,6 +211,18 @@ private void doCancel() {

}

@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);
Expand Down Expand Up @@ -288,21 +302,36 @@ private void initMonitor() {

}

/**
* 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() {
Expand Down
1 change: 1 addition & 0 deletions src/main/res/layout/activity_monitor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b1b6d94

Please sign in to comment.