Skip to content
Open
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
android:theme="@style/Theme.App"
android:taskAffinity=".ui.activities.InAppGallery"
android:excludeFromRecents="true"
android:windowSoftInputMode="adjustResize"
android:exported="false"/>

<activity
Expand Down
71 changes: 68 additions & 3 deletions app/src/main/java/app/grapheneos/camera/CamConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class CamConfig(private val mActivity: MainActivity) {

const val ENABLE_ZSL = "enable_zsl"

const val VIDEO_BITRATE_VALUE = "video_bitrate_value"

const val VIDEO_BITRATE_UNIT = "video_bitrate_unit"

// const val IMAGE_FILE_FORMAT = "image_quality"
// const val VIDEO_FILE_FORMAT = "video_quality"
}
Expand Down Expand Up @@ -156,6 +160,10 @@ class CamConfig(private val mActivity: MainActivity) {

const val ENABLE_ZSL = false

const val VIDEO_BITRATE_VALUE = 0 // auto

const val VIDEO_BITRATE_UNIT = "b/s"

// const val IMAGE_FILE_FORMAT = ""
// const val VIDEO_FILE_FORMAT = ""
}
Expand All @@ -176,6 +184,12 @@ class CamConfig(private val mActivity: MainActivity) {
BarcodeFormat.PDF_417,
)

val VIDEO_BITRATE_UNITS = arrayOf(
"b/s",
"kb/s",
"mb/s"
)

val imageCollectionUri: Uri = MediaStore.Images.Media.getContentUri(
MediaStore.VOLUME_EXTERNAL_PRIMARY
)!!
Expand Down Expand Up @@ -555,6 +569,52 @@ class CamConfig(private val mActivity: MainActivity) {
editor.apply()
}

// The value of bit rate set by the user (the effective value can be different based on the selected unit)
var videoBitRateValue: Int
get() {
return commonPref.getInt(
SettingValues.Key.VIDEO_BITRATE_VALUE,
SettingValues.Default.VIDEO_BITRATE_VALUE
)
}
set(value) {
val editor = commonPref.edit()
editor.putInt(SettingValues.Key.VIDEO_BITRATE_VALUE, value)
editor.apply()
}

// The unit of bit rate set by the user (impacts the effective value of bit rate sent)
var videoBitRateUnit: String
get() {
return commonPref.getString(
SettingValues.Key.VIDEO_BITRATE_UNIT,
SettingValues.Default.VIDEO_BITRATE_UNIT
) ?: SettingValues.Default.VIDEO_BITRATE_UNIT
}
set(value) {
val editor = commonPref.edit()
editor.putString(SettingValues.Key.VIDEO_BITRATE_UNIT, value)
editor.apply()
}

// Returns a multiplier value based on the
val videoBitRateMultiplier : Int
get() {
return if (videoBitRateUnit == "kb/s") {
1000
} else if (videoBitRateUnit == "mb/s") {
1000000
} else {
1
}
}

// The effective video bit rate based on [videoBitRateValue] and [videoBitRateUnit]
val videoBitRate : Int
get() {
return videoBitRateMultiplier * videoBitRateValue
}

val isZslSupported : Boolean by lazy {
camera!!.cameraInfo.isZslSupported
}
Expand Down Expand Up @@ -1146,10 +1206,15 @@ class CamConfig(private val mActivity: MainActivity) {
View.VISIBLE
}

val videoCaptureBuilder = VideoCapture.Builder(
Recorder.Builder()
val recorderBuilder = Recorder.Builder()
.setQualitySelector(QualitySelector.from(videoQuality))
.build()

if (mActivity.camConfig.videoBitRateValue != 0) {
recorderBuilder.setTargetVideoEncodingBitRate(mActivity.camConfig.videoBitRate)
}

val videoCaptureBuilder = VideoCapture.Builder(
recorderBuilder.build()
)

videoCaptureBuilder.setVideoStabilizationEnabled(mActivity.camConfig.enableEIS)
Expand Down
42 changes: 0 additions & 42 deletions app/src/main/java/app/grapheneos/camera/NumInputFilter.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package app.grapheneos.camera.inputfilter

import android.text.InputFilter
import android.text.Spanned

open class CustomNumFilter(
val shouldAcceptNumber : (Float) -> Boolean,
) : InputFilter {

override fun filter(
source: CharSequence,
start: Int,
end: Int,
dest: Spanned,
dstart: Int,
dend: Int
): CharSequence? {
val transformedString = source.subSequence(start, end).replace(Regex("[^0-9]"), "")

try {
val input = (dest.subSequence(0, dstart).toString() + source + dest.subSequence(
dend,
dest.length
)).toFloat()
if (this.shouldAcceptNumber(input)) {
return transformedString
} else {
return ""
}
} catch (e: NumberFormatException) {
e.printStackTrace()
return transformedString
}
return transformedString
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.grapheneos.camera.inputfilter

// Ensures that the field is within the min/max limits for a number type input field
class NumLimitFilter(
val min: Float,
val max: Float,
val onOutOfRange: () -> Unit,
) : CustomNumFilter(
shouldAcceptNumber = { num ->
if (num in min..max) {
true
} else {
onOutOfRange()
false
}
}
) {
constructor(min: Int, max: Int, onOutOfRange: () -> Unit) : this(min.toFloat(), max.toFloat(), onOutOfRange)
}
Loading