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 a2c5d0a..2b08d9b 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java @@ -3,6 +3,7 @@ package it.danieleverducci.ojo.ui; import android.content.Context; import android.graphics.Color; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.util.DisplayMetrics; import android.util.Log; @@ -12,9 +13,15 @@ import android.view.SurfaceView; 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.widget.LinearLayout; import androidx.annotation.NonNull; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.view.WindowInsetsControllerCompat; import androidx.fragment.app.Fragment; import androidx.navigation.fragment.NavHostFragment; @@ -31,6 +38,7 @@ import it.danieleverducci.ojo.R; import it.danieleverducci.ojo.Settings; import it.danieleverducci.ojo.databinding.FragmentSurveillanceBinding; import it.danieleverducci.ojo.entities.Camera; +import it.danieleverducci.ojo.utils.DpiUtils; /** * Some streams to test: @@ -98,18 +106,32 @@ public class SurveillanceFragment extends Fragment implements MediaPlayer.EventL camIdx++; } } - - - - - - } @Override public void onStart() { super.onStart(); + // 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); + } + } + + // Start playback for all streams for (CameraView cv : cameraViews) { cv.startPlayback(); } @@ -174,6 +196,8 @@ public class SurveillanceFragment extends Fragment implements MediaPlayer.EventL LinearLayout.LayoutParams.MATCH_PARENT, 1.0f ); + int viewMargin = DpiUtils.DpToPixels(rowContainer.getContext(), 2); + params.setMargins(viewMargin,viewMargin,viewMargin,viewMargin); rowContainer.addView(cv.surfaceView, params); cameraViews.add(cv); diff --git a/app/src/main/java/it/danieleverducci/ojo/utils/DpiUtils.java b/app/src/main/java/it/danieleverducci/ojo/utils/DpiUtils.java new file mode 100644 index 0000000..b2efbdb --- /dev/null +++ b/app/src/main/java/it/danieleverducci/ojo/utils/DpiUtils.java @@ -0,0 +1,16 @@ +package it.danieleverducci.ojo.utils; + +import android.content.Context; +import android.content.res.Resources; +import android.util.TypedValue; + +public class DpiUtils { + public static int DpToPixels(Context context, int dp) { + Resources r = context.getResources(); + return (int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + dp, + r.getDisplayMetrics() + ); + } +} diff --git a/app/src/main/res/layout/fragment_add_stream.xml b/app/src/main/res/layout/fragment_add_stream.xml index 8b2525a..fe9f364 100644 --- a/app/src/main/res/layout/fragment_add_stream.xml +++ b/app/src/main/res/layout/fragment_add_stream.xml @@ -1,26 +1,81 @@ - - -