Add an auto-send button to sounder, to optionally batch up a message
This commit is contained in:
parent
2cdc7d75cd
commit
9fcc87963e
4 changed files with 54 additions and 4 deletions
|
@ -3,6 +3,11 @@ package es.eoinrul.ecwt
|
|||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.Button
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -24,6 +29,21 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio
|
|||
mKeyboardInput = findViewById<EditText>(R.id.sounderInput)
|
||||
mKeyboardInput?.addTextChangedListener(mInputHandler)
|
||||
mKeyboardInput?.requestFocus()
|
||||
mKeyboardInput?.setOnEditorActionListener { textView, actionId, keyEvent ->
|
||||
if(!mAutoSend && (actionId == EditorInfo.IME_ACTION_SEND ||
|
||||
(actionId == EditorInfo.IME_NULL && keyEvent.keyCode == KeyEvent.KEYCODE_ENTER) ) ) {
|
||||
mUserTriggeredSend = true
|
||||
mKeyboardInput!!.isEnabled = false
|
||||
ensurePlaying()
|
||||
}
|
||||
mAutoSend
|
||||
}
|
||||
|
||||
var autoSendCheck = findViewById<CheckBox>(R.id.autoSendCheck);
|
||||
autoSendCheck.setOnCheckedChangeListener { compoundButton, _ ->
|
||||
mAutoSend = compoundButton.isChecked
|
||||
}
|
||||
autoSendCheck.isChecked = mAutoSend
|
||||
|
||||
initSoundPlayer()
|
||||
}
|
||||
|
@ -47,6 +67,8 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio
|
|||
mSpaceDurationMs = (mSoundPlayer!!.durationOf(listOf(SoundTypes.LETTER_SPACE)) * 1000).toLong()
|
||||
}
|
||||
|
||||
private var mAutoSend : Boolean = true
|
||||
private var mUserTriggeredSend : Boolean = false
|
||||
private var mPreviouslySentText : TextView? = null
|
||||
private var mCurrentlySendingText : TextView? = null
|
||||
private var mKeyboardInput : EditText? = null
|
||||
|
@ -87,7 +109,8 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio
|
|||
|
||||
mSoundAwaitingText = true
|
||||
runOnUiThread {
|
||||
if( mKeyboardInput?.text!!.isNotEmpty() && mSoundAwaitingText ) {
|
||||
if( (mAutoSend || mUserTriggeredSend) &&
|
||||
mKeyboardInput?.text!!.isNotEmpty() && mSoundAwaitingText ) {
|
||||
mSoundAwaitingText = false
|
||||
// Extract and remove the first character
|
||||
val firstInput = mKeyboardInput!!.text!!.subSequence(0, 1).toString()
|
||||
|
@ -112,6 +135,13 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio
|
|||
mPreviouslySentText?.text = mPreviouslySentText?.text!!.substring(trimFrom,
|
||||
mPreviouslySentText?.text!!.length) + extraSpace + firstInput
|
||||
|
||||
// Re-enable the send button if this was the last character to go
|
||||
if (mUserTriggeredSend && mKeyboardInput!!.text.isEmpty()) {
|
||||
mKeyboardInput!!.isEnabled = true
|
||||
mKeyboardInput!!.requestFocus()
|
||||
mUserTriggeredSend = false
|
||||
}
|
||||
|
||||
// Then play the sound:
|
||||
mSoundPlayer?.enqueue(sequence)
|
||||
}
|
||||
|
|
|
@ -32,18 +32,34 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/sentText" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/inputContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/keyedText" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/sounderInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="15"
|
||||
android:ems="10"
|
||||
android:textSize="36sp"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="text|textNoSuggestions"
|
||||
android:textSize="36sp"
|
||||
tools:layout_editor_absoluteX="99dp"
|
||||
tools:layout_editor_absoluteY="53dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/autoSendCheck"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="@string/auto_send"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/inputContainer" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -55,6 +55,7 @@
|
|||
to move on to the next character.
|
||||
</string>
|
||||
<string name="add_spaces_tip">Be sure to add spaces between the words!</string>
|
||||
<string name="auto_send">Auto send</string>
|
||||
|
||||
<string-array name="tone_frequency_strings">
|
||||
<item>400Hz</item>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
Fixed bug where duration of lessons was too long
|
||||
Added tip if users didn't add spaces to lesson input
|
||||
Improved "Sounder" UI. Now shows some history and upcoming text.
|
||||
Improved "Sounder" UI.
|
||||
Shows user the progress and upcoming text.
|
||||
Add an "auto-send" checkbox, allowing writing a message
|
||||
and sending all in one go.
|
||||
|
|
Loading…
Reference in a new issue