Aperture: Reformat code [2/2]
Change-Id: I13ae852582ab9a22bd386b49ef1244b567cd6530
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index 6d10827..e0e67fd 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -290,9 +290,11 @@
MSG_HIDE_ZOOM_SLIDER -> {
zoomLevel.visibility = View.GONE
}
+
MSG_HIDE_FOCUS_RING -> {
viewFinderFocus.visibility = View.GONE
}
+
MSG_HIDE_EXPOSURE_SLIDER -> {
exposureLevel.visibility = View.GONE
}
@@ -431,16 +433,20 @@
PowerManager.THERMAL_STATUS_MODERATE -> {
showSnackBar(R.string.thermal_status_moderate)
}
+
PowerManager.THERMAL_STATUS_SEVERE -> {
showSnackBar(R.string.thermal_status_severe)
}
+
PowerManager.THERMAL_STATUS_CRITICAL -> {
showSnackBar(R.string.thermal_status_critical)
}
+
PowerManager.THERMAL_STATUS_EMERGENCY -> {
showSnackBar(R.string.thermal_status_emergency)
emergencyClose()
}
+
PowerManager.THERMAL_STATUS_SHUTDOWN -> {
showSnackBar(R.string.thermal_status_shutdown)
emergencyClose()
@@ -679,6 +685,7 @@
}
}.start()
}
+
else -> {
handler.removeMessages(MSG_HIDE_FOCUS_RING)
ValueAnimator.ofInt(8.px, 0.px).apply {
@@ -736,6 +743,7 @@
shutterButton.performClick()
}
}
+
else -> {}
}
}
@@ -816,6 +824,7 @@
startShutterAnimation(ShutterAnimation.VideoStart)
}
}
+
else -> {}
}
@@ -847,8 +856,10 @@
null -> {
capturePreviewLayout.isVisible = false
}
+
is InputStream,
is Uri -> sendIntentResultAndExit(input)
+
else -> throw Exception("Invalid input")
}
}
@@ -905,11 +916,13 @@
primaryBarLayoutGroupPhoto.isVisible = false
googleLensButton.isVisible = isGoogleLensAvailable
}
+
CameraMode.PHOTO -> {
secondaryBottomBarLayout.isVisible = true
primaryBarLayoutGroupPhoto.isVisible = true
googleLensButton.isVisible = false
}
+
CameraMode.VIDEO -> {
secondaryBottomBarLayout.isVisible = true
primaryBarLayoutGroupPhoto.isVisible = true
@@ -1222,6 +1235,7 @@
}
true
}
+
KeyEvent.KEYCODE_CAMERA -> {
if (cameraMode == CameraMode.VIDEO && shutterButton.isEnabled &&
event?.repeatCount == 1
@@ -1230,6 +1244,7 @@
}
true
}
+
KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_VOLUME_DOWN -> when (sharedPreferences.volumeButtonsAction) {
GestureActions.SHUTTER -> {
@@ -1240,6 +1255,7 @@
}
true
}
+
GestureActions.ZOOM -> {
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_UP -> zoomIn()
@@ -1247,14 +1263,17 @@
}
true
}
+
GestureActions.VOLUME -> {
super.onKeyDown(keyCode, event)
}
+
GestureActions.NOTHING -> {
// Do nothing
true
}
}
+
else -> super.onKeyDown(keyCode, event)
}
}
@@ -1269,6 +1288,7 @@
}
true
}
+
KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_VOLUME_DOWN -> {
when (sharedPreferences.volumeButtonsAction) {
@@ -1278,18 +1298,22 @@
}
true
}
+
GestureActions.ZOOM -> {
true
}
+
GestureActions.VOLUME -> {
super.onKeyDown(keyCode, event)
}
+
GestureActions.NOTHING -> {
// Do nothing
true
}
}
}
+
else -> super.onKeyUp(keyCode, event)
}
}
@@ -1313,6 +1337,7 @@
when (shutterAnimation) {
ShutterAnimation.InitPhoto,
ShutterAnimation.InitVideo -> drawable.reset()
+
else -> drawable.start()
}
}
@@ -1456,17 +1481,21 @@
cameraState = CameraState.RECORDING_VIDEO
startVideoRecordingStateAnimation(VideoRecordingStateAnimation.Init)
}
+
is VideoRecordEvent.Pause -> runOnUiThread {
cameraState = CameraState.RECORDING_VIDEO_PAUSED
startVideoRecordingStateAnimation(VideoRecordingStateAnimation.ResumeToPause)
}
+
is VideoRecordEvent.Resume -> runOnUiThread {
cameraState = CameraState.RECORDING_VIDEO
startVideoRecordingStateAnimation(VideoRecordingStateAnimation.PauseToResume)
}
+
is VideoRecordEvent.Status -> runOnUiThread {
updateRecordingStatus(true, it.recordingStats.recordedDurationNanos)
}
+
is VideoRecordEvent.Finalize -> {
runOnUiThread {
startShutterAnimation(ShutterAnimation.VideoEnd)
@@ -1517,6 +1546,7 @@
CameraMode.QR -> cameraManager.getCameraOfFacingOrFirstAvailable(
CameraFacing.BACK, cameraMode
)
+
else -> camera
}
@@ -1539,6 +1569,7 @@
cameraController.setImageAnalysisAnalyzer(cameraExecutor, imageAnalyzer)
CameraController.IMAGE_ANALYSIS
}
+
CameraMode.PHOTO -> {
cameraController.imageCaptureResolutionSelector = ResolutionSelector.Builder()
.setAspectRatioStrategy(
@@ -1556,6 +1587,7 @@
.build()
CameraController.IMAGE_CAPTURE
}
+
CameraMode.VIDEO -> {
// Fallback to highest supported video quality
if (!supportedVideoQualities.contains(videoQuality)) {
@@ -1615,41 +1647,49 @@
showToast(R.string.error_max_cameras_in_use)
finish()
}
+
CameraXCameraState.ERROR_CAMERA_IN_USE -> {
// No way to fix it without user action, bail out
showToast(R.string.error_camera_in_use)
finish()
}
+
CameraXCameraState.ERROR_OTHER_RECOVERABLE_ERROR -> {
// Warn the user and don't do anything
showToast(R.string.error_other_recoverable_error)
}
+
CameraXCameraState.ERROR_STREAM_CONFIG -> {
// CameraX use case misconfiguration, no way to recover
showToast(R.string.error_stream_config)
finish()
}
+
CameraXCameraState.ERROR_CAMERA_DISABLED -> {
// No way to fix it without user action, bail out
showToast(R.string.error_camera_disabled)
finish()
}
+
CameraXCameraState.ERROR_CAMERA_FATAL_ERROR -> {
// No way to fix it without user action, bail out
showToast(R.string.error_camera_fatal_error)
finish()
}
+
CameraXCameraState.ERROR_DO_NOT_DISTURB_MODE_ENABLED -> {
// No way to fix it without user action, bail out
showToast(R.string.error_do_not_disturb_mode_enabled)
finish()
}
+
else -> {
// We know anything about it, just check if it's recoverable or critical
when (it.type) {
CameraXCameraState.ErrorType.RECOVERABLE -> {
showToast(R.string.error_unknown_recoverable)
}
+
CameraXCameraState.ErrorType.CRITICAL -> {
showToast(R.string.error_unknown_critical)
finish()
@@ -1701,8 +1741,10 @@
CameraMode.PHOTO -> photoCaptureMode !=
ImageCapture.CAPTURE_MODE_ZERO_SHUTTER_LAG ||
NoiseReductionMode.ALLOWED_MODES_ON_ZSL.contains(it)
+
CameraMode.VIDEO ->
NoiseReductionMode.ALLOWED_MODES_ON_VIDEO_MODE.contains(it)
+
CameraMode.QR -> false
}
}?.let {
@@ -1713,8 +1755,10 @@
CameraMode.PHOTO -> photoCaptureMode !=
ImageCapture.CAPTURE_MODE_ZERO_SHUTTER_LAG ||
ShadingMode.ALLOWED_MODES_ON_ZSL.contains(it)
+
CameraMode.VIDEO ->
ShadingMode.ALLOWED_MODES_ON_VIDEO_MODE.contains(it)
+
CameraMode.QR -> false
}
}?.let {
@@ -1743,8 +1787,10 @@
CameraMode.PHOTO -> photoCaptureMode !=
ImageCapture.CAPTURE_MODE_ZERO_SHUTTER_LAG ||
DistortionCorrectionMode.ALLOWED_MODES_ON_ZSL.contains(it)
+
CameraMode.VIDEO ->
DistortionCorrectionMode.ALLOWED_MODES_ON_VIDEO_MODE.contains(it)
+
CameraMode.QR -> false
}
}?.let {
@@ -1757,8 +1803,10 @@
CameraMode.PHOTO -> photoCaptureMode !=
ImageCapture.CAPTURE_MODE_ZERO_SHUTTER_LAG ||
HotPixelMode.ALLOWED_MODES_ON_ZSL.contains(it)
+
CameraMode.VIDEO ->
HotPixelMode.ALLOWED_MODES_ON_VIDEO_MODE.contains(it)
+
CameraMode.QR -> false
}
}?.let {
@@ -1813,6 +1861,7 @@
startShutterAnimation(ShutterAnimation.InitPhoto)
}
}
+
CameraMode.VIDEO -> {
if (this.cameraMode == CameraMode.PHOTO) {
startShutterAnimation(ShutterAnimation.PhotoToVideo)
@@ -1820,6 +1869,7 @@
startShutterAnimation(ShutterAnimation.InitVideo)
}
}
+
else -> {}
}
@@ -2220,9 +2270,11 @@
is InputStream -> input.use {
input.copyTo(outputStream!!)
}
+
is Uri -> contentResolver.openInputStream(input).use { inputStream ->
inputStream!!.copyTo(outputStream!!)
}
+
else -> throw IllegalStateException("Input is not Uri or InputStream")
}
}
@@ -2244,12 +2296,14 @@
).transform(transform)
putExtra("data", scaledAndRotatedBitmap)
}
+
is Uri -> {
// We saved the media (video), so return the URI that we saved.
data = input
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
putExtra(MediaStore.EXTRA_OUTPUT, input)
}
+
else -> throw IllegalStateException("Input is not Uri or InputStream")
}
})
diff --git a/app/src/main/java/org/lineageos/aperture/SettingsActivity.kt b/app/src/main/java/org/lineageos/aperture/SettingsActivity.kt
index 049e39f..b20667f 100644
--- a/app/src/main/java/org/lineageos/aperture/SettingsActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/SettingsActivity.kt
@@ -55,6 +55,7 @@
onBackPressedDispatcher.onBackPressed()
true
}
+
else -> {
super.onOptionsItemSelected(item)
}
diff --git a/app/src/main/java/org/lineageos/aperture/camera/Camera.kt b/app/src/main/java/org/lineageos/aperture/camera/Camera.kt
index bf6aafb..0592d61 100644
--- a/app/src/main/java/org/lineageos/aperture/camera/Camera.kt
+++ b/app/src/main/java/org/lineageos/aperture/camera/Camera.kt
@@ -109,9 +109,11 @@
CameraCharacteristics.NOISE_REDUCTION_MODE_FAST -> NoiseReductionMode.FAST
CameraCharacteristics.NOISE_REDUCTION_MODE_HIGH_QUALITY ->
NoiseReductionMode.HIGH_QUALITY
+
CameraCharacteristics.NOISE_REDUCTION_MODE_MINIMAL -> NoiseReductionMode.MINIMAL
CameraCharacteristics.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG ->
NoiseReductionMode.ZERO_SHUTTER_LAG
+
else -> null
}
}
@@ -142,10 +144,13 @@
when (it) {
CameraCharacteristics.COLOR_CORRECTION_ABERRATION_MODE_OFF ->
ColorCorrectionAberrationMode.OFF
+
CameraCharacteristics.COLOR_CORRECTION_ABERRATION_MODE_FAST ->
ColorCorrectionAberrationMode.FAST
+
CameraCharacteristics.COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY ->
ColorCorrectionAberrationMode.HIGH_QUALITY
+
else -> null
}
}
@@ -161,10 +166,13 @@
when (it) {
CameraCharacteristics.DISTORTION_CORRECTION_MODE_OFF ->
DistortionCorrectionMode.OFF
+
CameraCharacteristics.DISTORTION_CORRECTION_MODE_FAST ->
DistortionCorrectionMode.FAST
+
CameraCharacteristics.DISTORTION_CORRECTION_MODE_HIGH_QUALITY ->
DistortionCorrectionMode.HIGH_QUALITY
+
else -> null
}
}
diff --git a/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt b/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt
index 58a4048..9772f52 100644
--- a/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt
+++ b/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt
@@ -164,6 +164,7 @@
CameraFacing.EXTERNAL -> externalCamerasSupportingVideoRecording
else -> throw Exception("Unknown facing")
}
+
else -> when (cameraFacing) {
CameraFacing.BACK -> backCameras
CameraFacing.FRONT -> frontCameras
diff --git a/app/src/main/java/org/lineageos/aperture/ext/CaptureRequestOptionsBuilder.kt b/app/src/main/java/org/lineageos/aperture/ext/CaptureRequestOptionsBuilder.kt
index c454cf4..5f1f905 100644
--- a/app/src/main/java/org/lineageos/aperture/ext/CaptureRequestOptionsBuilder.kt
+++ b/app/src/main/java/org/lineageos/aperture/ext/CaptureRequestOptionsBuilder.kt
@@ -97,6 +97,7 @@
ColorCorrectionAberrationMode.OFF -> CameraMetadata.COLOR_CORRECTION_ABERRATION_MODE_OFF
ColorCorrectionAberrationMode.FAST ->
CameraMetadata.COLOR_CORRECTION_ABERRATION_MODE_FAST
+
ColorCorrectionAberrationMode.HIGH_QUALITY ->
CameraMetadata.COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY
}
diff --git a/app/src/main/java/org/lineageos/aperture/qr/QrTextClassifier.kt b/app/src/main/java/org/lineageos/aperture/qr/QrTextClassifier.kt
index ff1b85b..4542743 100644
--- a/app/src/main/java/org/lineageos/aperture/qr/QrTextClassifier.kt
+++ b/app/src/main/java/org/lineageos/aperture/qr/QrTextClassifier.kt
@@ -55,6 +55,7 @@
)
.build()
}
+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && isValidWifiUri(text.toString()) -> {
val wifiNetwork = WifiNetwork.fromQr(text.toString())!!
val networkSuggestion = wifiNetwork.toNetworkSuggestion()!!
@@ -82,6 +83,7 @@
)
.build()
}
+
else -> parent.classifyText(text, startIndex, endIndex, defaultLocales)
}
diff --git a/app/src/main/java/org/lineageos/aperture/qr/WifiNetwork.kt b/app/src/main/java/org/lineageos/aperture/qr/WifiNetwork.kt
index 5718453..32193d2 100644
--- a/app/src/main/java/org/lineageos/aperture/qr/WifiNetwork.kt
+++ b/app/src/main/java/org/lineageos/aperture/qr/WifiNetwork.kt
@@ -46,9 +46,11 @@
// this networks supports WPA2
setWpa2Passphrase(it)
}
+
EncryptionType.SAE -> {
setWpa3Passphrase(it)
}
+
else -> throw Exception("Invalid encryption type/password combination")
}
}
diff --git a/app/src/main/java/org/lineageos/aperture/ui/CapturePreviewLayout.kt b/app/src/main/java/org/lineageos/aperture/ui/CapturePreviewLayout.kt
index 6799fc2..50bdd48 100644
--- a/app/src/main/java/org/lineageos/aperture/ui/CapturePreviewLayout.kt
+++ b/app/src/main/java/org/lineageos/aperture/ui/CapturePreviewLayout.kt
@@ -123,6 +123,7 @@
imageView.setImageBitmap(bitmap)
}
}
+
MediaType.VIDEO -> {
exoPlayer = ExoPlayer.Builder(context)
.build()
diff --git a/app/src/main/java/org/lineageos/aperture/ui/InfoChipView.kt b/app/src/main/java/org/lineageos/aperture/ui/InfoChipView.kt
index 0fcaa22..17b43a6 100644
--- a/app/src/main/java/org/lineageos/aperture/ui/InfoChipView.kt
+++ b/app/src/main/java/org/lineageos/aperture/ui/InfoChipView.kt
@@ -145,12 +145,14 @@
Rotation.ROTATION_0,
Rotation.ROTATION_90,
Rotation.ROTATION_180 -> R.id.viewFinder
+
Rotation.ROTATION_270 -> LayoutParams.UNSET
}
endToEnd = when (screenRotation) {
Rotation.ROTATION_0,
Rotation.ROTATION_90,
Rotation.ROTATION_180 -> LayoutParams.UNSET
+
Rotation.ROTATION_270 -> R.id.viewFinder
}
}
@@ -162,12 +164,14 @@
translationX = when (screenRotation) {
Rotation.ROTATION_0,
Rotation.ROTATION_180 -> 0F
+
Rotation.ROTATION_90 -> -((measuredWidth - measuredHeight) / 2).toFloat()
Rotation.ROTATION_270 -> ((measuredWidth - measuredHeight) / 2).toFloat()
}
translationY = when (screenRotation) {
Rotation.ROTATION_0,
Rotation.ROTATION_180 -> 0F
+
Rotation.ROTATION_90,
Rotation.ROTATION_270 -> -((measuredHeight - measuredWidth) / 2).toFloat()
}