Commit 6973a854 authored by mistermad's avatar mistermad

- Add speaker profiles

- Bug fix: added language in RecordMetadataLig
- Minor change UI
- Minor bug fix
parent e10cb60b
...@@ -45,13 +45,14 @@ dependencies { ...@@ -45,13 +45,14 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
//exclude module: 'support-v4' //exclude module: 'support-v4'
}) })
compile ('com.android.support:appcompat-v7:25.3.1') { compile('com.android.support:appcompat-v7:25.3.1') {
//exclude module: 'support-annotations' //exclude module: 'support-annotations'
} }
compile "com.android.support:support-core-utils:25.3.1" compile project(path: ':library')
compile 'com.android.support:support-core-utils:25.3.1'
compile 'com.google.android.gms:play-services:10.2.1' compile 'com.google.android.gms:play-services:10.2.1'
compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
compile 'javax.annotation:javax.annotation-api:1.2' compile 'javax.annotation:javax.annotation-api:1.2'
compile project(path: ':library') compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
} }
This diff is collapsed.
...@@ -99,12 +99,7 @@ public class Speaker extends FileModel { ...@@ -99,12 +99,7 @@ public class Speaker extends FileModel {
* *
* @return A String object. * @return A String object.
*/ */
public String getName() { public String getName() {return (name != null)? name: "";}
if (name == null) {
return "";
}
return name;
}
/** /**
* Gets the list of languages associated with the Speaker. * Gets the list of languages associated with the Speaker.
...@@ -146,9 +141,7 @@ public class Speaker extends FileModel { ...@@ -146,9 +141,7 @@ public class Speaker extends FileModel {
* @return A Bitmap object. * @return A Bitmap object.
* @throws IOException If the image cannot be retrieved. * @throws IOException If the image cannot be retrieved.
*/ */
public Bitmap getImage() throws IOException { public Bitmap getImage() throws IOException {return ImageUtils.retrieveFromFile(getImageFile());}
return ImageUtils.retrieveFromFile(getImageFile());
}
/** /**
* Gets the small version of the Speaker's image. * Gets the small version of the Speaker's image.
...@@ -169,12 +162,9 @@ public class Speaker extends FileModel { ...@@ -169,12 +162,9 @@ public class Speaker extends FileModel {
* @return A Bitmap object. * @return A Bitmap object.
* @throws IOException If the image cannot be retrieved. * @throws IOException If the image cannot be retrieved.
*/ */
public static Bitmap getSmallImage(String verName, String ownerAccount, public static Bitmap getSmallImage(String verName, String ownerAccount, String speakerId) throws IOException {
String speakerId) throws IOException {
File ownerDir = FileIO.getOwnerPath(verName, ownerAccount); File ownerDir = FileIO.getOwnerPath(verName, ownerAccount);
return ImageUtils.retrieveFromFile( return ImageUtils.retrieveFromFile(new File(getSpeakersPath(ownerDir), speakerId + "/" + speakerId + "-image-small.jpg"));
new File(getSpeakersPath(ownerDir),
speakerId + "/" + speakerId + "-image-small.jpg"));
} }
...@@ -202,7 +192,7 @@ public class Speaker extends FileModel { ...@@ -202,7 +192,7 @@ public class Speaker extends FileModel {
*/ */
public static JSONArray encodeList(List<Speaker> speakers) { public static JSONArray encodeList(List<Speaker> speakers) {
JSONArray speakerArray = new JSONArray(); JSONArray speakerArray = new JSONArray();
for (Speaker speaker : speakers) for(Speaker speaker : speakers)
speakerArray.add(speaker.getId()); speakerArray.add(speaker.getId());
return speakerArray; return speakerArray;
} }
...@@ -214,9 +204,9 @@ public class Speaker extends FileModel { ...@@ -214,9 +204,9 @@ public class Speaker extends FileModel {
* @return A list of the speakers in the JSONArray * @return A list of the speakers in the JSONArray
*/ */
public static List<String> decodeJSONArray(JSONArray speakerArray) { public static List<String> decodeJSONArray(JSONArray speakerArray) {
List<String> speakerIDs = new ArrayList<String>(); List<String> speakerIDs = new ArrayList<>();
if(speakerArray != null) if(speakerArray != null)
for (Object speakerObj : speakerArray) for(Object speakerObj : speakerArray)
speakerIDs.add(((String) speakerObj)); speakerIDs.add(((String) speakerObj));
return speakerIDs; return speakerIDs;
} }
...@@ -249,11 +239,10 @@ public class Speaker extends FileModel { ...@@ -249,11 +239,10 @@ public class Speaker extends FileModel {
String id) throws IOException { String id) throws IOException {
File ownerDir = FileIO.getOwnerPath(verName, ownerAccount); File ownerDir = FileIO.getOwnerPath(verName, ownerAccount);
JSONObject jsonObj = FileIO.readJSONObject( JSONObject jsonObj = FileIO.readJSONObject(new File(getSpeakersPath(ownerDir), id + "/" + id + METADATA_SUFFIX));
new File(getSpeakersPath(ownerDir), id + "/" + id + METADATA_SUFFIX));
String name = (String) jsonObj.get("name"); String name = (String) jsonObj.get("name");
JSONArray languageArray = (JSONArray) jsonObj.get("languages"); JSONArray languageArray = (JSONArray) jsonObj.get("languages");
if (languageArray == null) if(languageArray == null)
throw new IOException("Null languages in the JSON file."); throw new IOException("Null languages in the JSON file.");
List<Language> languages = Language.decodeJSONArray(languageArray); List<Language> languages = Language.decodeJSONArray(languageArray);
String versionName = (String) jsonObj.get("version"); String versionName = (String) jsonObj.get("version");
...@@ -261,7 +250,7 @@ public class Speaker extends FileModel { ...@@ -261,7 +250,7 @@ public class Speaker extends FileModel {
return new Speaker(name, languages, id, versionName, ownerId); return new Speaker(name, languages, id, versionName, ownerId);
} }
/** /* *
* Read all users from file * Read all users from file
* *
* @return A list of the users found in the users directory. * @return A list of the users found in the users directory.
...@@ -362,9 +351,9 @@ public class Speaker extends FileModel { ...@@ -362,9 +351,9 @@ public class Speaker extends FileModel {
* false otherwise. * false otherwise.
*/ */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) return false; if(obj == null) return false;
if (obj == this) return true; if(obj == this) return true;
if (obj.getClass() != getClass()) return false; if(obj.getClass() != getClass()) return false;
Speaker rhs = (Speaker) obj; Speaker rhs = (Speaker) obj;
return new EqualsBuilder() return new EqualsBuilder()
.append(id, rhs.id).append(name, rhs.name) .append(id, rhs.id).append(name, rhs.name)
...@@ -425,9 +414,8 @@ public class Speaker extends FileModel { ...@@ -425,9 +414,8 @@ public class Speaker extends FileModel {
* associated with the Speaker. * associated with the Speaker.
* @throws IllegalArgumentException If the language list is null * @throws IllegalArgumentException If the language list is null
*/ */
private void setLanguages(List<Language> languages) throws private void setLanguages(List<Language> languages) throws IllegalArgumentException {
IllegalArgumentException { if(languages == null)
if (languages == null)
throw new IllegalArgumentException("Speaker languages cannot be null."); throw new IllegalArgumentException("Speaker languages cannot be null.");
this.languages = languages; this.languages = languages;
} }
...@@ -444,7 +432,8 @@ public class Speaker extends FileModel { ...@@ -444,7 +432,8 @@ public class Speaker extends FileModel {
* @param _flags Unused additional flags about how the object should be * @param _flags Unused additional flags about how the object should be
* written. * written.
*/ */
public void writeToParcel(Parcel out, int _flags) { public void writeToParcel(Parcel out, int _flags)
{
out.writeString(versionName); out.writeString(versionName);
out.writeString(ownerId); out.writeString(ownerId);
out.writeString(id.toString()); out.writeString(id.toString());
...@@ -455,8 +444,8 @@ public class Speaker extends FileModel { ...@@ -455,8 +444,8 @@ public class Speaker extends FileModel {
/** /**
* Generates instances of a Speaker from a parcel. * Generates instances of a Speaker from a parcel.
*/ */
public static final Parcelable.Creator<Speaker> CREATOR = public static final Parcelable.Creator<Speaker> CREATOR = new Parcelable.Creator<Speaker>()
new Parcelable.Creator<Speaker>() { {
public Speaker createFromParcel(Parcel in) { public Speaker createFromParcel(Parcel in) {
return new Speaker(in); return new Speaker(in);
} }
...@@ -470,17 +459,19 @@ public class Speaker extends FileModel { ...@@ -470,17 +459,19 @@ public class Speaker extends FileModel {
* *
* @param in The parcel representing the Speaker to be constructed. * @param in The parcel representing the Speaker to be constructed.
*/ */
public Speaker(Parcel in) { public Speaker(Parcel in)
{
super(in); super(in);
setId(in.readString()); setId(in.readString());
setName(in.readString()); setName(in.readString());
List<Language> languages = new ArrayList<Language>(); List<Language> languages = new ArrayList<>();
in.readTypedList(languages, Language.CREATOR); in.readTypedList(languages, Language.CREATOR);
setLanguages(languages); setLanguages(languages);
} }
// Creates a purely numeric speaker ID // Creates a purely numeric speaker ID
private String createId(String name) { private String createId(String name)
{
// Generate 12 random uppercase alphabets. // Generate 12 random uppercase alphabets.
return IdUtils.sampleFromAlphabet(12, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); return IdUtils.sampleFromAlphabet(12, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
} }
...@@ -488,10 +479,11 @@ public class Speaker extends FileModel { ...@@ -488,10 +479,11 @@ public class Speaker extends FileModel {
// Extracts the first character of each token in a string and uppercases, but // Extracts the first character of each token in a string and uppercases, but
// stops after 4 characters have been extracted. // stops after 4 characters have been extracted.
// Never use // Never use
private String extractInitials(String name) { /*private String extractInitials(String name) {
StringBuilder initials = new StringBuilder(); StringBuilder initials = new StringBuilder();
int count = 0; int count = 0;
for (String token : name.split("\\s+")) { for (String token : name.split("\\s+"))
{
if (token.length() > 0) { if (token.length() > 0) {
initials.append(Character.toUpperCase(token.charAt(0))); initials.append(Character.toUpperCase(token.charAt(0)));
count += 1; count += 1;
...@@ -502,7 +494,7 @@ public class Speaker extends FileModel { ...@@ -502,7 +494,7 @@ public class Speaker extends FileModel {
if(BuildConfig.DEBUG)Log.i("extractInitials", "Extracting initials of: " + name + ". " + if(BuildConfig.DEBUG)Log.i("extractInitials", "Extracting initials of: " + name + ". " +
"Returning " + initials.toString()); "Returning " + initials.toString());
return initials.toString(); return initials.toString();
} }*/
/** /**
* The name of the Speaker. * The name of the Speaker.
......
package org.getalp.ligaikuma.lig_aikuma.model;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataLig;
import java.util.ArrayList;
public class SpeakerProfile
{
public static String TAG = "SpeakerProfile";
private String _name;
private int _birthYear;
private int _gender;
private Language _recordLang;
private Language _motherTongue;
private ArrayList<Language> _otherLanguages;
private String _region;
private String _note;
/** Build profile with all informations
*
* @param name speaker name
* @param birthYear speaker birth year
* @param gender gender of speaker
* @param recordLang language of record
* @param motherTongue mother tongue of speaker
* @param otherLanguages other tongue of speaker
* @param region region of record
* @param note free field for annotation
*/
public SpeakerProfile(String name, int birthYear, int gender, Language recordLang, Language motherTongue,
ArrayList<Language> otherLanguages, String region, String note)
{
init(name, birthYear, gender, recordLang, motherTongue, otherLanguages, region, note);
}
/** Build new profile with key and context
*
* @param c Current context to access to SharedPreferences
* @param key key of profile
*/
public SpeakerProfile(Context c, String key)
{
SharedPreferences sp = c.getSharedPreferences(key, Context.MODE_PRIVATE);
String[] tmpL = sp.getString("recordLang"," : ").split(" : ");
Language recordLang = new Language(tmpL[0],tmpL[1]);
tmpL = sp.getString("motherTongue"," : ").split(" : ");
Language motherTongue = new Language(tmpL[0],tmpL[1]);
ArrayList<Language> otherLanguages = new ArrayList<>();
String t = sp.getString("otherLanguages", null);
if(t != null)
for(String tmpS : t.split("§§"))
{
tmpL = tmpS.split(" : ");
otherLanguages.add(new Language(tmpL[0],tmpL[1]));
}
init(sp.getString("name",""), sp.getInt("birdthYear",0), sp.getInt("gender",2),
recordLang, motherTongue, otherLanguages, sp.getString("region",""), sp.getString("note",""));
}
private void init(String name, int birthYear, int gender, Language recordLang, Language motherTongue,
ArrayList<Language> otherLanguages, String region, String note)
{
_name = name;
_birthYear = birthYear;
_gender = gender;
_recordLang = recordLang;
_motherTongue = motherTongue;
_otherLanguages = otherLanguages;
_region = region;
_note = note;
}
/**
*
* @return Key used for SharedPreferences
*/
public String getKey()
{
return _name+"_"+_recordLang.getCode();//+"_"+new SimpleDateFormat("yyMMdd").format(new Date());
}
/** Checks if key exists in SharedPreferences
*
* @param c Current context to access to SharedPreferences
* @param key key of profile
* @return true if key exist, false otherwise
*/
public boolean keyExist(Context c, String key)
{
return c.getSharedPreferences("_master_speaker_keys", Context.MODE_PRIVATE).getString("_all_keys",null).contains(key);
}
/** save current profile on SharedPreferences
*
* @param c Current context to access to SharedPreferences
*/
public SpeakerProfile saveOnSharedPreferences(Context c)
{
String key = getKey();
if(keyExist(c, key)) removeProfile(c, key);
SharedPreferences.Editor edit = c.getSharedPreferences(key, Context.MODE_PRIVATE).edit();
edit.putString("name", _name)
.putInt("birdthYear", _birthYear)
.putInt("gender", _gender)
.putString("recordLang", _recordLang.toString())
.putString("region", _region)
.putString("note", _note);
if(_motherTongue!=null) edit.putString("motherTongue", _motherTongue.toString());
String l="";
for(int i=0;i<_otherLanguages.size();i++)
{
if(i!=0) l+="§§";
l+=_otherLanguages.get(i).toString();
}
edit.putString("otherLanguages", l).apply();
// Save on key register
SharedPreferences sp = c.getSharedPreferences("_master_speaker_keys", Context.MODE_PRIVATE);
String s = sp.getString("_all_keys","");
if(!s.isEmpty()) s+="§§";
sp.edit().putString("_all_keys",s+getKey()).apply();
return this;
}
/**
*
* @param c Current context to access to SharedPreferences
* @param key key of profile
*/
public static void removeProfile(Context c, String key)
{
// Remove data of preferance
c.getSharedPreferences(key, Context.MODE_PRIVATE).edit().clear().apply();
// Remove key
SharedPreferences sp = c.getSharedPreferences("_master_speaker_keys", Context.MODE_PRIVATE);
String t = sp.getString("_all_keys","").replace(key,"");
while(t.contains("§§§§")) t=t.replace("§§§§","§§");
sp.edit().putString("_all_keys",((t.equals("§§"))?"":t)).apply();
}
/** Create new profile from profile key
*
* @param c Current context to access to SharedPreferences
* @param key key of profile
* @return Speaker profile
*/
public static SpeakerProfile importFromSharedPreferences(Context c, String key)
{
SharedPreferences sp = c.getSharedPreferences(key, Context.MODE_PRIVATE);
String[] tmpL = sp.getString("recordLang"," : ").split(" : ");
Language recordLang = new Language(tmpL[0],tmpL[1]);
tmpL = sp.getString("motherTongue"," : ").split(" : ");
Language motherTongue = new Language(tmpL[0],tmpL[1]);
ArrayList<Language> otherLanguages = new ArrayList<>();
String t = sp.getString("otherLanguages", null);
if(t != null && !t.isEmpty()) {
Log.d(TAG, "otherLanguages = "+t);
for(String tmpS : t.split("§§")) {
tmpL = tmpS.split(" : ");
otherLanguages.add(new Language(tmpL[0], tmpL[1]));
}
}
return new SpeakerProfile(sp.getString("name",""), sp.getInt("birdthYear",0), sp.getInt("gender",RecordingMetadataLig.GENDER_UNSPECIFIED),
recordLang, motherTongue, otherLanguages, sp.getString("region",""), sp.getString("note",""));
}
/** Get all speaker key
*
* @param c Curent context to access to SharedPreferences
* @return Return all key, null is it's empty
*/
public static String[] getAllKeys(Context c)
{
//c.getSharedPreferences("_master_speaker_keys", Context.MODE_PRIVATE).edit().putString("_all_keys","").apply();
String t = c.getSharedPreferences("_master_speaker_keys", Context.MODE_PRIVATE).getString("_all_keys",null);
Log.d(TAG, t.replace("§§", " | "));
return (t!=null&&!t.isEmpty())? t.split("§§"): null;
}
/** get String to display it
*
* @return String serialization of SpeakerProfil to display it
*/
public String toString()
{
String r = _name+" | ";
r+= _birthYear+" | ";
switch(_gender)
{
case RecordingMetadataLig.GENDER_MALE: r+= "Male | "; break;
case RecordingMetadataLig.GENDER_FEMALE: r+= "Female | "; break;
case RecordingMetadataLig.GENDER_UNSPECIFIED: r+= "Unspecified | "; break;
}
r+= _recordLang.toString()+" | ";
r+= ((_motherTongue!=null)?_motherTongue.toString():"")+" | ";
if(_otherLanguages!=null) for(Language l : _otherLanguages) r+= l.toString()+" | ";
return r+_region+" | "+_note;
}
// ######################################
// # GETTERS #
// ######################################
public String getName() {return _name;}
public String getRegion() {return _region;}
public String getNote() {return _note;}
public int getBirthYear() {return _birthYear;}
public int getGender() {return _gender;}
public Language getRecordLang() {return _recordLang;}
public Language getMotherTongue() {return _motherTongue;}
public ArrayList<Language> getOtherLanguages() {return _otherLanguages;}
}
\ No newline at end of file
...@@ -286,7 +286,7 @@ public class CheckTranscription extends AikumaActivity { ...@@ -286,7 +286,7 @@ public class CheckTranscription extends AikumaActivity {
//allocation of the player to the fragment //allocation of the player to the fragment
fragment.setPlayer(player); fragment.setPlayer(player);
} catch (IOException e) { } catch (IOException e) {
Toast.makeText(this, R.string.the_corresponding_audio_file_is_unobtainable_please_proceed_to_next_transcript, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.the_audio_file_is_unobtainable_please_proceed_to_the_next_transcript, Toast.LENGTH_LONG).show();
transcriptOK.setEnabled(false); transcriptOK.setEnabled(false);
} }
} else { } else {
......
...@@ -66,8 +66,7 @@ public class ListenFragment extends Fragment implements OnClickListener { ...@@ -66,8 +66,7 @@ public class ListenFragment extends Fragment implements OnClickListener {
seekBar.setOnSeekBarChangeListener( seekBar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() { new SeekBar.OnSeekBarChangeListener() {
int originalProgress; int originalProgress;
public void onProgressChanged(SeekBar seekBar, public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int progress, boolean fromUser) {
if (fromUser) if (fromUser)
seekBar.setProgress(originalProgress); seekBar.setProgress(originalProgress);
} }
...@@ -89,25 +88,20 @@ public class ListenFragment extends Fragment implements OnClickListener { ...@@ -89,25 +88,20 @@ public class ListenFragment extends Fragment implements OnClickListener {
new SeekBar.OnSeekBarChangeListener() { new SeekBar.OnSeekBarChangeListener() {
int prog; int prog;
boolean isPlayed = false; boolean isPlayed = false;
public void onProgressChanged(SeekBar seekBar, public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int progress, boolean fromUser) { if(!fromUser) return;
if (fromUser) { if(player.isPlaying())
if (player.isPlaying()) { {
pause (); pause ();
isPlayed = true; isPlayed = true;
} }
prog = progress; prog = progress;
} }
}
public void onStopTrackingTouch(SeekBar _seekBar) { public void onStopTrackingTouch(SeekBar _seekBar) {
player.seekToMsec((int)Math.round( player.seekToMsec(Math.round((((float)prog)/100)* player.getDurationMsec()));
(((float)prog)/100)* if(!isPlayed) return;
player.getDurationMsec())); isPlayed = false;
play ();
if (isPlayed) {
isPlayed = false;
play ();
}
} }
public void onStartTrackingTouch(SeekBar _seekBar) {}; public void onStartTrackingTouch(SeekBar _seekBar) {};
}); });
...@@ -129,7 +123,7 @@ public class ListenFragment extends Fragment implements OnClickListener { ...@@ -129,7 +123,7 @@ public class ListenFragment extends Fragment implements OnClickListener {