Skip to content

Commit c118eeb

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 168b598 commit c118eeb

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
@@ -93,7 +93,6 @@ import app.grapheneos.camera.util.CameraControl
9393
import app.grapheneos.camera.util.ImageResizer
9494
import app.grapheneos.camera.util.executeIfAlive
9595
import app.grapheneos.camera.util.resolveActivity
96-
import app.grapheneos.camera.util.setBlurBitmapCompat
9796
import com.google.android.material.color.DynamicColors
9897
import com.google.android.material.dialog.MaterialAlertDialogBuilder
9998
import com.google.android.material.imageview.ShapeableImageView
@@ -131,7 +130,7 @@ open class MainActivity : AppCompatActivity(),
131130
// is already visible and to dismiss it if the permission gets granted.
132131
private var cameraPermissionDialog: AlertDialog? = null
133132
private var audioPermissionDialog: AlertDialog? = null
134-
private var lastFrame: Bitmap? = null
133+
var lastFrame: Bitmap? = null
135134

136135
private lateinit var mainFrame: View
137136
lateinit var rootView: View
@@ -649,6 +648,7 @@ open class MainActivity : AppCompatActivity(),
649648
timerView = binding.timer
650649
previewView.previewStreamState.observe(this) { state: StreamState ->
651650
if (state == StreamState.STREAMING) {
651+
previewView.visibility = View.VISIBLE
652652
mainOverlay.visibility = View.INVISIBLE
653653
camConfig.reloadSettings()
654654
if (!camConfig.isQRMode) {
@@ -660,15 +660,6 @@ open class MainActivity : AppCompatActivity(),
660660
}
661661

662662
restartRecordingIfPermissionsWasUnavailable()
663-
} else {
664-
previewGrid.visibility = View.INVISIBLE
665-
val lastFrame = lastFrame
666-
if (lastFrame != null && this !is CaptureActivity) {
667-
setBlurBitmapCompat(mainOverlay, lastFrame)
668-
settingsIcon.visibility = View.INVISIBLE
669-
settingsIcon.isEnabled = false
670-
mainOverlay.visibility = View.VISIBLE
671-
}
672663
}
673664
}
674665
flipCameraCircle = binding.flipCameraCircle

0 commit comments

Comments
 (0)