Skip to content

Commit

Permalink
Merge pull request #5 from jogrimst/master
Browse files Browse the repository at this point in the history
#1 Match sound with first sound in words
  • Loading branch information
literacyapp authored Apr 28, 2017
2 parents bb616ec + 3e1b6e9 commit 059be9c
Show file tree
Hide file tree
Showing 28 changed files with 173 additions and 41 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.literacyapp.soundcards"
minSdkVersion 21
targetSdkVersion 23
versionCode 1000000
versionName "1.0.0-SNAPSHOT"
versionCode 1000001
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -39,8 +39,8 @@ dependencies {
})
testCompile 'junit:junit:4.12'

compile 'org.literacyapp:literacyapp-model:1.1.33'
compile 'org.literacyapp:contentprovider:1.0.3'
compile 'org.literacyapp:literacyapp-model:1.1.38'
compile 'org.literacyapp:contentprovider:1.0.5'
compile 'org.greenrobot:greendao:3.2.0'

compile 'com.android.support:appcompat-v7:23.4.0'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</intent-filter>
</activity>
<activity
android:name="org.literacyapp.soundcards.OnsetSoundActivity" />
android:name="org.literacyapp.soundcards.task.OnsetSoundActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.util.Log;

import org.literacyapp.contentprovider.ContentProvider;
import org.literacyapp.soundcards.task.OnsetSoundActivity;

public class MainActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.literacyapp.soundcards;
package org.literacyapp.soundcards.task;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
Expand Down Expand Up @@ -27,12 +27,15 @@
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.contentprovider.model.content.multimedia.Image;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.soundcards.R;
import org.literacyapp.soundcards.util.IpaToAndroidResourceConverter;
import org.literacyapp.soundcards.util.MediaPlayerHelper;
import org.literacyapp.soundcards.util.TtsHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -179,22 +182,45 @@ private void loadNextTask() {
alt1CardView.postDelayed(new Runnable() {
@Override
public void run() {
TtsHelper.speak(getApplicationContext(), "Which word begins with this sound?");
// TtsHelper.speak(getApplicationContext(), "Ni neno lipi linaanza kwa sauti hii?");
final String letter = alt1Word.getText().substring(0, 1);
Log.i(getClass().getName(), "letter: " + letter);

// TtsHelper.speak(getApplicationContext(), getString(R.string.which_word_begins_with_this_sound));
MediaPlayerHelper.play(getApplicationContext(), R.raw.which_word_begins_with_this_sound);

Log.i(getClass().getName(), "alt1Word.getPhonetics(): /" + alt1Word.getPhonetics() + "/");

// TODO: fetch Allophone instead of String
// final String allophoneIpa = alt1Word.getPhonetics().substring(0, 1);
// Temporary hack to handle /ɑ/
final String allophoneIpa = ("sw".equals(Locale.getDefault().getLanguage()) && alt1Word.getText().startsWith("a"))
? "a"
: alt1Word.getPhonetics().substring(0, 1);
Log.i(getClass().getName(), "allophoneIpa: " + allophoneIpa);

// final String androidResourceName = IpaToAndroidResourceConverter.getAndroidResourceName(allophoneIpa);
// Temporary hack to handle /ɑ/
final String androidResourceName = ("sw".equals(Locale.getDefault().getLanguage()) && alt1Word.getText().startsWith("a"))
? "a2"
: IpaToAndroidResourceConverter.getAndroidResourceName(allophoneIpa);
Log.i(getClass().getName(), "androidResourceName: " + androidResourceName);

int pauseBeforePlayingSound = 2500;
if ("sw".equals(Locale.getDefault().getLanguage())) {
pauseBeforePlayingSound = 5000;
}
alt1CardView.postDelayed(new Runnable() {
@Override
public void run() {
playLetterSound(letter);

Log.i(getClass().getName(), "Looking up resource: animated_emoji_u1f603_mouth_" + letter);
int drawableResourceId = getResources().getIdentifier("animated_emoji_u1f603_mouth_" + letter, "drawable", getPackageName());
final Drawable drawable = getDrawable(drawableResourceId);
emojiImageView.setImageDrawable(drawable);
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) emojiImageView.getDrawable();
animatedVectorDrawable.start();
playSound(allophoneIpa);

Log.i(getClass().getName(), "Looking up resource: animated_emoji_u1f603_mouth_" + androidResourceName);
int drawableResourceId = getResources().getIdentifier("animated_emoji_u1f603_mouth_" + androidResourceName, "drawable", getPackageName());
try {
final Drawable drawable = getDrawable(drawableResourceId);
emojiImageView.setImageDrawable(drawable);
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) emojiImageView.getDrawable();
animatedVectorDrawable.start();
} catch (Resources.NotFoundException e) {
Log.w(getClass().getName(), null, e);
}

alt1CardView.postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -310,7 +336,7 @@ public void onClick(View v) {
}
}, 2000);
}
}, 2500);
}, pauseBeforePlayingSound);
}
}, 1000);
}
Expand All @@ -329,12 +355,12 @@ private int parseRgbColor(String input, int alpha) {
}
}

