Skip to content

Commit

Permalink
Add 60 fps toggle to Camera app
Browse files Browse the repository at this point in the history
This change adds a toggle to the Camera app allowing for 60fps video.
The default is unchanged, and this setting is set to "false" by default.
When the user toggles the switch, the video records in higher framerate.
  • Loading branch information
shur-complement committed Nov 30, 2023
1 parent 754acde commit 4e2da89
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
51 changes: 44 additions & 7 deletions app/src/main/java/app/grapheneos/camera/CamConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import android.util.Log
import android.util.Range
import android.util.Size
import android.view.MotionEvent
import android.view.View
Expand Down Expand Up @@ -89,6 +90,7 @@ class CamConfig(private val mActivity: MainActivity) {
const val ASPECT_RATIO = "aspect_ratio"
const val INCLUDE_AUDIO = "include_audio"
const val ENABLE_EIS = "enable_eis"
const val ENABLE_60FPS = "enable_60fps"
const val SCAN = "scan"
const val SCAN_ALL_CODES = "scan_all_codes"
const val SAVE_IMAGE_AS_PREVIEW = "save_image_as_preview"
Expand Down Expand Up @@ -137,6 +139,8 @@ class CamConfig(private val mActivity: MainActivity) {

const val ENABLE_EIS = true

const val ENABLE_60FPS = false

const val SCAN_ALL_CODES = false

const val SAVE_IMAGE_AS_PREVIEW = false
Expand Down Expand Up @@ -441,6 +445,18 @@ class CamConfig(private val mActivity: MainActivity) {
mActivity.settingsDialog.enableEISToggle.isChecked = value
}

var enable60fps: Boolean
get() {
return mActivity.settingsDialog.enable60fpsToggle.isChecked
}
set(value) {
val editor = commonPref.edit()
editor.putBoolean(SettingValues.Key.ENABLE_60FPS, value)
editor.apply()

mActivity.settingsDialog.enable60fpsToggle.isChecked = value
}

var enableZsl: Boolean
get() {
return commonPref.getBoolean(
Expand Down Expand Up @@ -750,6 +766,13 @@ class CamConfig(private val mActivity: MainActivity) {
)
}

if (!commonPref.contains(SettingValues.Key.ENABLE_60FPS)) {
editor.putBoolean(
SettingValues.Key.ENABLE_60FPS,
SettingValues.Default.ENABLE_60FPS
)
}

if (!commonPref.contains(SettingValues.Key.ASPECT_RATIO)) {
editor.putInt(
SettingValues.Key.ASPECT_RATIO,
Expand Down Expand Up @@ -818,6 +841,11 @@ class CamConfig(private val mActivity: MainActivity) {
SettingValues.Default.ENABLE_EIS
)

enable60fps = commonPref.getBoolean(
SettingValues.Key.ENABLE_60FPS,
SettingValues.Default.ENABLE_60FPS
)

allowedFormats.clear()

for (format in BarcodeFormat.values()) {
Expand Down Expand Up @@ -1113,16 +1141,25 @@ class CamConfig(private val mActivity: MainActivity) {
)

@androidx.camera.camera2.interop.ExperimentalCamera2Interop
if (isVideoMode && enableEIS) {
Camera2Interop.Extender(previewBuilder).setCaptureRequestOption(
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
if (isVideoMode) {
val stabilizationMode = if (enableEIS) {
CameraMetadata.CONTROL_VIDEO_STABILIZATION_MODE_ON
)
} else {
Camera2Interop.Extender(previewBuilder).setCaptureRequestOption(
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
} else {
CameraMetadata.CONTROL_VIDEO_STABILIZATION_MODE_OFF
}
Camera2Interop.Extender(previewBuilder).setCaptureRequestOption(
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
stabilizationMode
)

if (enable60fps) {
// is 60 fps toggle is enabled, set target frame rate to 60 FPS
Camera2Interop.Extender(previewBuilder)
.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
Range<Int>(60, 60)
)
}
}

preview = previewBuilder.build().also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class VideoCapturer(private val mActivity: MainActivity) {
mActivity.settingsDialog.includeAudioToggle.isEnabled = false
mActivity.settingsDialog.videoQualitySpinner.isEnabled = false
mActivity.settingsDialog.enableEISToggle.isEnabled = false
mActivity.settingsDialog.enable60fpsToggle.isEnabled = false

mActivity.flipCamIcon.setImageResource(R.drawable.pause)
isPaused = false
Expand Down Expand Up @@ -324,6 +325,7 @@ class VideoCapturer(private val mActivity: MainActivity) {
mActivity.settingsDialog.includeAudioToggle.isEnabled = true
mActivity.settingsDialog.videoQualitySpinner.isEnabled = true
mActivity.settingsDialog.enableEISToggle.isEnabled = true
mActivity.settingsDialog.enable60fpsToggle.isEnabled = true

if (mActivity !is VideoCaptureActivity) {
mActivity.thirdOption.visibility = View.VISIBLE
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/app/grapheneos/camera/ui/SettingsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ class SettingsDialog(val mActivity: MainActivity) :

var includeAudioToggle: SwitchCompat
var enableEISToggle: SwitchCompat
var enable60fpsToggle: SwitchCompat

var selfIlluminationToggle: SwitchCompat

private val timeOptions = mActivity.resources.getStringArray(R.array.time_options)

private var includeAudioSetting: View
private var enableEISSetting: View
private var enable60fpsSetting: View
private var selfIlluminationSetting: View
private var videoQualitySetting: View
private var timerSetting: View
Expand Down Expand Up @@ -316,6 +318,7 @@ class SettingsDialog(val mActivity: MainActivity) :

includeAudioSetting = binding.includeAudioSetting
enableEISSetting = binding.enableEisSetting
enable60fpsSetting = binding.enable60fpsSetting
selfIlluminationSetting = binding.selfIlluminationSetting
videoQualitySetting = binding.videoQualitySetting
timerSetting = binding.timerSetting
Expand All @@ -336,6 +339,14 @@ class SettingsDialog(val mActivity: MainActivity) :
camConfig.startCamera(true)
}

enable60fpsToggle = binding.enable60fpsSwitch
enable60fpsToggle.setOnClickListener {
camConfig.enable60fps = enable60fpsToggle.isChecked
}
enable60fpsToggle.setOnCheckedChangeListener { _, _ ->
camConfig.startCamera(true)
}

window?.setFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
Expand Down Expand Up @@ -375,10 +386,12 @@ class SettingsDialog(val mActivity: MainActivity) :
if (mode == CameraMetadata.CONTROL_VIDEO_STABILIZATION_MODE_ON)
enableEISSetting.visibility = View.VISIBLE
}
enable60fpsSetting.visibility = View.VISIBLE
videoQualitySetting.visibility = View.VISIBLE
} else {
includeAudioSetting.visibility = View.GONE
enableEISSetting.visibility = View.GONE
enable60fpsSetting.visibility = View.GONE
videoQualitySetting.visibility = View.GONE
}

Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,29 @@

</LinearLayout>

<LinearLayout
android:id="@+id/enable_60fps_setting"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingHorizontal="@dimen/settings_dialog_menu_item_horizontal"
android:paddingVertical="@dimen/settings_dialog_menu_item_vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/enable_60fps" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/enable_60fps_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:checked="false" />

</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<string name="grid_toggle">Grid Toggle</string>
<string name="include_audio">Include Audio</string>
<string name="enable_eis">Enable EIS</string>
<string name="enable_60fps">Enable 60 FPS</string>
<string name="video_quality">Video Quality</string>
<string name="optimize_for">Optimize for</string>
<string name="quality">Quality</string>
Expand Down

0 comments on commit 4e2da89

Please sign in to comment.