From 121e7835d0f0cf5e7e6241077cd4819355957032 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 14 Jul 2022 18:22:17 +0600 Subject: [PATCH 1/2] 5664-continuous_burst_mode_not_stopping_issue issue: https://gitlab.e.foundation/e/backlog/-/issues/5664 When user long press capture button & start continuousBrustMode & remove touch before cameraController start taking image, causes unwanted behavior where burstMode doesn't stop. Here when user remove the touch should_run_continuous_fast_burst is maintained. When 1 burst image is taken an event is passed EventBus to the MainActivity. On listening the event, the flag is checked & burstMode stop called if necessary. --- app/build.gradle | 1 + .../ContinuousBurstImageRunningAction.java | 20 ++++++++++++++ .../sourceforge/opencamera/MainActivity.java | 26 ++++++++++++++++++- .../cameracontroller/CameraController2.java | 6 +++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/net/sourceforge/opencamera/ContinuousBurstImageRunningAction.java diff --git a/app/build.gradle b/app/build.gradle index 0902d363c..a74a36609 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,5 +57,6 @@ dependencies { //noinspection GradleCompatible implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation "androidx.constraintlayout:constraintlayout:2.1.3" + implementation "org.greenrobot:eventbus:3.3.1" testImplementation 'junit:junit:4.13' } diff --git a/app/src/main/java/net/sourceforge/opencamera/ContinuousBurstImageRunningAction.java b/app/src/main/java/net/sourceforge/opencamera/ContinuousBurstImageRunningAction.java new file mode 100644 index 000000000..0c7f5b36e --- /dev/null +++ b/app/src/main/java/net/sourceforge/opencamera/ContinuousBurstImageRunningAction.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2022 E FOUNDATION + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.sourceforge.opencamera; + +public class ContinuousBurstImageRunningAction { +} diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index d71461520..b465020e0 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -77,6 +77,10 @@ import net.sourceforge.opencamera.ui.FolderChooserDialog; import net.sourceforge.opencamera.ui.MainUI; import net.sourceforge.opencamera.ui.ManualSeekbars; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -130,6 +134,7 @@ public class MainActivity extends Activity { private final Map preloaded_bitmap_resources = new HashMap<>(); private ValueAnimator gallery_save_anim; private boolean last_continuous_fast_burst; // whether the last photo operation was a continuous_fast_burst + private boolean should_run_continuous_fast_burst = false; private TextToSpeech textToSpeech; private boolean textToSpeechSuccess; @@ -637,6 +642,12 @@ public class MainActivity extends Activity { Log.d(TAG, "onCreate: total time for Activity startup: " + (System.currentTimeMillis() - debug_time)); } + @Override + protected void onStart() { + super.onStart(); + EventBus.getDefault().register(this); + } + /** * if navigationMode is no gesture, then retrieve navigationBar's height & update navigation_gap */ @@ -971,6 +982,7 @@ public class MainActivity extends Activity { if( MyDebug.LOG ) Log.d(TAG, "onStop"); super.onStop(); + EventBus.getDefault().unregister(this); // we stop location listening in onPause, but done here again just to be certain! applicationInterface.getLocationSupplier().freeLocationListeners(); @@ -3822,6 +3834,7 @@ public class MainActivity extends Activity { closePopup(); this.last_continuous_fast_burst = continuous_fast_burst; + this.should_run_continuous_fast_burst = continuous_fast_burst; this.preview.takePicturePressed(photo_snapshot, continuous_fast_burst); } @@ -4935,7 +4948,18 @@ public class MainActivity extends Activity { public void takePhotoButtonLongClickCancelled() { if( MyDebug.LOG ) Log.d(TAG, "takePhotoButtonLongClickCancelled"); - if( preview.getCameraController() != null && preview.getCameraController().isContinuousBurstInProgress() ) { + if (preview.getCameraController() == null) { + return; + } + if(preview.getCameraController().isContinuousBurstInProgress() ) { + preview.getCameraController().stopContinuousBurst(); + } + should_run_continuous_fast_burst = false; + } + + @Subscribe(threadMode = ThreadMode.MAIN_ORDERED) + public void onContinuousBurstImageRunningAction(ContinuousBurstImageRunningAction action) { + if (!should_run_continuous_fast_burst && preview.getCameraController() != null && preview.getCameraController().isContinuousBurstInProgress()) { preview.getCameraController().stopContinuousBurst(); } } diff --git a/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController2.java b/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController2.java index 077ed27fa..de98372c7 100644 --- a/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController2.java +++ b/app/src/main/java/net/sourceforge/opencamera/cameracontroller/CameraController2.java @@ -1,5 +1,6 @@ package net.sourceforge.opencamera.cameracontroller; +import net.sourceforge.opencamera.ContinuousBurstImageRunningAction; import net.sourceforge.opencamera.MyDebug; import java.nio.ByteBuffer; @@ -54,6 +55,8 @@ import android.view.Surface; import android.view.SurfaceHolder; import android.view.TextureView; +import org.greenrobot.eventbus.EventBus; + /** Provides support using Android 5's Camera 2 API * android.hardware.camera2.*. */ @@ -1346,6 +1349,9 @@ public class CameraController2 extends CameraController { takePhotoCompleted(); } + if (n_burst_taken == 1) { + EventBus.getDefault().post(new ContinuousBurstImageRunningAction()); + } if( MyDebug.LOG ) Log.d(TAG, "done onImageAvailable"); } -- GitLab From 3182ba1130de8d7f823cde1b4154fe7db64d5b9f Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Fri, 15 Jul 2022 05:26:25 +0000 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) --- app/src/main/java/net/sourceforge/opencamera/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index b465020e0..1c114f63a 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -4951,7 +4951,7 @@ public class MainActivity extends Activity { if (preview.getCameraController() == null) { return; } - if(preview.getCameraController().isContinuousBurstInProgress() ) { + if (preview.getCameraController().isContinuousBurstInProgress()) { preview.getCameraController().stopContinuousBurst(); } should_run_continuous_fast_burst = false; -- GitLab