Allow scanning while device is locked

Show the camera and newly scanned results over the lock screen
while keeping history, media selection, and settings protected.
This commit is contained in:
Markus Fisch
2026-06-08 20:21:05 +02:00
parent ae29a4d207
commit 8298ce70ef
3 changed files with 28 additions and 2 deletions
@@ -60,6 +60,7 @@ import de.markusfisch.android.binaryeye.media.releaseToneGenerators
import de.markusfisch.android.binaryeye.net.isScanDeeplink
import de.markusfisch.android.binaryeye.net.sendAsync
import de.markusfisch.android.binaryeye.net.urlEncode
import de.markusfisch.android.binaryeye.os.showWhenLocked
import de.markusfisch.android.binaryeye.preference.Preferences
import de.markusfisch.android.binaryeye.view.errorFeedback
import de.markusfisch.android.binaryeye.view.initBars
@@ -190,6 +191,7 @@ class CameraActivity : AppCompatActivity() {
override fun onCreate(state: Bundle?) {
super.onCreate(state)
showWhenLocked()
setContentView(R.layout.activity_camera)
// Necessary to get the right translation after setting a
@@ -1081,7 +1083,7 @@ fun Activity.showResult(
return
}
if (!bulkMode) {
startActivity(DecodeActivity.newIntent(this, scan))
startActivity(DecodeActivity.newIntent(this, scan, showWhenLocked = true))
}
}
@@ -53,6 +53,7 @@ import de.markusfisch.android.binaryeye.io.askForFileName
import de.markusfisch.android.binaryeye.io.toSaveResult
import de.markusfisch.android.binaryeye.io.writeExternalFile
import de.markusfisch.android.binaryeye.net.createEncodeDeeplink
import de.markusfisch.android.binaryeye.os.showWhenLocked
import de.markusfisch.android.binaryeye.view.hideSoftKeyboard
import de.markusfisch.android.binaryeye.view.setPaddingFromWindowInsets
import de.markusfisch.android.binaryeye.widget.toast
@@ -122,6 +123,9 @@ class DecodeActivity : AbstractBaseActivity() {
override fun onCreate(state: Bundle?) {
super.onCreate(state)
if (intent.getBooleanExtra(SHOW_WHEN_LOCKED, false)) {
showWhenLocked()
}
setScreenContentView(R.layout.activity_decode)
setTitle(R.string.content)
@@ -734,12 +738,18 @@ class DecodeActivity : AbstractBaseActivity() {
private const val SCAN_BUNDLE = "scan_bundle"
private const val OPEN_DOCUMENT = 1
private const val SCHEME_FILE = "file://"
private const val SHOW_WHEN_LOCKED = "show_when_locked"
fun newIntent(context: Context, scan: Scan): Intent {
fun newIntent(
context: Context,
scan: Scan,
showWhenLocked: Boolean = false
): Intent {
val args = Bundle()
args.putBundle(SCAN_BUNDLE, scan.toBundle())
return Intent(context, DecodeActivity::class.java).apply {
putExtra(DECODED_SCAN, true)
putExtra(SHOW_WHEN_LOCKED, showWhenLocked)
putExtras(args)
}
}
@@ -0,0 +1,14 @@
package de.markusfisch.android.binaryeye.os
import android.app.Activity
import android.os.Build
import android.view.WindowManager
@Suppress("DEPRECATION")
fun Activity.showWhenLocked() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true)
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
}
}