diff --git a/app/build.gradle b/app/build.gradle index 0902d363c272349d327a0cede862bff1fd1ef421..a74a36609789c4a26c2b7c04cc8bb14504f0408f 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 0000000000000000000000000000000000000000..0c7f5b36e3ee6fcc6b7d32d9716946498bdff78a --- /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 d714615201c5d72fd835cf0a8b6b9d6ca1361075..1c114f63a1ad7c1cda29eeab2512f0b67156db67 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 077ed27fa50385826323826518b714c8930ff42d..de98372c7cca56d70f312dd2c2fbb19f0f7f5166 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"); }