Skip to content

Commit

Permalink
Aperture: SettingsActivity: Only two-way gestures can invert buttons
Browse files Browse the repository at this point in the history
Change-Id: I05b31ccf1a458d1051b09d51fd6f34c8e7c349ab
  • Loading branch information
SebaUbuntu committed Sep 7, 2024
1 parent cde40a1 commit 3f3c736
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/org/lineageos/aperture/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.lineageos.aperture

import android.hardware.input.InputManager
import android.os.Bundle
import android.util.Log
import android.view.KeyCharacterMap
import android.view.LayoutInflater
import android.view.MenuItem
Expand All @@ -32,6 +33,7 @@ import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.MaterialToolbar
import org.lineageos.aperture.ext.gestureActionToString
import org.lineageos.aperture.ext.setOffset
import org.lineageos.aperture.ext.stringToGestureAction
import org.lineageos.aperture.models.HardwareKey
import org.lineageos.aperture.utils.CameraSoundsUtils
import org.lineageos.aperture.utils.PermissionsUtils
Expand Down Expand Up @@ -276,6 +278,26 @@ class SettingsActivity : AppCompatActivity(R.layout.activity_settings) {

keyCategory.addPreference(actionPreference)
keyCategory.addPreference(invertPreference)

actionPreference.setOnPreferenceChangeListener { _, newValue ->
val value = newValue as String
val gestureAction = stringToGestureAction(value) ?: run {
Log.wtf(LOG_TAG, "Got invalid gesture action $value")
null
}

val enableInvert = gestureAction?.isTwoWayAction ?: true

invertPreference.isEnabled = enableInvert
if (!enableInvert) {
invertPreference.isChecked = false
}

true
}
actionPreference.onPreferenceChangeListener!!.onPreferenceChange(
actionPreference, actionPreference.value
)
}
}

Expand Down Expand Up @@ -340,4 +362,8 @@ class SettingsActivity : AppCompatActivity(R.layout.activity_settings) {
}

class ProcessingSettingsFragment : SettingsFragment(R.xml.processing_preferences)

companion object {
private val LOG_TAG = SettingsActivity::class.simpleName!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,22 @@ internal val SharedPreferences.videoMirrorMode: VideoMirrorMode
}

// Hardware key preferences
internal fun SharedPreferences.getHardwareKeyAction(
hardwareKey: HardwareKey
) = when (getString("${hardwareKey.sharedPreferencesKeyPrefix}_action", null)) {
internal fun stringToGestureAction(string: String?) = when (string) {
"shutter" -> GestureAction.SHUTTER
"focus" -> GestureAction.FOCUS
"mic_mute" -> GestureAction.MIC_MUTE
"zoom" -> GestureAction.ZOOM
"volume", "default" -> GestureAction.DEFAULT // volume for compat
"nothing" -> GestureAction.NOTHING
else -> hardwareKey.defaultAction
else -> null
}

internal fun SharedPreferences.getHardwareKeyAction(
hardwareKey: HardwareKey
) = stringToGestureAction(
getString("${hardwareKey.sharedPreferencesKeyPrefix}_action", null)
) ?: hardwareKey.defaultAction

internal fun SharedPreferences.getHardwareKeyInvert(
hardwareKey: HardwareKey
) = hardwareKey.isTwoWayKey && getBoolean(
Expand Down

0 comments on commit 3f3c736

Please sign in to comment.