Fixed back button exiting from app in full screen mode

This commit is contained in:
Daniele Verducci (Slimpenguin) 2022-02-02 09:16:47 +01:00
parent a750dbbb00
commit 559c831d08
3 changed files with 32 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
@ -21,6 +22,7 @@ public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private NavController navController;
private boolean rotationEnabledSetting;
private OnBackButtonPressedListener onBackButtonPressedListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -49,6 +51,17 @@ public class MainActivity extends AppCompatActivity {
});
}
public void setOnBackButtonPressedListener(OnBackButtonPressedListener onBackButtonPressedListener) {
this.onBackButtonPressedListener = onBackButtonPressedListener;
}
@Override
public void onBackPressed() {
if (this.onBackButtonPressedListener != null && this.onBackButtonPressedListener.onBackPressed())
return;
super.onBackPressed();
}
public void navigateToFragment(int actionId) {
navigateToFragment(actionId, null);
}

View File

@ -0,0 +1,5 @@
package it.danieleverducci.ojo.ui;
public interface OnBackButtonPressedListener {
public boolean onBackPressed();
}

View File

@ -80,7 +80,6 @@ public class SurveillanceFragment extends Fragment {
binding = FragmentSurveillanceBinding.inflate(inflater, container, false);
return binding.getRoot();
}
@Override
@ -106,12 +105,26 @@ public class SurveillanceFragment extends Fragment {
}
}
fullscreenCameraView = false;
addAllCameras();
// Start playback for all streams
for (CameraView cv : cameraViews) {
cv.startPlayback();
}
// Register for back pressed events
((MainActivity)getActivity()).setOnBackButtonPressedListener(new OnBackButtonPressedListener() {
@Override
public boolean onBackPressed() {
if(fullscreenCameraView && cameraViews.size() > 1) {
fullscreenCameraView = false;
showAllCameras();
return true;
}
return false;
}
});
}
@Override