Merge branch 'master' of https://github.com/adrienmalin/PingPoints
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								.idea/caches/build_file_checksums.ser
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.idea/caches/build_file_checksums.ser
									
									
									
										generated
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -1 +1 @@ | ||||
| [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"2.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] | ||||
| [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":5,"versionName":"2.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] | ||||
| @ -30,7 +30,7 @@ class MatchActivity : AppCompatActivity() { | ||||
|  | ||||
|     inner class SttAfterTts : UtteranceProgressListener() { | ||||
|         override fun onDone(id: String) { | ||||
|             SttDialog().show( supportFragmentManager, "SttDialog") | ||||
|             SttDialog().show(supportFragmentManager, "SttDialog") | ||||
|         } | ||||
|  | ||||
|         override fun onStart(id: String) {} | ||||
| @ -57,8 +57,8 @@ class MatchActivity : AppCompatActivity() { | ||||
|                     val player1Name = getStringExtra("player1Name") | ||||
|                     val player2Name = getStringExtra("player2Name") | ||||
|                     players = listOf( | ||||
|                         Player(player1Name, 0, Pattern.compile(getString(R.string.pattern, player1Name))), | ||||
|                         Player(player2Name, 0, Pattern.compile(getString(R.string.pattern, player2Name))) | ||||
|                         Player(player1Name, 0), | ||||
|                         Player(player2Name, 0) | ||||
|                     ) | ||||
|                     serviceSide = getIntExtra("starterId", 0) | ||||
|                     relaunchSide = when(serviceSide) { | ||||
| @ -69,7 +69,10 @@ class MatchActivity : AppCompatActivity() { | ||||
|                     sttEnabled = getBooleanExtra("enableSTT", false) | ||||
|                     saveState() | ||||
|  | ||||
|                     if (ttsEnabled) tts = TextToSpeech(this@MatchActivity, WaitForTtsInit()) | ||||
|                     if (ttsEnabled) { | ||||
|                         tts = TextToSpeech(this@MatchActivity, WaitForTtsInit()) | ||||
|                         if (sttEnabled) tts?.setOnUtteranceProgressListener(SttAfterTts()) | ||||
|                     } | ||||
|                     if (!sttEnabled) showPopUp(getString(R.string.button_hint)) | ||||
|                 } | ||||
|             } | ||||
| @ -127,10 +130,7 @@ class MatchActivity : AppCompatActivity() { | ||||
|                     if (matchPoint) scoreSpeech += getString(R.string.match_point) | ||||
|                     say(scoreSpeech) | ||||
|                 } | ||||
|                 if (sttEnabled) { | ||||
|                     if (ttsEnabled) tts?.setOnUtteranceProgressListener(SttAfterTts()) | ||||
|                     else SttDialog().show(supportFragmentManager, "SttDialog") | ||||
|                 } | ||||
|                 if (sttEnabled and !ttsEnabled) SttDialog().show(supportFragmentManager, "SttDialog") | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| package adrienmalin.pingpoints | ||||
|  | ||||
| import java.util.regex.Pattern | ||||
|  | ||||
| data class Player ( | ||||
|     var name: String, | ||||
|     var score: Int, | ||||
|     var pattern: Pattern? = null | ||||
|     var score: Int | ||||
| ) | ||||
| @ -11,11 +11,10 @@ import android.speech.RecognitionListener | ||||
| import android.speech.RecognizerIntent | ||||
| import android.speech.SpeechRecognizer | ||||
| import android.support.v4.app.DialogFragment | ||||
| import android.util.Log | ||||
| import android.view.LayoutInflater | ||||
| import android.widget.ImageView | ||||
| import android.widget.TextView | ||||
| import java.util.* | ||||
| import java.util.regex.Pattern | ||||
| import kotlin.math.max | ||||
| import kotlin.math.min | ||||
|  | ||||
| @ -26,6 +25,7 @@ class SttDialog : DialogFragment() { | ||||
|     var icStt: ImageView? = null | ||||
|     var stt: SpeechRecognizer? = null | ||||
|     var sttIntent: Intent? = null | ||||
|     var pattern: Pattern? = null | ||||
|  | ||||
|     inner class SttListener : RecognitionListener { | ||||
|         val ERROR_NOT_UNDERSTOOD = 1 | ||||
| @ -51,8 +51,12 @@ class SttDialog : DialogFragment() { | ||||
|                     matchModel?.apply { | ||||
|                         for (result in results) { | ||||
|                             partialResultsTextView?.text = result | ||||
|                             pattern?.apply{ | ||||
|                                 val matcher = matcher(result) | ||||
|                                 if (matcher.matches()) { | ||||
|                                     val name_found = matcher.group(1) | ||||
|                                     for (player in players) { | ||||
|                                 if (player.pattern?.matcher(result)?.find() == true) { | ||||
|                                         if (name_found == player.name) { | ||||
|                                             dismiss() | ||||
|                                             updateScore(player) | ||||
|                                             updateUI() | ||||
| @ -64,6 +68,8 @@ class SttDialog : DialogFragment() { | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         override fun onResults(data: Bundle) { | ||||
|             partialResultsTextView?.text = getString(R.string.not_understood) | ||||
| @ -99,11 +105,24 @@ class SttDialog : DialogFragment() { | ||||
|                         players[1].name | ||||
|                     ) | ||||
|                     sttIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply { | ||||
|                         putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) | ||||
|                         putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH) | ||||
|                         putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10) | ||||
|                         putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true) | ||||
|                         putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true) | ||||
|                         putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 30000) | ||||
|                     } | ||||
|                     stt = SpeechRecognizer.createSpeechRecognizer(activity).apply { | ||||
|                         setRecognitionListener(SttListener()) | ||||
|                         try { | ||||
|                             stopListening() | ||||
|                             startListening(sttIntent) | ||||
|                         } catch (e: ActivityNotFoundException) { | ||||
|                             sttEnabled = false | ||||
|                             dismiss() | ||||
|                             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_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="STT_hint">Dîtes : \"point %s\"\nou \"point %s\"</string> | ||||
|     <string name="pattern">(?i:(point|.) %s)</string> | ||||
|     <string name="STT_hint">Dîtes : \"Point pour %s\"\nou \"Point pour %s\"</string> | ||||
|     <string name="pattern">point pour (.+)</string> | ||||
|     <string name="not_understood">Pouvez-vous répéter ?</string> | ||||
|     <string name="STT_disabled">Reconnaissance vocale désactivée.</string> | ||||
| </resources> | ||||
| @ -37,8 +37,8 @@ | ||||
|     <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="match_point">Match point</string> | ||||
|     <string name="STT_hint">Say: \"point %s\"\nor \"point %s\"</string> | ||||
|     <string name="pattern">(?i:(point|.) %s)</string> | ||||
|     <string name="STT_hint">Say: \"Point for %s\"\nor \"Point for %s\"</string> | ||||
|     <string name="pattern">point for (.+)</string> | ||||
|     <string name="not_understood">Can you repeat, please?</string> | ||||
|     <string name="score" translatable="false">%d - %d</string> | ||||
|     <string name="STT_disabled">Voice recognition disabled.</string> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user