Skip to content

Commit ba71f09

Browse files
committed
Update mainOverlay immediately
Since we don't have a concrete position where previewView will appear anymore, we need to ensure that mainOverlay is at the right position and that we hide previewView until it's ready. As a result, I needed to move hiding previewView and showing mainOverlay to the moment where we change the camera configuration. I also needed to make sure that mainOverlay appears at the old y position of previewView. Once that is ready we can simply show previewView once again when we observe StreamingState.STREAMING. This also has a side effect of fixing a small issue where you could see previewView show a broken image for a frame when swapping between aspect ratios.
1 parent ed3748f commit ba71f09

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

app/src/main/java/app/grapheneos/camera/CamConfig.kt

+16-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import app.grapheneos.camera.ui.activities.SecureMainActivity
4848
import app.grapheneos.camera.ui.activities.VideoCaptureActivity
4949
import app.grapheneos.camera.ui.activities.VideoOnlyActivity
5050
import app.grapheneos.camera.util.edit
51+
import app.grapheneos.camera.util.setBlurBitmapCompat
5152
import com.google.android.material.dialog.MaterialAlertDialogBuilder
5253
import com.google.zxing.BarcodeFormat
5354
import java.util.concurrent.ExecutionException
@@ -1049,6 +1050,21 @@ class CamConfig(private val mActivity: MainActivity) {
10491050
fun startCamera(forced: Boolean = false) {
10501051
if ((!forced && camera != null) || cameraProvider == null) return
10511052

1053+
// To use the last frame instead of showing a blank screen when
1054+
// the camera that is being currently used gets unbind
1055+
mActivity.updateLastFrame()
1056+
1057+
if (mActivity.lastFrame != null && mActivity !is CaptureActivity) {
1058+
setBlurBitmapCompat(mActivity.mainOverlay, mActivity.lastFrame!!)
1059+
mActivity.settingsIcon.visibility = View.INVISIBLE
1060+
mActivity.settingsIcon.isEnabled = false
1061+
mActivity.mainOverlay.visibility = View.VISIBLE
1062+
}
1063+
mActivity.previewGrid.visibility = View.INVISIBLE
1064+
mActivity.mainOverlay.y = mActivity.previewView.y
1065+
mActivity.mainOverlay.visibility = View.VISIBLE
1066+
mActivity.previewView.visibility = View.INVISIBLE
1067+
10521068
mActivity.exposureBar.hidePanel()
10531069
modePref = mActivity.getSharedPreferences(currentMode.name, Context.MODE_PRIVATE)
10541070

@@ -1086,10 +1102,6 @@ class CamConfig(private val mActivity: MainActivity) {
10861102

10871103
val builder = ImageCapture.Builder()
10881104

1089-
// To use the last frame instead of showing a blank screen when
1090-
// the camera that is being currently used gets unbind
1091-
mActivity.updateLastFrame()
1092-
10931105
// Unbind/close all other camera(s) [if any]
10941106
cameraProvider?.unbindAll()
10951107

app/src/main/java/app/grapheneos/camera/ui/activities/MainActivity.kt

+2-11
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ import app.grapheneos.camera.util.CameraControl
9292
import app.grapheneos.camera.util.ImageResizer
9393
import app.grapheneos.camera.util.executeIfAlive
9494
import app.grapheneos.camera.util.resolveActivity
95-
import app.grapheneos.camera.util.setBlurBitmapCompat
9695
import com.google.android.material.color.DynamicColors
9796
import com.google.android.material.dialog.MaterialAlertDialogBuilder
9897
import com.google.android.material.imageview.ShapeableImageView
@@ -130,7 +129,7 @@ open class MainActivity : AppCompatActivity(),
130129
// is already visible and to dismiss it if the permission gets granted.
131130
private var cameraPermissionDialog: AlertDialog? = null
132131
private var audioPermissionDialog: AlertDialog? = null
133-
private var lastFrame: Bitmap? = null
132+
var lastFrame: Bitmap? = null
134133

135134
private lateinit var mainFrame: View
136135
lateinit var rootView: View
@@ -652,6 +651,7 @@ open class MainActivity : AppCompatActivity(),
652651
timerView = binding.timer
653652
previewView.previewStreamState.observe(this) { state: StreamState ->
654653
if (state == StreamState.STREAMING) {
654+
previewView.visibility = View.VISIBLE
655655
mainOverlay.visibility = View.INVISIBLE
656656
camConfig.reloadSettings()
657657
if (!camConfig.isQRMode) {
@@ -663,15 +663,6 @@ open class MainActivity : AppCompatActivity(),
663663
}
664664

665665
restartRecordingIfPermissionsWasUnavailable()
666-
} else {
667-
previewGrid.visibility = View.INVISIBLE
668-
val lastFrame = lastFrame
669-
if (lastFrame != null && this !is CaptureActivity) {
670-
setBlurBitmapCompat(mainOverlay, lastFrame)
671-
settingsIcon.visibility = View.INVISIBLE
672-
settingsIcon.isEnabled = false
673-
mainOverlay.visibility = View.VISIBLE
674-
}
675666
}
676667
}
677668
flipCameraCircle = binding.flipCameraCircle

0 commit comments

Comments
 (0)