3 Commits

Author SHA1 Message Date
448ff4d2b3 v0.0.2 2021-10-14 16:57:17 +02:00
82810f06e1 Fixed navigation 2021-10-14 16:54:59 +02:00
d207b78065 Working zoom 2021-10-14 16:44:28 +02:00
4 changed files with 68 additions and 30 deletions

View File

@ -10,8 +10,8 @@ android {
applicationId "it.danieleverducci.ojo" applicationId "it.danieleverducci.ojo"
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 30 targetSdkVersion 30
versionCode 1 versionCode 2
versionName "0.0.1" versionName "0.0.2"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true

View File

@ -0,0 +1,18 @@
{
"version": 2,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "it.danieleverducci.ojo",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 1,
"versionName": "0.0.1",
"outputFile": "app-release.apk"
}
]
}

View File

@ -57,7 +57,7 @@ public class AddStreamFragment extends Fragment {
// Back to first fragment // Back to first fragment
NavHostFragment.findNavController(AddStreamFragment.this) NavHostFragment.findNavController(AddStreamFragment.this)
.navigate(R.id.action_SecondFragment_to_FirstFragment); .popBackStack();
} }
}); });
} }

View File

@ -52,14 +52,31 @@ public class SurveillanceFragment extends Fragment {
private FragmentSurveillanceBinding binding; private FragmentSurveillanceBinding binding;
private List<CameraView> cameraViews = new ArrayList<>(); private List<CameraView> cameraViews = new ArrayList<>();
int viewMargin; private boolean fullscreenCameraView = false;
private LinearLayout.LayoutParams cameraViewLayoutParams;
private LinearLayout.LayoutParams rowLayoutParams;
private LinearLayout.LayoutParams hiddenLayoutParams;
@Override @Override
public View onCreateView( public View onCreateView(
LayoutInflater inflater, ViewGroup container, LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState Bundle savedInstanceState
) { ) {
viewMargin = DpiUtils.DpToPixels(container.getContext(), 2); int viewMargin = DpiUtils.DpToPixels(container.getContext(), 2);
cameraViewLayoutParams = new LinearLayout.LayoutParams(
0,
LinearLayout.LayoutParams.MATCH_PARENT,
1.0f
);
cameraViewLayoutParams.setMargins(viewMargin,viewMargin,viewMargin,viewMargin);
rowLayoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1.0f
);
hiddenLayoutParams = new LinearLayout.LayoutParams(0, 0);
binding = FragmentSurveillanceBinding.inflate(inflater, container, false); binding = FragmentSurveillanceBinding.inflate(inflater, container, false);
return binding.getRoot(); return binding.getRoot();
@ -114,29 +131,30 @@ public class SurveillanceFragment extends Fragment {
for (int r = 0; r < elemsPerSide; r++) { for (int r = 0; r < elemsPerSide; r++) {
// Create row and add to row container // Create row and add to row container
LinearLayout row = new LinearLayout(getContext()); LinearLayout row = new LinearLayout(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( binding.gridRowContainer.addView(row, rowLayoutParams);
LinearLayout.LayoutParams.MATCH_PARENT,
0,
1.0f
);
binding.gridRowContainer.addView(row, params);
// Add camera viewers to the row // Add camera viewers to the row
for (int c = 0; c < elemsPerSide; c++) { for (int c = 0; c < elemsPerSide; c++) {
if ( camIdx < cc.size() ) { if ( camIdx < cc.size() ) {
Camera cam = cc.get(camIdx); Camera cam = cc.get(camIdx);
CameraView cv = addCameraView(cam, row); CameraView cv = addCameraView(cam, row);
cv.startPlayback(); cv.startPlayback();
cv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toggle single/multi camera views
fullscreenCameraView = !fullscreenCameraView;
if (fullscreenCameraView) {
hideAllCameraViewsButNot(v);
} else {
showAllCameras();
}
}
});
} else { } else {
// Cameras are less than the maximum number of cells in grid: fill remaining cells with empty views // Cameras are less than the maximum number of cells in grid: fill remaining cells with empty views
View ev = new View(getContext()); View ev = new View(getContext());
ev.setBackgroundColor(getResources().getColor(R.color.purple_700)); ev.setBackgroundColor(getResources().getColor(R.color.purple_700));
LinearLayout.LayoutParams evParams = new LinearLayout.LayoutParams( row.addView(ev, cameraViewLayoutParams);
0,
LinearLayout.LayoutParams.MATCH_PARENT,
1.0f
);
evParams.setMargins(viewMargin,viewMargin,viewMargin,viewMargin);
row.addView(ev, evParams);
} }
camIdx++; camIdx++;
} }
@ -156,22 +174,26 @@ public class SurveillanceFragment extends Fragment {
protected void hideAllCameraViewsButNot(View cameraView) { protected void hideAllCameraViewsButNot(View cameraView) {
for (int i = 0; i < binding.gridRowContainer.getChildCount(); i++) { for (int i = 0; i < binding.gridRowContainer.getChildCount(); i++) {
LinearLayout row = (LinearLayout) binding.gridRowContainer.getChildAt(i); LinearLayout row = (LinearLayout) binding.gridRowContainer.getChildAt(i);
boolean emptyRow = true;
for (int j = 0; j < row.getChildCount(); j++) { for (int j = 0; j < row.getChildCount(); j++) {
View cam = row.getChildAt(j); View cam = row.getChildAt(j);
if (cameraView.getId() == cam.getId()) if (cameraView == cam)
cam.setVisibility(View.VISIBLE); emptyRow = false;
else else
cam.setVisibility(View.GONE); cam.setLayoutParams(hiddenLayoutParams);
} }
if (emptyRow)
row.setLayoutParams(hiddenLayoutParams);
} }
} }
protected void showAllCameras() { protected void showAllCameras() {
for (int i = 0; i < binding.gridRowContainer.getChildCount(); i++) { for (int i = 0; i < binding.gridRowContainer.getChildCount(); i++) {
LinearLayout row = (LinearLayout) binding.gridRowContainer.getChildAt(i); LinearLayout row = (LinearLayout) binding.gridRowContainer.getChildAt(i);
row.setLayoutParams(rowLayoutParams);
for (int j = 0; j < row.getChildCount(); j++) { for (int j = 0; j < row.getChildCount(); j++) {
View cam = row.getChildAt(j); View cam = row.getChildAt(j);
cam.setVisibility(View.VISIBLE); cam.setLayoutParams(cameraViewLayoutParams);
} }
} }
} }
@ -183,13 +205,7 @@ public class SurveillanceFragment extends Fragment {
); );
// Add to layout // Add to layout
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( rowContainer.addView(cv.surfaceView, cameraViewLayoutParams);
0,
LinearLayout.LayoutParams.MATCH_PARENT,
1.0f
);
params.setMargins(viewMargin,viewMargin,viewMargin,viewMargin);
rowContainer.addView(cv.surfaceView, params);
cameraViews.add(cv); cameraViews.add(cv);
return cv; return cv;
@ -223,7 +239,7 @@ public class SurveillanceFragment extends Fragment {
surfaceView.setOnClickListener(new View.OnClickListener() { surfaceView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
SurveillanceFragment.this.hideAllCameraViewsButNot(v);
} }
}); });
SurfaceHolder holder = surfaceView.getHolder(); SurfaceHolder holder = surfaceView.getHolder();
@ -250,6 +266,10 @@ public class SurveillanceFragment extends Fragment {
}); });
} }
public void setOnClickListener(View.OnClickListener listener) {
surfaceView.setOnClickListener(listener);
}
/** /**
* Starts the playback. * Starts the playback.
*/ */