private void playLetterSound(String letter) {
Log.i(getClass().getName(), "playLetterSound");
private void playSound(String ipaValue) {
Log.i(getClass().getName(), "playSound");

// Look up corresponding Audio
Log.d(getClass().getName(), "Looking up \"letter_sound_" + letter + "\"");
Audio audio = ContentProvider.getAudio("letter_sound_" + letter);
Log.d(getClass().getName(), "Looking up \"letter_sound_" + ipaValue + "\"");
Audio audio = ContentProvider.getAudio("letter_sound_" + ipaValue);
Log.i(getClass().getName(), "audio: " + audio);
if (audio != null) {
// Play audio
Expand All @@ -351,18 +377,18 @@ public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.start();
} else {
// Audio not found. Fall-back to application resource.
String audioFileName = "letter_sound_" + letter;
String audioFileName = "letter_sound_" + ipaValue;
int resourceId = getResources().getIdentifier(audioFileName, "raw", getPackageName());
try {
if (resourceId != 0) {
MediaPlayerHelper.play(getApplicationContext(), resourceId);
} else {
// Fall-back to TTS
TtsHelper.speak(getApplicationContext(), letter);
TtsHelper.speak(getApplicationContext(), ipaValue);
}
} catch (Resources.NotFoundException e) {
// Fall-back to TTS
TtsHelper.speak(getApplicationContext(), letter);
TtsHelper.speak(getApplicationContext(), ipaValue);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.literacyapp.soundcards.util;

/**
* Helper class for converting IPA values into a format allowed in an Android file name: [a-z], [0-9], [_]
*/
public class IpaToAndroidResourceConverter {

public static String getAndroidResourceName(String ipaValue) {
String resourceName = ipaValue;

// The number 2 indicates that the X-SAMPA value is upper-case (e.g. 'A' instead of 'a')
if ("ɑ".equals(ipaValue)) {
// X-SAMPA: '}'
resourceName = "ae";
} else if ("ɑ".equals(ipaValue)) {
// X-SAMPA: 'A'
resourceName = "a2";
} else if ("ɛ".equals(ipaValue)) {
// X-SAMPA: 'E'
resourceName = "e2";
}

return resourceName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="@string/u1f603_mouth_neutral"
android:valueTo="@string/u1f603_mouth_e"
android:valueTo="@string/u1f603_mouth_A"
android:valueType="pathType" />
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="@string/u1f603_mouth_neutral"
android:valueTo="@string/u1f603_mouth_a_i"
android:valueTo="@string/u1f603_mouth_ae"
android:valueType="pathType" />
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="@string/u1f603_mouth_neutral"
android:valueTo="@string/u1f603_mouth_o"
android:valueTo="@string/u1f603_mouth_E"
android:valueType="pathType" />
10 changes: 10 additions & 0 deletions app/src/main/res/animator/u1f603_mouth_i.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:interpolator="@android:interpolator/overshoot"
android:propertyName="pathData"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="@string/u1f603_mouth_neutral"
android:valueTo="@string/u1f603_mouth_i"
android:valueType="pathType" />
10 changes: 10 additions & 0 deletions app/src/main/res/animator/u1f603_mouth_t.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:interpolator="@android:interpolator/overshoot"
android:propertyName="pathData"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="@string/u1f603_mouth_neutral"
android:valueTo="@string/u1f603_mouth_t"
android:valueType="pathType" />
10 changes: 10 additions & 0 deletions app/src/main/res/animator/u1f603_mouth_w.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:interpolator="@android:interpolator/overshoot"
android:propertyName="pathData"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="@string/u1f603_mouth_neutral"
android:valueTo="@string/u1f603_mouth_w"
android:valueType="pathType" />
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_a_i" />
android:animation="@animator/u1f603_mouth_a2" />
</animated-vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/animated_emoji_u1f603_mouth_ae.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/emoji_u1f603">

<target
android:name="left_eye"
android:animation="@animator/u1f603_left_eye_laughing" />
<target
android:name="right_eye"
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_ae" />
</animated-vector>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_e" />
android:animation="@animator/u1f603_mouth_e2" />
</animated-vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/animated_emoji_u1f603_mouth_e2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/emoji_u1f603">

<target
android:name="left_eye"
android:animation="@animator/u1f603_left_eye_laughing" />
<target
android:name="right_eye"
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_e2" />
</animated-vector>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_a_i" />
android:animation="@animator/u1f603_mouth_i" />
</animated-vector>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_o" />
android:animation="@animator/u1f603_mouth_t" />
</animated-vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/animated_emoji_u1f603_mouth_w.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/emoji_u1f603">

<target
android:name="left_eye"
android:animation="@animator/u1f603_left_eye_laughing" />
<target
android:name="right_eye"
android:animation="@animator/u1f603_right_eye_laughing" />
<target
android:name="mouth"
android:animation="@animator/u1f603_mouth_w" />
</animated-vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/emoji_u1f603.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<path
android:name="mouth"
android:fillColor="#CC7968CD"
android:pathData="M44.469,82.373 C43.776,83.08 43.642,84.322 53.856,85.23 C45.492,92.214 54.273,96.664 65.027,96.664 C76.661,96.664 73.291,91.673 74.42,85.228 C84.563,84.408 84.383,83.45 83.482,82.708 C80.996,80.663 75.871,83.14 65.408,83.14 C54.542,83.141 47.27,79.518 44.469,82.373 z" />
android:pathData="@string/u1f603_mouth_neutral" />
</group>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_onset_sound.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:id="@+id/emoji"
android:layout_width="match_parent"
android:layout_height="@dimen/emoji_height"
android:src="@drawable/animated_emoji_u1f603_mouth_e" />
android:src="@drawable/animated_emoji_u1f603_mouth_e2" />

<View
android:layout_width="match_parent"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion app/src/main/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="u1f603_mouth_u">M44.469,82.373 C43.776,83.08 43.642,84.322 53.856,85.23 C45.492,92.214 54.273,96.664 65.027,96.664 C76.661,96.664 73.291,91.673 74.42,85.228 C84.563,84.408 84.383,83.45 83.482,82.708 C80.996,80.663 75.871,83.14 65.408,83.14 C54.542,83.141 47.27,79.518 44.469,82.373 z</string>
<string name="app_name">Kadi ya sauti</string>

<string name="which_word_begins_with_this_sound">Ni neno lipi linaanza kwa sauti hii?</string>
</resources>
Loading

0 comments on commit 059be9c

Please sign in to comment.