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" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="192.168.1.45:42069" />
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Nexus_5_API_21.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-02-15T07:59:24.141496Z" />
<timeTargetWasSelectedWithDropDown value="2023-02-21T07:28:02.087325Z" />
</component>
</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)
## 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
defaultConfig {
applicationId "it.danieleverducci.ojo.googleplay"
applicationId "it.danieleverducci.ojo"
minSdkVersion 21
targetSdkVersion 33
versionCode 6

View File

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

View File

@ -1,11 +1,13 @@
package it.danieleverducci.ojo.ui;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.WindowManager;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
@ -26,6 +28,14 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle 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);
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.ViewTreeObserver;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager;
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 org.videolan.libvlc.IVLCVout;
@ -26,6 +28,7 @@ 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;
@ -87,24 +90,7 @@ public class SurveillanceFragment extends Fragment {
public void onResume() {
super.onResume();
// Leanback mode (fullscreen)
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);
}
}
leanbackMode(true);
fullscreenCameraView = false;
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
public void onPause() {
super.onPause();
// Disable Leanback mode (fullscreen)
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);
}
}
leanbackMode(false);
disposeAllCameras();
}

View File

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