Skip to content

Commit 584022b

Browse files
t895thestinger
authored andcommitted
Ignore short edges mode for camera screen dialogs
The MaterialAlertDialog appears broken when large, the status bar is hidden, and short edges mode used in the parent window. This tells the dialog to use the default mode to prevent weird layout issues.
1 parent 542cac7 commit 584022b

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import app.grapheneos.camera.ui.activities.SecureActivity
4747
import app.grapheneos.camera.ui.activities.SecureMainActivity
4848
import app.grapheneos.camera.ui.activities.VideoCaptureActivity
4949
import app.grapheneos.camera.ui.activities.VideoOnlyActivity
50+
import app.grapheneos.camera.ui.showIgnoringShortEdgeMode
5051
import app.grapheneos.camera.util.edit
5152
import com.google.android.material.dialog.MaterialAlertDialogBuilder
5253
import com.google.zxing.BarcodeFormat
@@ -1450,7 +1451,7 @@ class CamConfig(private val mActivity: MainActivity) {
14501451
}
14511452

14521453
fun showMoreOptionsForQR() {
1453-
val builder = AlertDialog.Builder(mActivity)
1454+
val builder = MaterialAlertDialogBuilder(mActivity)
14541455
builder.setTitle(mActivity.resources.getString(R.string.more_options))
14551456

14561457
val optionNames = arrayListOf<String>()
@@ -1524,7 +1525,7 @@ class CamConfig(private val mActivity: MainActivity) {
15241525
}
15251526
}
15261527

1527-
dialog.show()
1528+
dialog.showIgnoringShortEdgeMode()
15281529
}
15291530

15301531
fun onStorageLocationNotFound() {
@@ -1540,6 +1541,6 @@ class CamConfig(private val mActivity: MainActivity) {
15401541
}
15411542
val alertDialog = builder.create()
15421543
alertDialog.setCancelable(false)
1543-
alertDialog.show()
1544+
alertDialog.showIgnoringShortEdgeMode()
15441545
}
15451546
}

app/src/main/java/app/grapheneos/camera/capturer/ImageCapturer.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import app.grapheneos.camera.CapturedItem
2121
import app.grapheneos.camera.R
2222
import app.grapheneos.camera.ui.activities.MainActivity
2323
import app.grapheneos.camera.ui.activities.SecureMainActivity
24+
import app.grapheneos.camera.ui.showIgnoringShortEdgeMode
2425
import app.grapheneos.camera.util.printStackTraceToString
2526
import com.google.android.material.dialog.MaterialAlertDialogBuilder
2627

@@ -213,10 +214,10 @@ class ImageCapturer(val mActivity: MainActivity) {
213214
cm.setPrimaryClip(clipData)
214215
ctx.showMessage(R.string.copied_text_to_clipboard)
215216
}
216-
show()
217+
showIgnoringShortEdgeMode()
217218
}
218219
}
219-
show()
220+
showIgnoringShortEdgeMode()
220221
}
221222
}
222223

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package app.grapheneos.camera.ui
2+
3+
import android.view.WindowManager
4+
import androidx.appcompat.app.AlertDialog
5+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
6+
7+
/**
8+
* When in an activity where the status bar is hidden, the window layoutInDisplayCutoutMode
9+
* is set to [WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES], and a
10+
* material alert dialog is present that is large enough, the layout of the dialog will appear
11+
* broken and sometimes will shift randomly. These extensions force the dialog window to ignore
12+
* the short edges mode so that it will appear as normal.
13+
*/
14+
15+
fun AlertDialog.ignoreShortEdges() {
16+
window?.attributes?.layoutInDisplayCutoutMode =
17+
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
18+
}
19+
20+
fun AlertDialog.showIgnoringShortEdgeMode(): AlertDialog {
21+
ignoreShortEdges()
22+
show()
23+
return this
24+
}
25+
26+
fun MaterialAlertDialogBuilder.showIgnoringShortEdgeMode(): AlertDialog =
27+
this.create().showIgnoringShortEdgeMode()

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import app.grapheneos.camera.ui.QRToggle
8888
import app.grapheneos.camera.ui.SettingsDialog
8989
import app.grapheneos.camera.ui.seekbar.ExposureBar
9090
import app.grapheneos.camera.ui.seekbar.ZoomBar
91+
import app.grapheneos.camera.ui.showIgnoringShortEdgeMode
9192
import app.grapheneos.camera.util.CameraControl
9293
import app.grapheneos.camera.util.ImageResizer
9394
import app.grapheneos.camera.util.executeIfAlive
@@ -329,7 +330,7 @@ open class MainActivity : AppCompatActivity(),
329330
onDisableAudio()
330331
}
331332

332-
audioPermissionDialog = builder.show()
333+
audioPermissionDialog = builder.showIgnoringShortEdgeMode()
333334
}
334335

335336
fun updateLastFrame() {
@@ -474,7 +475,7 @@ open class MainActivity : AppCompatActivity(),
474475
finish()
475476
}
476477
}
477-
cameraPermissionDialog = builder.show()
478+
cameraPermissionDialog = builder.showIgnoringShortEdgeMode()
478479
}
479480

480481
// Request for the permission (Android will actually popup the permission
@@ -1222,7 +1223,7 @@ open class MainActivity : AppCompatActivity(),
12221223

12231224
camConfig.cameraProvider?.unbindAll()
12241225

1225-
builder.show()
1226+
builder.showIgnoringShortEdgeMode()
12261227
}
12271228
}
12281229

@@ -1703,7 +1704,7 @@ open class MainActivity : AppCompatActivity(),
17031704
camConfig.requireLocation = false
17041705
}
17051706
}
1706-
}.show()
1707+
}.showIgnoringShortEdgeMode()
17071708
}
17081709

17091710
(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)

0 commit comments

Comments
 (0)