Skip to content

Commit

Permalink
0.0.9a
Browse files Browse the repository at this point in the history
- Moved "skip" button at the bottom (Sav22999#5) in Speak and Listen
- Now also Listen section shows sentences
- Fix bug Listen API url
  • Loading branch information
Sav22999 committed Dec 14, 2019
1 parent ed48219 commit 2562b0c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.android.volley.AuthFailureError
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.JsonArrayRequest
Expand All @@ -31,8 +32,7 @@ class ListenActivity : AppCompatActivity() {
private var PRIVATE_MODE = 0
private val LANGUAGE_NAME = "LANGUAGE"
var url: String =
"https://voice.mozilla.org/api/v1/{{*{{lang}}*}}/clips" //API url -> replace {{*{{lang}}*}} with the selected_language || GET request (get recording)
//var url_send: String = "https://voice.mozilla.org/api/v1/{{*{{lang}}*}}/clips" //API url -> replace {{*{{lang}}*}} with the selected_language || POST request (send validating)
"https://voice.mozilla.org/api/v1/{{*{{lang}}*}}/" //API url -> replace {{*{{lang}}*}} with the selected_language

var id_sentence: Int = 0
var text_sentence: String = ""
Expand Down Expand Up @@ -61,8 +61,7 @@ class ListenActivity : AppCompatActivity() {
start_stop_listening.setOnClickListener {
if (this.status == 0 || this.status == 2) {
StartListening() //0->play | 2->re-play
}
else if (this.status == 1)
} else if (this.status == 1)
StopListening()
}

Expand Down Expand Up @@ -104,20 +103,20 @@ class ListenActivity : AppCompatActivity() {
//params.put("")

val que = Volley.newRequestQueue(this)
val req = JsonArrayRequest(Request.Method.GET, url + path, params,
val req = object : JsonArrayRequest(Request.Method.GET, url + path, params,
Response.Listener {
val json_result = it.toString()
if (json_result.length>2) {
if (json_result.length > 2) {
val jsonObj = JSONObject(
json_result.substring(
json_result.indexOf("{"),
json_result.lastIndexOf("}") + 1
)
)
this.id_sentence=jsonObj.getString("id").toInt()
this.text_sentence=jsonObj.getString("text")
this.sound_sentence=jsonObj.getString("sound")
this.glob_sentence=jsonObj.getString("glob")
this.id_sentence = jsonObj.getString("id").toInt()
this.text_sentence = jsonObj.getString("text")
this.sound_sentence = jsonObj.getString("sound")
this.glob_sentence = jsonObj.getString("glob")
//this.text_sentence = json_result//just for testing
sentence.text = this.text_sentence
btnListen.isEnabled = true
Expand All @@ -126,11 +125,23 @@ class ListenActivity : AppCompatActivity() {
} else {
error1()
}

}, Response.ErrorListener {
//println(" -->> Something wrong: "+it.toString()+" <<-- ")
error1()
}
)
) {
@Throws(AuthFailureError::class)
override fun getHeaders(): Map<String, String> {
val headers = HashMap<String, String>()
//it permits to get the audio to validate (just if user doesn't do the log-in/sign-up)
headers.put(
"Authorization",
"Basic MzVmNmFmZTItZjY1OC00YTNhLThhZGMtNzQ0OGM2YTM0MjM3OjNhYzAwMWEyOTQyZTM4YzBiNmQwMWU0M2RjOTk0YjY3NjA0YWRmY2Q="
)
return headers
}
}
que.add(req)
} catch (e: Exception) {
error1()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SpeakActivity : AppCompatActivity() {
val req = JsonArrayRequest(Request.Method.GET, url + path, params,
Response.Listener {
val json_result = it.toString()
if (json_result.length>2) {
if (json_result.length > 2) {
val jsonObj = JSONObject(
json_result.substring(
json_result.indexOf("{"),
Expand Down
15 changes: 8 additions & 7 deletions Common Voice Android/app/src/main/res/layout/activity_listen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="200dp"
android:layout_marginBottom="30dp"
android:background="@drawable/yes_thumb_cv"
android:textColor="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -24,6 +25,7 @@
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginEnd="200dp"
android:layout_marginBottom="30dp"
android:background="@drawable/no_thumb_cv"
android:textColor="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -48,21 +50,21 @@

<Button
android:id="@+id/btn_skip_listen"
android:layout_width="250dp"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/btn_rounded"
android:text="@string/btn_skip_sentence"
android:textColor="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn_start_listen"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="30dp"
android:background="@drawable/listen_cv"
android:textColor="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -86,8 +88,7 @@
android:textSize="30dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_skip_listen" />
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
13 changes: 6 additions & 7 deletions Common Voice Android/app/src/main/res/layout/activity_speak.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@

<Button
android:id="@+id/btn_skip_speak"
android:layout_width="250dp"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/btn_rounded"
android:text="@string/btn_skip_sentence"
android:textColor="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn_start_speak"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="20dp"
android:layout_marginBottom="30dp"
android:background="@drawable/speak_cv"
android:textColor="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -62,7 +61,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_skip_speak" />
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textMessageAlertSpeak"
Expand Down

0 comments on commit 2562b0c

Please sign in to comment.