Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions app/src/main/java/co/stonephone/stonecamera/StoneCameraApp.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// StoneCameraApp.kt
@file:kotlin.OptIn(ExperimentalMaterial3Api::class)

package co.stonephone.stonecamera

import android.annotation.SuppressLint
Expand All @@ -10,6 +12,12 @@ import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FlipCameraAndroid
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.*
Expand All @@ -27,6 +35,7 @@ import co.stonephone.stonecamera.plugins.PhotoModePlugin
import co.stonephone.stonecamera.plugins.PinchToZoomPlugin
import co.stonephone.stonecamera.plugins.QRScannerPlugin
import co.stonephone.stonecamera.plugins.SettingLocation
import co.stonephone.stonecamera.plugins.SettingsTrayPlugin
import co.stonephone.stonecamera.plugins.ShutterFlashPlugin
import co.stonephone.stonecamera.plugins.TapToFocusPlugin
import co.stonephone.stonecamera.plugins.VolumeControlsPlugin
Expand All @@ -53,10 +62,13 @@ val PLUGINS = listOf(
VolumeControlsPlugin(),
PhotoModePlugin(),
VideoModePlugin(),
SettingsTrayPlugin()
// DebugPlugin()
)

@OptIn(ExperimentalCamera2Interop::class)
@OptIn(
ExperimentalCamera2Interop::class
)
@SuppressLint("ClickableViewAccessibility")
@Composable
fun StoneCameraApp(
Expand Down Expand Up @@ -141,8 +153,13 @@ fun StoneCameraApp(
.align(Alignment.BottomCenter),
verticalArrangement = Arrangement.SpaceBetween
) {
plugins.map {
it.renderTray(stoneCameraViewModel, it)

Box(
modifier = Modifier.fillMaxWidth(),
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These previous 3 lines look unnecessarily spread out; is there a reason why they're not on the same line?

plugins.map {
it.renderTray(stoneCameraViewModel, it)
}
}

// Translucent overlay for mode switch & shutter
Expand Down Expand Up @@ -179,5 +196,6 @@ fun StoneCameraApp(
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.stonephone.stonecamera.plugins

import android.app.Application
import android.util.Size
import androidx.camera.core.AspectRatio
import androidx.camera.core.ImageCapture
Expand All @@ -14,7 +13,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import co.stonephone.stonecamera.MyApplication
Expand Down Expand Up @@ -175,10 +173,10 @@ class AspectRatioPlugin : IPlugin {
key = "aspectRatio",
defaultValue = "16:9",
options = listOf("16:9", "4:3", "FULL"),
render = { value ->
render = { value, isSelected ->
Text(
text = value,
color = Color.White,
color = if (isSelected) Color(0xFFFFCC00) else Color.White,
style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Bold,
modifier = Modifier
Expand All @@ -193,9 +191,9 @@ class AspectRatioPlugin : IPlugin {
previewView!!.scaleType = PreviewView.ScaleType.FIT_CENTER
}
viewModel.recreateUseCases()

},
renderLocation = SettingLocation.TOP
renderLocation = SettingLocation.TOP,
label = "Aspect Ratio"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DebugPlugin : IPlugin {
x = visibleRegion!!.left.dp,
y = visibleRegion!!.top.dp
)
.border(2.dp, Color.Yellow)
.border(2.dp, Color(0xAAFFCC00))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I'm curious why this is a hard-coded colour...?

.padding(16.dp),
contentAlignment = Alignment.TopCenter
) { }
Expand Down
56 changes: 32 additions & 24 deletions app/src/main/java/co/stonephone/stonecamera/plugins/Flash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package co.stonephone.stonecamera.plugins

import android.util.Log
import androidx.camera.core.ImageCapture
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FlashAuto
import androidx.compose.material.icons.filled.FlashOff
import androidx.compose.material.icons.filled.FlashOn
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import co.stonephone.stonecamera.StoneCameraViewModel

class FlashPlugin : IPlugin {
Expand All @@ -19,8 +24,7 @@ class FlashPlugin : IPlugin {
}

override fun onImageCapture(
viewModel: StoneCameraViewModel,
imageCapture: ImageCapture.Builder
viewModel: StoneCameraViewModel, imageCapture: ImageCapture.Builder
): ImageCapture.Builder {
val flashMode = viewModel.getSetting<String>("flash") ?: "OFF"
val mode = flashModeStringToMode(flashMode)
Expand All @@ -40,33 +44,37 @@ class FlashPlugin : IPlugin {
}
}

override val settings = { viewModel: StoneCameraViewModel ->
override val settings: (StoneCameraViewModel) -> List<PluginSetting> = { viewModel ->
listOf(
PluginSetting.EnumSetting(
key = "flash",
label = "Flash",
defaultValue = "OFF",
options = listOf("OFF", "ON", "AUTO"),
render = { flashMode ->
Icon(
imageVector = when (flashMode) {
"OFF" -> Icons.Default.FlashOff // Replace with your preferred icon
"ON" -> Icons.Default.FlashOn
"AUTO" -> Icons.Default.FlashAuto // You may need to add custom icons for Flash Auto
else -> {
Icons.Default.FlashOff
}
},
contentDescription = when (flashMode) {
"OFF" -> "Flash Off"
"ON" -> "Flash On"
"AUTO" -> "Flash Auto"
else -> {
"Flash"
}
},
tint = Color.White // Customize as needed
)

render = { flashMode, isSelected ->
Box(
modifier = Modifier.padding(8.dp)
) {
Icon(
imageVector = when (flashMode) {
"OFF" -> Icons.Default.FlashOff // Replace with your preferred icon
"ON" -> Icons.Default.FlashOn
"AUTO" -> Icons.Default.FlashAuto // You may need to add custom icons for Flash Auto
else -> {
Icons.Default.FlashOff
}
},
contentDescription = when (flashMode) {
"OFF" -> "Flash Off"
"ON" -> "Flash On"
"AUTO" -> "Flash Auto"
else -> {
"Flash"
}
},
tint = if (isSelected) Color(0xFFFFCC00) else Color.White
)
}
},
onChange = { viewModel, value ->
viewModel.recreateUseCases()
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/co/stonephone/stonecamera/plugins/IPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package co.stonephone.stonecamera.plugins

import android.content.ContentValues
import android.media.Image
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageProxy
import androidx.camera.core.Preview
Expand Down Expand Up @@ -115,20 +114,23 @@ enum class SettingLocation {
sealed class PluginSetting(
val key: String,
val defaultValue: Any?,
val label: String,
val onChange: (StoneCameraViewModel, Any?) -> Unit,
val renderLocation: SettingLocation? = SettingLocation.NONE,
) {

class EnumSetting(
key: String,
defaultValue: String,
label: String,
renderLocation: SettingLocation? = SettingLocation.NONE,
val options: List<String>,
val render: @Composable (value: String) -> Unit,
val render: @Composable (value: String, Boolean) -> Unit,
onChange: (StoneCameraViewModel, String) -> Unit
) : PluginSetting(
key,
defaultValue,
label,
onChange as (StoneCameraViewModel, Any?) -> Unit,
renderLocation
)
Expand All @@ -137,22 +139,25 @@ sealed class PluginSetting(
key: String,
defaultValue: Float,
renderLocation: SettingLocation? = SettingLocation.NONE,
label: String,
val minValue: Float,
val maxValue: Float,
val stepValue: Float? = null,
onChange: (StoneCameraViewModel, Float) -> Unit
) : PluginSetting(
key,
defaultValue,
label,
onChange as (StoneCameraViewModel, Any?) -> Unit,
renderLocation
)

class CustomSetting(
key: String,
defaultValue: String,
label: String,
renderLocation: SettingLocation? = SettingLocation.NONE,
val customRender: @Composable (StoneCameraViewModel, Any?, (Any?) -> Unit) -> Unit, // Render function with a callback for value changes
onChange: (StoneCameraViewModel, Any?) -> Unit
) : PluginSetting(key, defaultValue, onChange, renderLocation)
) : PluginSetting(key, defaultValue, label, onChange, renderLocation)
}
Loading
Loading