Skip to content

Commit

Permalink
add play-voice switch
Browse files Browse the repository at this point in the history
adjust the threshold's default value & range
update version number
  • Loading branch information
the0cp committed Jul 25, 2024
1 parent 5499c0d commit 6167799
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
minSdk = 24
//noinspection OldTargetApi
targetSdk = 34
versionCode = 2
versionName = "1.1"
versionCode = 3
versionName = "1.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/the0cp/objection/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import android.util.Log
import android.view.View
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.Switch
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreference
import kotlin.properties.Delegates

class AccelerationDetector(private val sensorManager: SensorManager, private var threshold: Float, private val onAccelerationDetected: () -> Boolean) : SensorEventListener {

Expand Down Expand Up @@ -93,6 +96,8 @@ class MainActivity : AppCompatActivity(){

private lateinit var voicePath: String

private var voiceSwitch by Delegates.notNull<Boolean>()


private fun playAudio(context: Context, filePath: String){
/*
Expand Down Expand Up @@ -209,7 +214,9 @@ class MainActivity : AppCompatActivity(){

val selectedCharacter = preferences.getString("character", "wright")
val selectedVoice = preferences.getString("voice", "igiari")
voicePath = "lines/$selectedCharacter/$selectedVoice.mp3" // concat strings
voicePath = "lines/$selectedCharacter/$selectedVoice.mp3" /* concat strings */

voiceSwitch = preferences.getBoolean("is_voice", true) /* get switch state */

/*
* set splash
Expand All @@ -224,10 +231,14 @@ class MainActivity : AppCompatActivity(){
println(imagePath)




accelerationDetector = AccelerationDetector(sensorManager, threshold) {
accelerationDetector.stopListening()
println(voicePath)
playAudio(this, voicePath)
if(voiceSwitch){
playAudio(this, voicePath)
}
imageView.visibility = View.VISIBLE
handler.postDelayed({
imageView.visibility = View.INVISIBLE
Expand Down Expand Up @@ -277,6 +288,8 @@ class MainActivity : AppCompatActivity(){
val selectedVoice = preferences.getString("voice", "igiari")
voicePath = "lines/$selectedCharacter/$selectedVoice.mp3" // concat strings

voiceSwitch = preferences.getBoolean("is_voice", true) /* get switch state */

/*
* set splash
* */
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

<string name="voice">Voice</string>
<string name="character">Character</string>
<string name="music">Play Music</string>
<string name="is_voice">Play Voice</string>
</resources>
13 changes: 8 additions & 5 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
android:key="voice"
android:title="@string/voice"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:defaultValue="true"
android:key="is_voice"
android:title="@string/is_voice" />
<PreferenceCategory android:title="@string/threshold_header">

</PreferenceCategory>
<SeekBarPreference
android:defaultValue="4"
android:defaultValue="10"
android:key="threshold"
android:max="100"
android:max="50"
android:title="Sensitivity"
app:showSeekBarValue="true" />

Expand All @@ -34,9 +38,8 @@
<PreferenceCategory app:title="@string/about_header"/>

<Preference
android:title="Objection!"
android:summary="the0cp\nver 1.0">
</Preference>
android:summary="Author: the0cp\nVersion: v1.2"
android:title="Objection!"></Preference>
<Preference
android:title="View Source"
android:summary="Open Github">
Expand Down

0 comments on commit 6167799

Please sign in to comment.