From 23535448a55beb2dacd423cc197105a58424e13c Mon Sep 17 00:00:00 2001 From: free-bots Date: Thu, 8 Feb 2024 17:21:11 +0100 Subject: [PATCH] added intent for direct camera access and leanback support --- app/src/main/AndroidManifest.xml | 12 +++++- .../ojo/ui/SurveillanceFragment.java | 42 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 09aae44..ec00221 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,11 @@ - + + @@ -25,12 +30,17 @@ + + + + + diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java b/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java index ba5fa14..d072be9 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java @@ -1,6 +1,7 @@ package it.danieleverducci.ojo.ui; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -28,7 +29,6 @@ import org.videolan.libvlc.MediaPlayer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; import it.danieleverducci.ojo.R; import it.danieleverducci.ojo.Settings; @@ -100,6 +100,8 @@ public class SurveillanceFragment extends Fragment { cv.startPlayback(); } + expandToCameraViewIfRequired(); + // Register for back pressed events ((MainActivity)getActivity()).setOnBackButtonPressedListener(new OnBackButtonPressedListener() { @Override @@ -256,6 +258,44 @@ public class SurveillanceFragment extends Fragment { return dimensions; } + private void expandToCameraViewIfRequired() { + final String EXTRA_CAMERA_NUMBER = "it.danieleverducci.ojo.CAMERA_NUMBER"; + final String EXTRA_CAMERA_NAME = "it.danieleverducci.ojo.CAMERA_NAME"; + final String OPEN_CAMERA = "it.danieleverducci.ojo.OPEN_CAMERA"; + + if (this.getActivity() == null) { + return; + } + + Intent intent = this.getActivity().getIntent(); + + if (OPEN_CAMERA.equals(intent.getAction())) { + String cameraName = intent.getStringExtra(EXTRA_CAMERA_NAME); + if (cameraName == null) { + int cameraNumber = intent.getIntExtra(EXTRA_CAMERA_NUMBER, 0) - 1; + expandByIndex(cameraNumber); + return; + } + expandByName(cameraName); + } + } + + private void expandByIndex(int index) { + if (index < 0 || cameraViews.size() <= index) { + return; + } + hideAllCameraViewsButNot(cameraViews.get(index).surfaceView); + } + + private void expandByName(String name) { + for(CameraView cameraView: cameraViews) { + if (cameraView.camera.getName().equals(name)) { + hideAllCameraViewsButNot(cameraView.surfaceView); + break; + } + } + } + /** * Contains all entities (views and java entities) related to a camera stream viewer */