True fullscreen under notches

This commit is contained in:
Daniele Verducci (Slimpenguin) 2023-02-17 09:22:53 +01:00
parent 66d0a1081a
commit d3cb5abe27
7 changed files with 69 additions and 44 deletions

View File

@ -6,12 +6,12 @@
<type value="RUNNING_DEVICE_TARGET" /> <type value="RUNNING_DEVICE_TARGET" />
<deviceKey> <deviceKey>
<Key> <Key>
<type value="SERIAL_NUMBER" /> <type value="VIRTUAL_DEVICE_PATH" />
<value value="192.168.1.45:42069" /> <value value="$USER_HOME$/.android/avd/Nexus_5_API_21.avd" />
</Key> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</runningDeviceTargetSelectedWithDropDown> </runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-02-15T07:59:24.141496Z" /> <timeTargetWasSelectedWithDropDown value="2023-02-21T07:28:02.087325Z" />
</component> </component>
</project> </project>

View File

@ -16,3 +16,7 @@ This app was specifically developed for F-Droid, as I couldn't find any open sou
![Screenshot 1](media/screenshots/1.png) ![Screenshot 2](media/screenshots/2.png) ![Screenshot 3](media/screenshots/3.png) ![Screenshot 1](media/screenshots/1.png) ![Screenshot 2](media/screenshots/2.png) ![Screenshot 3](media/screenshots/3.png)
## Contributors
Thanks to [brenard](https://github.com/brenard) for the new grid sizing method
Thanks to [davquar](https://github.com/davquar) for the fullscreen compatibility fix on Android 11

View File

@ -6,7 +6,7 @@ android {
compileSdkVersion 33 compileSdkVersion 33
defaultConfig { defaultConfig {
applicationId "it.danieleverducci.ojo.googleplay" applicationId "it.danieleverducci.ojo"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 33 targetSdkVersion 33
versionCode 6 versionCode 6

View File

@ -1,18 +1,20 @@
{ {
"version": 2, "version": 3,
"artifactType": { "artifactType": {
"type": "APK", "type": "APK",
"kind": "Directory" "kind": "Directory"
}, },
"applicationId": "it.danieleverducci.ojo", "applicationId": "it.danieleverducci.ojo.googleplay",
"variantName": "release", "variantName": "release",
"elements": [ "elements": [
{ {
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"versionCode": 4, "attributes": [],
"versionName": "0.1.0", "versionCode": 6,
"versionName": "0.1.1",
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }
] ],
"elementType": "File"
} }

View File

@ -1,11 +1,13 @@
package it.danieleverducci.ojo.ui; package it.danieleverducci.ojo.ui;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.WindowManager;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
@ -26,6 +28,14 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Interface can go below notches
if (Build.VERSION.SDK_INT >= 28) {
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);
}
rotationEnabledSetting = SharedPreferencesManager.loadRotationEnabled(this); rotationEnabledSetting = SharedPreferencesManager.loadRotationEnabled(this);
this.setRequestedOrientation(this.rotationEnabledSetting ? ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); this.setRequestedOrientation(this.rotationEnabledSetting ? ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

View File

@ -12,10 +12,12 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.Window; import android.view.Window;
import android.view.WindowInsets; import android.view.WindowManager;
import android.view.WindowInsetsController;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import org.videolan.libvlc.IVLCVout; import org.videolan.libvlc.IVLCVout;
@ -26,6 +28,7 @@ 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;
@ -87,24 +90,7 @@ public class SurveillanceFragment extends Fragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
// Leanback mode (fullscreen) leanbackMode(true);
Window window = getActivity().getWindow();
if (window != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final WindowInsetsController controller = window.getInsetsController();
if (controller != null)
controller.hide(WindowInsets.Type.statusBars());
} else {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
}
fullscreenCameraView = false; fullscreenCameraView = false;
addAllCameras(); addAllCameras();
@ -128,23 +114,46 @@ public class SurveillanceFragment extends Fragment {
}); });
} }
/**
* Goes fullscreen igoring the device screen insets (camera etc)
*/
private void leanbackMode(boolean leanback) {
Window w = requireActivity().getWindow();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
return;
if (leanback) {
// Iterface can go below notch
/*w.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);*/
w.getAttributes().layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
// Hide system bar
WindowInsetsControllerCompat windowInsetsController = WindowCompat.getInsetsController(w, w.getDecorView());
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
// System bar is hidden when not touched for a while
windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
} else {
// Interface cannot go below notch
/*w.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.getAttributes().layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;*/
// Show system bar
WindowInsetsControllerCompat windowInsetsController = WindowCompat.getInsetsController(w, w.getDecorView());
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
}
}
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
// Disable Leanback mode (fullscreen) leanbackMode(false);
Window window = getActivity().getWindow();
if (window != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final WindowInsetsController controller = window.getInsetsController();
if (controller != null)
controller.show(WindowInsets.Type.statusBars());
} else {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_VISIBLE);
}
}
disposeAllCameras(); disposeAllCameras();
} }

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Ojo" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <style name="Theme.Ojo" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
<!-- Primary brand color. --> <!-- Primary brand color. -->
@ -13,7 +12,8 @@
<item name="colorSecondaryVariant">@color/purple_700</item> <item name="colorSecondaryVariant">@color/purple_700</item>
<item name="colorOnSecondary">@color/black</item> <item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
</style> </style>
</resources> </resources>