Improve regex
This commit is contained in:
parent
98fec45f4f
commit
8c483824b8
@ -57,8 +57,8 @@ class MatchActivity : AppCompatActivity() {
|
|||||||
val player1Name = getStringExtra("player1Name")
|
val player1Name = getStringExtra("player1Name")
|
||||||
val player2Name = getStringExtra("player2Name")
|
val player2Name = getStringExtra("player2Name")
|
||||||
players = listOf(
|
players = listOf(
|
||||||
Player(player1Name, 0, Pattern.compile(getString(R.string.pattern, player1Name))),
|
Player(player1Name, 0),
|
||||||
Player(player2Name, 0, Pattern.compile(getString(R.string.pattern, player2Name)))
|
Player(player2Name, 0)
|
||||||
)
|
)
|
||||||
serviceSide = getIntExtra("starterId", 0)
|
serviceSide = getIntExtra("starterId", 0)
|
||||||
relaunchSide = when(serviceSide) {
|
relaunchSide = when(serviceSide) {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package adrienmalin.pingpoints
|
package adrienmalin.pingpoints
|
||||||
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
data class Player (
|
data class Player (
|
||||||
var name: String,
|
var name: String,
|
||||||
var score: Int,
|
var score: Int
|
||||||
var pattern: Pattern? = null
|
)
|
||||||
)
|
|
||||||
|
@ -11,11 +11,10 @@ import android.speech.RecognitionListener
|
|||||||
import android.speech.RecognizerIntent
|
import android.speech.RecognizerIntent
|
||||||
import android.speech.SpeechRecognizer
|
import android.speech.SpeechRecognizer
|
||||||
import android.support.v4.app.DialogFragment
|
import android.support.v4.app.DialogFragment
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import java.util.*
|
import java.util.regex.Pattern
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
@ -26,6 +25,7 @@ class SttDialog : DialogFragment() {
|
|||||||
var icStt: ImageView? = null
|
var icStt: ImageView? = null
|
||||||
var stt: SpeechRecognizer? = null
|
var stt: SpeechRecognizer? = null
|
||||||
var sttIntent: Intent? = null
|
var sttIntent: Intent? = null
|
||||||
|
var pattern: Pattern? = null
|
||||||
|
|
||||||
inner class SttListener : RecognitionListener {
|
inner class SttListener : RecognitionListener {
|
||||||
val ERROR_NOT_UNDERSTOOD = 1
|
val ERROR_NOT_UNDERSTOOD = 1
|
||||||
@ -51,12 +51,18 @@ class SttDialog : DialogFragment() {
|
|||||||
matchModel?.apply {
|
matchModel?.apply {
|
||||||
for (result in results) {
|
for (result in results) {
|
||||||
partialResultsTextView?.text = result
|
partialResultsTextView?.text = result
|
||||||
for (player in players) {
|
pattern?.apply{
|
||||||
if (player.pattern?.matcher(result)?.find() == true) {
|
val matcher = matcher(result)
|
||||||
dismiss()
|
if (matcher.matches()) {
|
||||||
updateScore(player)
|
val name_found = matcher.group(1)
|
||||||
updateUI()
|
for (player in players) {
|
||||||
return
|
if (name_found == player.name) {
|
||||||
|
dismiss()
|
||||||
|
updateScore(player)
|
||||||
|
updateUI()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,6 +122,7 @@ class SttDialog : DialogFragment() {
|
|||||||
showPopUp(R.string.STT_unavailable)
|
showPopUp(R.string.STT_unavailable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pattern = Pattern.compile(getString(R.string.pattern), Pattern.CASE_INSENSITIVE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
<string name="share_subject">Match Ping Points : %s contre %s</string>
|
<string name="share_subject">Match Ping Points : %s contre %s</string>
|
||||||
<string name="share_message">"%s contre %s:\n%s a gagné par %d à %d\nPing Points est disponible sur Google Play"</string>
|
<string name="share_message">"%s contre %s:\n%s a gagné par %d à %d\nPing Points est disponible sur Google Play"</string>
|
||||||
<string name="match_point">Balle de match</string>
|
<string name="match_point">Balle de match</string>
|
||||||
<string name="STT_hint">Dîtes : \"point %s\"\nou \"point %s\"</string>
|
<string name="STT_hint">Dîtes : \"Point pour %s\"\nou \"Point pour %s\"</string>
|
||||||
<string name="pattern">(?i:(point|.) %s)</string>
|
<string name="pattern">point pour (.+)</string>
|
||||||
<string name="not_understood">Pouvez-vous répéter ?</string>
|
<string name="not_understood">Pouvez-vous répéter ?</string>
|
||||||
<string name="STT_disabled">Reconnaissance vocale désactivée.</string>
|
<string name="STT_disabled">Reconnaissance vocale désactivée.</string>
|
||||||
</resources>
|
</resources>
|
@ -37,8 +37,8 @@
|
|||||||
<string name="share_subject">Ping Points Match: %s vs. %s</string>
|
<string name="share_subject">Ping Points Match: %s vs. %s</string>
|
||||||
<string name="share_message">%s vs. %s:\n%s won by %d to %d\nGet Ping Points on Google Play</string>
|
<string name="share_message">%s vs. %s:\n%s won by %d to %d\nGet Ping Points on Google Play</string>
|
||||||
<string name="match_point">Match point</string>
|
<string name="match_point">Match point</string>
|
||||||
<string name="STT_hint">Say: \"point %s\"\nor \"point %s\"</string>
|
<string name="STT_hint">Say: \"Point for %s\"\nor \"Point for %s\"</string>
|
||||||
<string name="pattern">(?i:(point|.) %s)</string>
|
<string name="pattern">point for (.+)</string>
|
||||||
<string name="not_understood">Can you repeat, please?</string>
|
<string name="not_understood">Can you repeat, please?</string>
|
||||||
<string name="score" translatable="false">%d - %d</string>
|
<string name="score" translatable="false">%d - %d</string>
|
||||||
<string name="STT_disabled">Voice recognition disabled.</string>
|
<string name="STT_disabled">Voice recognition disabled.</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user