added intent for direct camera access and leanback support

This commit is contained in:
free-bots 2024-02-08 17:21:11 +01:00
parent 4aa17ec8f3
commit 23535448a5
No known key found for this signature in database
GPG Key ID: 333C776CD83F2877
2 changed files with 52 additions and 2 deletions

View File

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

View File

@ -1,6 +1,7 @@
package it.danieleverducci.ojo.ui; package it.danieleverducci.ojo.ui;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -28,7 +29,6 @@ import org.videolan.libvlc.MediaPlayer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import it.danieleverducci.ojo.R; import it.danieleverducci.ojo.R;
import it.danieleverducci.ojo.Settings; import it.danieleverducci.ojo.Settings;
@ -100,6 +100,8 @@ public class SurveillanceFragment extends Fragment {
cv.startPlayback(); cv.startPlayback();
} }
expandToCameraViewIfRequired();
// Register for back pressed events // Register for back pressed events
((MainActivity)getActivity()).setOnBackButtonPressedListener(new OnBackButtonPressedListener() { ((MainActivity)getActivity()).setOnBackButtonPressedListener(new OnBackButtonPressedListener() {
@Override @Override
@ -256,6 +258,44 @@ public class SurveillanceFragment extends Fragment {
return dimensions; 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 * Contains all entities (views and java entities) related to a camera stream viewer
*/ */