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 {
exclude group: 'com.android.support', module: 'support-annotations'
//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'
}
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.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
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 {
*
* @return A String object.
*/
public String getName() {
if (name == null) {
return "";
}
return name;
}
public String getName() {return (name != null)? name: "";}
/**
* Gets the list of languages associated with the Speaker.
......@@ -146,9 +141,7 @@ public class Speaker extends FileModel {
* @return A Bitmap object.
* @throws IOException If the image cannot be retrieved.
*/
public Bitmap getImage() throws IOException {
return ImageUtils.retrieveFromFile(getImageFile());
}
public Bitmap getImage() throws IOException {return ImageUtils.retrieveFromFile(getImageFile());}
/**
* Gets the small version of the Speaker's image.
......@@ -169,12 +162,9 @@ public class Speaker extends FileModel {
* @return A Bitmap object.
* @throws IOException If the image cannot be retrieved.
*/
public static Bitmap getSmallImage(String verName, String ownerAccount,
String speakerId) throws IOException {
public static Bitmap getSmallImage(String verName, String ownerAccount, String speakerId) throws IOException {
File ownerDir = FileIO.getOwnerPath(verName, ownerAccount);
return ImageUtils.retrieveFromFile(
new File(getSpeakersPath(ownerDir),
speakerId + "/" + speakerId + "-image-small.jpg"));
return ImageUtils.retrieveFromFile(new File(getSpeakersPath(ownerDir), speakerId + "/" + speakerId + "-image-small.jpg"));
}
......@@ -202,7 +192,7 @@ public class Speaker extends FileModel {
*/
public static JSONArray encodeList(List<Speaker> speakers) {
JSONArray speakerArray = new JSONArray();
for (Speaker speaker : speakers)
for(Speaker speaker : speakers)
speakerArray.add(speaker.getId());
return speakerArray;
}
......@@ -214,9 +204,9 @@ public class Speaker extends FileModel {
* @return A list of the speakers in the JSONArray
*/
public static List<String> decodeJSONArray(JSONArray speakerArray) {
List<String> speakerIDs = new ArrayList<String>();
List<String> speakerIDs = new ArrayList<>();
if(speakerArray != null)
for (Object speakerObj : speakerArray)
for(Object speakerObj : speakerArray)
speakerIDs.add(((String) speakerObj));
return speakerIDs;
}
......@@ -249,11 +239,10 @@ public class Speaker extends FileModel {
String id) throws IOException {
File ownerDir = FileIO.getOwnerPath(verName, ownerAccount);
JSONObject jsonObj = FileIO.readJSONObject(
new File(getSpeakersPath(ownerDir), id + "/" + id + METADATA_SUFFIX));
JSONObject jsonObj = FileIO.readJSONObject(new File(getSpeakersPath(ownerDir), id + "/" + id + METADATA_SUFFIX));
String name = (String) jsonObj.get("name");
JSONArray languageArray = (JSONArray) jsonObj.get("languages");
if (languageArray == null)
if(languageArray == null)
throw new IOException("Null languages in the JSON file.");
List<Language> languages = Language.decodeJSONArray(languageArray);
String versionName = (String) jsonObj.get("version");
......@@ -261,7 +250,7 @@ public class Speaker extends FileModel {
return new Speaker(name, languages, id, versionName, ownerId);
}
/**
/* *
* Read all users from file
*
* @return A list of the users found in the users directory.
......@@ -362,9 +351,9 @@ public class Speaker extends FileModel {
* false otherwise.
*/
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj == this) return true;
if (obj.getClass() != getClass()) return false;
if(obj == null) return false;
if(obj == this) return true;
if(obj.getClass() != getClass()) return false;
Speaker rhs = (Speaker) obj;
return new EqualsBuilder()
.append(id, rhs.id).append(name, rhs.name)
......@@ -425,9 +414,8 @@ public class Speaker extends FileModel {
* associated with the Speaker.
* @throws IllegalArgumentException If the language list is null
*/
private void setLanguages(List<Language> languages) throws
IllegalArgumentException {
if (languages == null)
private void setLanguages(List<Language> languages) throws IllegalArgumentException {
if(languages == null)
throw new IllegalArgumentException("Speaker languages cannot be null.");
this.languages = languages;
}
......@@ -444,7 +432,8 @@ public class Speaker extends FileModel {
* @param _flags Unused additional flags about how the object should be
* written.
*/
public void writeToParcel(Parcel out, int _flags) {
public void writeToParcel(Parcel out, int _flags)
{
out.writeString(versionName);
out.writeString(ownerId);
out.writeString(id.toString());
......@@ -455,8 +444,8 @@ public class Speaker extends FileModel {
/**
* Generates instances of a Speaker from a parcel.
*/
public static final Parcelable.Creator<Speaker> CREATOR =
new Parcelable.Creator<Speaker>() {
public static final Parcelable.Creator<Speaker> CREATOR = new Parcelable.Creator<Speaker>()
{
public Speaker createFromParcel(Parcel in) {
return new Speaker(in);
}
......@@ -470,17 +459,19 @@ public class Speaker extends FileModel {
*
* @param in The parcel representing the Speaker to be constructed.
*/
public Speaker(Parcel in) {
public Speaker(Parcel in)
{
super(in);
setId(in.readString());
setName(in.readString());
List<Language> languages = new ArrayList<Language>();
List<Language> languages = new ArrayList<>();
in.readTypedList(languages, Language.CREATOR);
setLanguages(languages);
}
// Creates a purely numeric speaker ID
private String createId(String name) {
private String createId(String name)
{
// Generate 12 random uppercase alphabets.
return IdUtils.sampleFromAlphabet(12, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
......@@ -488,10 +479,11 @@ public class Speaker extends FileModel {
// Extracts the first character of each token in a string and uppercases, but
// stops after 4 characters have been extracted.
// Never use
private String extractInitials(String name) {
/*private String extractInitials(String name) {
StringBuilder initials = new StringBuilder();
int count = 0;
for (String token : name.split("\\s+")) {
for (String token : name.split("\\s+"))
{
if (token.length() > 0) {
initials.append(Character.toUpperCase(token.charAt(0)));
count += 1;
......@@ -502,7 +494,7 @@ public class Speaker extends FileModel {
if(BuildConfig.DEBUG)Log.i("extractInitials", "Extracting initials of: " + name + ". " +
"Returning " + initials.toString());
return initials.toString();
}
}*/
/**
* 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 {
//allocation of the player to the fragment
fragment.setPlayer(player);
} 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);
}
} else {
......
......@@ -66,8 +66,7 @@ public class ListenFragment extends Fragment implements OnClickListener {
seekBar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
int originalProgress;
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser)
seekBar.setProgress(originalProgress);
}
......@@ -89,25 +88,20 @@ public class ListenFragment extends Fragment implements OnClickListener {
new SeekBar.OnSeekBarChangeListener() {
int prog;
boolean isPlayed = false;
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
if (fromUser) {
if (player.isPlaying()) {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(!fromUser) return;
if(player.isPlaying())
{
pause ();
isPlayed = true;
}
prog = progress;
}
}
public void onStopTrackingTouch(SeekBar _seekBar) {
player.seekToMsec((int)Math.round(
(((float)prog)/100)*
player.getDurationMsec()));
if (isPlayed) {
isPlayed = false;
play ();
}
player.seekToMsec(Math.round((((float)prog)/100)* player.getDurationMsec()));
if(!isPlayed) return;
isPlayed = false;
play ();
}
public void onStartTrackingTouch(SeekBar _seekBar) {};
});
......@@ -129,7 +123,7 @@ public class ListenFragment extends Fragment implements OnClickListener {
*/
@Override
public void onDestroy() {
if (player != null)
if(player != null)
//If you hit the stop button really quickly, the player may not
//have been initialized fully.
player.release();
......@@ -144,17 +138,10 @@ public class ListenFragment extends Fragment implements OnClickListener {
*/
@Override
public void onClick(View v) {
if (v == playPauseButton) {
if (player.isPlaying()) {
pause();
if(otherPlayer != null)
otherPlayer.setEnabled(true);
} else {
if(otherPlayer != null)
otherPlayer.setEnabled(false);
play();
}
}
if(v != playPauseButton) return;
if(otherPlayer != null) otherPlayer.setEnabled(!isEnabled);
if(player.isPlaying()) pause();
else play();
}
/**
......@@ -188,25 +175,20 @@ public class ListenFragment extends Fragment implements OnClickListener {
for(int currentPosition;true;)
{
currentPosition = player.getCurrentMsec();
seekBar.setProgress(
(int)(((float)currentPosition/(float)
player.getDurationMsec())*100));
seekBar.setProgress((int)(((float)currentPosition/(float) player.getDurationMsec())*100));
try {
Thread.sleep(1000);
Thread.sleep(50);
} catch (InterruptedException e) {
currentPosition = player.getCurrentMsec();
seekBar.setProgress(
(int)(((float)currentPosition/(float)
player.getDurationMsec())*100));
if(otherPlayer != null)
otherPlayer.setProgress(currentPosition);
seekBar.setProgress((int)(((float)currentPosition/(float) player.getDurationMsec())*100));
if(otherPlayer != null) otherPlayer.setProgress(currentPosition);
return;
}
}
}
});
seekBarThread.start();
playPauseButton.setImageResource(R.drawable.pause_g);
if(isEnabled)playPauseButton.setImageResource(R.drawable.pause_g);
}
/**
......@@ -291,9 +273,9 @@ public class ListenFragment extends Fragment implements OnClickListener {
* @param isEnabled true: enable, false: disable
*/
private void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
playPauseButton.setEnabled(isEnabled);
if(isEnabled) playPauseButton.setImageResource(R.drawable.play_g);
else playPauseButton.setImageResource(R.drawable.play_grey);
playPauseButton.setImageResource((isEnabled)?R.drawable.play_g:R.drawable.play_grey);
}
public Player getPlayer() {
......@@ -320,4 +302,5 @@ public class ListenFragment extends Fragment implements OnClickListener {
private Thread seekBarThread;
private View inflatedView;
private ListenFragment otherPlayer;
private boolean isEnabled;
}
......@@ -207,7 +207,7 @@ public class ListenRespeakingActivity extends AikumaActivity{
} catch (IOException e) {
//The player couldn't be created from the recoridng, so lets wrap
//this activity up.
Toast.makeText(this, R.string.failed_to_create_from_recording, Toast.LENGTH_LONG).show();
Toast.makeText(this, R.string.failed_to_create_player_from_recording, Toast.LENGTH_LONG).show();
ListenRespeakingActivity.this.finish();
}
}
......
......@@ -447,7 +447,7 @@ public class RecordElicitation extends AikumaActivity {
}
public void onRecordClick(View _view) {
if (recording) pause();
if(recording) pause();
else record();
}
......@@ -466,6 +466,7 @@ public class RecordElicitation extends AikumaActivity {
ImageButton recordButton = (ImageButton) findViewById(R.id.btn_record_elicit);
recordButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.record));
recordButton.setEnabled(true);
//fragment.setEnabled(false);
}
......
package org.getalp.ligaikuma.lig_aikuma.ui;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.R;
import org.getalp.ligaikuma.lig_aikuma.model.SpeakerProfile;
import java.util.ArrayList;
import java.util.List;
public class SpeakerActivity extends AikumaActivity
{
public static final String TAG = "SpeakerActivity";
private ArrayList<String> _listValue;
private ProfileAdapter _adapteurKey;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speaker);
// Construct list and adapteur from keys values
String[] keys = SpeakerProfile.getAllKeys(this);
_listValue = new ArrayList<>();
if(keys != null)
for(String key : keys)
if(key.split("_").length==2)
_listValue.add(key);
_adapteurKey = new ProfileAdapter(this, _listValue);
// Set ListView controles
((ListView) findViewById(R.id.list_key)).setAdapter(_adapteurKey);
}
// DIALOG FOR VALIDATION OF USER REMOVING
public void showSessionDialog(int position) {
_position = position;
new SpeakerActivity.suppressDiaglogFragment().show(getFragmentManager(), "SessionDialogFragment");
}
public static int _position=0;
@SuppressLint("ValidFragment")
public class suppressDiaglogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
builder.setTitle(getString(R.string.do_you_want_to_delete_this_profile))
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {