Merge pull request #32 from free-bots/feature/intent

added intent for direct camera access and leanback support
This commit is contained in:
Daniele Verducci 2024-02-10 10:19:55 +01:00 committed by GitHub
commit 96a91a6c3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 2 deletions

View File

@ -14,6 +14,17 @@ The maximum number of cameras is determined by the device's capabilities.
The stream decoding and rendering is demanded to [VLC's library](https://code.videolan.org/videolan/vlc-android): without their effort this app wouldn't be possible.
This app was specifically developed for F-Droid, as I couldn't find any open source RTSP vievers in the main repository.
The app can be opened deeplinking to url ojo://view.
To open the app with focus on a specific camera, you can use an intent (it.danieleverducci.ojo.OPEN_CAMERA) to specify which camera you want to view.
The extra argument it.danieleverducci.ojo.CAMERA_NAME will open the app with the camera with the name you specified while adding the camera.
The extra argument it.danieleverducci.ojo.CAMERA_NUMBER starting at 1 could be used as well, if you have multiple cameras with the same name.
See belows example how to use the intent. The flag (-f 268468224) could be useful if you want to switch to an other camera while the app is running.
```shell
adb -s <YOUR_DEVICE> shell am start -a it.danieleverducci.ojo.OPEN_CAMERA -f 268468224 --es it.danieleverducci.ojo.CAMERA_NAME <YOUR_CAMERA_NAME>
adb -s <YOUR_DEVICE> shell am start -a it.danieleverducci.ojo.OPEN_CAMERA -f 268468224 --es it.danieleverducci.ojo.CAMERA_NUMBER <YOUR_CAMERA_NUMBER>
```
![Screenshot 1](media/screenshots/1.png) ![Screenshot 2](media/screenshots/2.png) ![Screenshot 3](media/screenshots/3.png)
## Contributors

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />
<application
android:allowBackup="true"
@ -12,6 +16,7 @@
android:theme="@style/Theme.Ojo">
<activity
android:name=".ui.SettingsActivity"
android:banner="@mipmap/ic_launcher"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Ojo">
@ -25,12 +30,17 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="ojo" android:host="view"/>
</intent-filter>
<intent-filter>
<action android:name="it.danieleverducci.ojo.OPEN_CAMERA"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>

View File

@ -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
*/

View File

@ -6,3 +6,9 @@ The stream decoding and rendering is demanded to VLC's library: without their ef
This app was specifically developed for F-Droid, as I couldn't find any open source RTSP vievers in the main repository.
The app can be opened deeplinking to url ojo://view
To open the app with focus on a specific camera, you can use an intent (it.danieleverducci.ojo.OPEN_CAMERA) to specify which camera you want to view.
The extra argument it.danieleverducci.ojo.CAMERA_NAME will open the app with the camera with the name you specified while adding the camera.
The extra argument it.danieleverducci.ojo.CAMERA_NUMBER starting at 1 could be used as well, if you have multiple cameras with the same name.
See belows example how to use the intent. The flag (-f 268468224) could be useful if you want to switch to an other camera while the app is running.
adb -s <YOUR_DEVICE> shell am start -a it.danieleverducci.ojo.OPEN_CAMERA -f 268468224 --es it.danieleverducci.ojo.CAMERA_NAME <YOUR_CAMERA_NAME>
adb -s <YOUR_DEVICE> shell am start -a it.danieleverducci.ojo.OPEN_CAMERA -f 268468224 --es it.danieleverducci.ojo.CAMERA_NUMBER <YOUR_CAMERA_NUMBER>