Start on preferences screen
This commit is contained in:
parent
26cc60adf5
commit
cf89b9b4f3
9 changed files with 98 additions and 3 deletions
2
TODO
2
TODO
|
@ -10,6 +10,8 @@ Basic:
|
|||
Polish:
|
||||
* Better user input
|
||||
* Visual styling
|
||||
* Settings info text
|
||||
* Extract UI strings into resource file
|
||||
|
||||
Bonus:
|
||||
* Morse machine
|
||||
|
|
|
@ -46,6 +46,7 @@ dependencies {
|
|||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.0-rc01'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
package com.example.ecwt
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
|
||||
//const val PREFERENCES_FILE = "es.eoinrul.ecwt.PREFERENCES"
|
||||
|
||||
class CWSettingsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_cw_settings)
|
||||
|
||||
// Sounds: WPM; Farnsworth; (character speed versus word speed) Tone freq
|
||||
// Koch: Lesson duration; word size
|
||||
//var preferences = getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,12 +139,13 @@ class DitDahGenerator : MediaDataSource {
|
|||
|
||||
class DitDahGeneratorSettings
|
||||
{
|
||||
val toneFrequency = 650
|
||||
var toneFrequency = 650 //TODO These values are duplicated in the settings fragment
|
||||
var WordsPerMinute = 20;
|
||||
}
|
||||
|
||||
class DitDahSoundStream {
|
||||
constructor(config : DitDahGeneratorSettings) {
|
||||
// Farnsworth timing calculations: https://morsecode.world/international/timing.html
|
||||
//TODO: Compute these properly
|
||||
val ditLengthSeconds = 0.15f;
|
||||
val dahLengthSeconds = ditLengthSeconds * 3.0f;
|
||||
|
|
11
app/src/main/java/com/example/ecwt/SettingsFragment.kt
Normal file
11
app/src/main/java/com/example/ecwt/SettingsFragment.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package com.example.ecwt
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import android.view.KeyEvent
|
|||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
|
||||
class TrainingActivity : AppCompatActivity() {
|
||||
|
||||
|
@ -23,7 +24,7 @@ class TrainingActivity : AppCompatActivity() {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
mSoundPlayer = DitDahSoundStream(DitDahGeneratorSettings())
|
||||
initSoundPlayer()
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +62,12 @@ class TrainingActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun initSoundPlayer() {
|
||||
mSoundPlayer = DitDahSoundStream(DitDahGeneratorSettings())
|
||||
val generatorSettings = DitDahGeneratorSettings()
|
||||
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
generatorSettings.toneFrequency = sharedPreferences.getInt("sender_tone", generatorSettings.toneFrequency)
|
||||
|
||||
mSoundPlayer = DitDahSoundStream(generatorSettings)
|
||||
}
|
||||
|
||||
private var mTextViewTest : TextView? = null;
|
||||
|
|
|
@ -19,4 +19,13 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:layout_editor_absoluteY="16dp" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment"
|
||||
android:name="com.example.ecwt.SettingsFragment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -9,4 +9,18 @@
|
|||
|
||||
<string name="hello_first_fragment">Hello first fragment</string>
|
||||
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
|
||||
<!-- Preference Titles -->
|
||||
<string name="messages_header">Messages</string>
|
||||
<string name="sync_header">Sync</string>
|
||||
|
||||
<!-- Messages Preferences -->
|
||||
<string name="signature_title">Your signature</string>
|
||||
<string name="reply_title">Default reply action</string>
|
||||
|
||||
<!-- Sync Preferences -->
|
||||
<string name="sync_title">Sync email periodically</string>
|
||||
<string name="attachment_title">Download incoming attachments</string>
|
||||
<string name="attachment_summary_on">Automatically download attachments for incoming emails
|
||||
</string>
|
||||
<string name="attachment_summary_off">Only download attachments when manually requested</string>
|
||||
</resources>
|
||||
|
|
43
app/src/main/res/xml/root_preferences.xml
Normal file
43
app/src/main/res/xml/root_preferences.xml
Normal file
|
@ -0,0 +1,43 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<PreferenceCategory app:title="Sender">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="switch_preference_1"
|
||||
android:summary="OMG"
|
||||
android:summaryOff="NOPE"
|
||||
android:summaryOn="YEAH"
|
||||
android:title="Switch preference" />
|
||||
|
||||
<SeekBarPreference
|
||||
android:defaultValue="600"
|
||||
android:max="900"
|
||||
app:defaultValue="650"
|
||||
app:key="sender_tone"
|
||||
app:min="500"
|
||||
app:seekBarIncrement="50"
|
||||
app:showSeekBarValue="true"
|
||||
app:title="Tone Frequency" />
|
||||
|
||||
<SeekBarPreference
|
||||
android:defaultValue="600"
|
||||
android:max="50"
|
||||
app:defaultValue="20"
|
||||
app:key="sender_wpm"
|
||||
app:min="5"
|
||||
app:showSeekBarValue="true"
|
||||
app:title="Words per Minute" />
|
||||
|
||||
<SeekBarPreference
|
||||
android:defaultValue="600"
|
||||
android:max="50"
|
||||
app:defaultValue="20"
|
||||
app:key="sender_effectivewpm"
|
||||
app:min="5"
|
||||
app:showSeekBarValue="true"
|
||||
app:title="Effective Words per Minute" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue