Commit b11287c3 authored by mistermad's avatar mistermad

- Deleting the session backup in elicitation mode if it in step one

- Changing the display of the distinction between file/folder translated and respected in the file exploreur.
- Fixed a bug corrupting files when using the undo button in elicitation mode.
- Fixed bug on dialog boxes at the end of the metadata entry
- Fixed various display bugs (RespeakingSelection, CheckTranscrition, CheckWordVariant, LanguageFilterList, RespeakingMetadataLig, RecordingMetadataLig...)
parent feababba
......@@ -7,7 +7,7 @@ import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/**
* Instrumentation test, which will execute on an Android device.
......
......@@ -8,6 +8,7 @@
<uses-sdk android:minSdkVersion="14"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
......
......@@ -14,6 +14,7 @@ import android.net.NetworkInfo;
import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import android.support.annotation.RequiresApi;
import org.getalp.ligaikuma.lig_aikuma.model.FileModel;
import org.getalp.ligaikuma.lig_aikuma.model.Language;
......@@ -28,9 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import android.support.annotation.RequiresApi;
/**
* Offers a collection of static methods that require a context independently
* of an Activity.
......
......@@ -4,8 +4,6 @@ package org.getalp.ligaikuma.lig_aikuma;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -161,162 +159,127 @@ public class ModeSelection extends Activity implements OnClickListener{
{
startActivity(new Intent(this, ShareFileActivity.class));
}
// START DIALOG DECLARATION
@SuppressLint("InflateParams")
public void showSessionDialog() {
new UserSessionDiaglogFragment().show(getFragmentManager(), "SessionDialogFragment");
View sessionView = getLayoutInflater().inflate(R.layout.session_dialog, null);
setDialogDetails((LinearLayout) sessionView);
new AlertDialog.Builder(this)
.setView(sessionView)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
if(BuildConfig.DEBUG)Log.i(TAG,"yes, retrieve the session");
retrieveSession();
}})
.setNegativeButton(R.string.no_but_keep_files, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
if(BuildConfig.DEBUG)Log.i(TAG,"no don't retrieve the session but keep files");
prefsUserSession = getSharedPreferences("userSession", MODE_PRIVATE);
ed.clear().commit();
}})
.setNeutralButton(R.string.no_and_erase_files, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
if(BuildConfig.DEBUG)Log.i(TAG,"no don't retrieve the session and erase files");
eraseFiles();
ed.clear().commit();
}})
.show();
}
public void retrieveSession()
{
String mode = prefsUserSession.getString("mode", null);
if(BuildConfig.DEBUG)Log.d(TAG, "mode retrieval: "+mode);
if(mode == null || mode.compareToIgnoreCase(CheckTranscription.TAG) == 0)
startActivity(new Intent(ModeSelection.this, CheckTranscription.class));
else if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0)
startActivity(new Intent(ModeSelection.this, CheckWordVariant.class));
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
startActivity(new Intent(ModeSelection.this, ThumbRespeakActivityLig.class));
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
startActivity(new Intent(ModeSelection.this, RecordElicitation.class));
else
Toast.makeText(this, "An error ocurred. The session could not be retrieved", Toast.LENGTH_LONG).show();
}
@SuppressLint("ValidFragment")
public class UserSessionDiaglogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LinearLayout ll = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.session_dialog, null);
setDialogDetails(ll);
builder.setView(ll)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(BuildConfig.DEBUG)Log.i(TAG,"yes, retrieve the session");
retrieveSession();
}
})
.setNegativeButton(R.string.no_but_keep_files, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(BuildConfig.DEBUG)Log.i(TAG,"no don't retrieve the session but keep files");
prefsUserSession = getSharedPreferences("userSession", MODE_PRIVATE);
//clear sharedPrefs
ed.clear().commit();
}
})
.setNeutralButton(R.string.no_and_erase_files, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(BuildConfig.DEBUG)Log.i(TAG,"no don't retrieve the session and erase files");
//remove files
eraseFiles();
//clear sharedPrefs
// ed.putBoolean(getString(R.string.sessionActive), false);
ed.clear().commit();
}
});
return builder.create();
public void setDialogDetails(LinearLayout ll) {
String mode = prefsUserSession.getString("mode", "undefined");
if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || mode.compareTo(CheckTranscription.TAG) == 0)
{
;
((TextView) ll.findViewById(R.id.session_submode)).setText(
(mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0) ? CheckWordVariant.TAG : CheckTranscription.TAG);
}
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
{
String submode = prefsUserSession.getString("submode", "text");
((TextView) ll.findViewById(R.id.session_mode)).setText("Elicitation");
((TextView) ll.findViewById(R.id.session_submode)).setText(submode.toLowerCase());
}
public void retrieveSession()
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
{
String mode = prefsUserSession.getString("mode", null);
if(BuildConfig.DEBUG)Log.d(TAG, "mode retrieval: "+mode);
if(mode == null || mode.compareToIgnoreCase(CheckTranscription.TAG) == 0)
startActivity(new Intent(getActivity(), CheckTranscription.class));
else if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0)
startActivity(new Intent(getActivity(), CheckWordVariant.class));
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
startActivity(new Intent(getActivity(), ThumbRespeakActivityLig.class));
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
startActivity(new Intent(getActivity(), RecordElicitation.class));
else
Toast.makeText(getActivity(), "An error ocurred. The session could not be retrieved", Toast.LENGTH_LONG).show();
String submode = prefsUserSession.getString("submode", "undefined");
if(submode.compareToIgnoreCase("Respeaking") == 0)
((TextView) ll.findViewById(R.id.session_mode)).setText("Respeaking");
else if(submode.compareToIgnoreCase("translation") == 0)
((TextView) ll.findViewById(R.id.session_mode)).setText("Translation");
((TextView) ll.findViewById(R.id.session_submode)).setText("None");
}
public void setDialogDetails(LinearLayout ll) {
// retrieve prefs values and store display them on popup menu
/*
* *** convert internal mode/submode to display mode/submode following the rule: ***
* internal mode / internal submode ----------> display mode / display submode
* CheckWordVariant / null ----------> Check mode / CheckWordVariant
* CheckTranscription / null ----------> Check mode / CheckTranscription
* RecordElicitation / text ----------> Elicitation / text
* "" / image ----------> "" / image
* "" / video ----------> "" / video
* ThumbRespeakActivityLig / respeaking ----------> Respeaking / null
* "" / translation ----------> Translation / null
*/
String mode = prefsUserSession.getString("mode", "undefined");
String modeDialog = null, submodeDialog = null;
if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || mode.compareTo(CheckTranscription.TAG) == 0)
{
modeDialog ="Check mode";
submodeDialog = (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0) ? CheckWordVariant.TAG : CheckTranscription.TAG;
}
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
{
String submode = prefsUserSession.getString("submode", "undefined");
modeDialog ="Elicitation";
if (submode.compareToIgnoreCase("text") == 0) submodeDialog = "text";
else if (submode.compareToIgnoreCase("image") == 0) submodeDialog = "image";
else if (submode.compareToIgnoreCase("video") == 0) submodeDialog = "video";
}
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
{
String submode = prefsUserSession.getString("submode", "undefined");
if (submode.compareToIgnoreCase("Respeaking") == 0) modeDialog = "Respeaking";
else if (submode.compareToIgnoreCase("translation") == 0) modeDialog = "Translation";
submodeDialog = "None";
}
((TextView) ll.findViewById(R.id.session_mode)).setText(modeDialog);
((TextView) ll.findViewById(R.id.session_submode)).setText(submodeDialog);
// display date in a more convenient way
try {
Date date = new SimpleDateFormat().parse(prefsUserSession.getString("date", "undefined"));
// TODO parsing fails...
((TextView) ll.findViewById(R.id.session_date)).setText(new SimpleDateFormat("dd/MM/yyyy at HH:mm",Locale.FRANCE).format(date));
} catch (ParseException e) {
if(BuildConfig.DEBUG)Log.e(TAG, ""+e);
((TextView) ll.findViewById(R.id.session_date)).setText(prefsUserSession.getString("date", "undefined"));
}
((TextView) ll.findViewById(R.id.session_progress)).setText("" + prefsUserSession.getString("progress", "0"));
// display only filename
String file = new File(prefsUserSession.getString("inputFile", "undefined")).getName();
((TextView) ll.findViewById(R.id.session_input_file)).setText(file);
//Usefull only for Translating and Respeaking ode
MediaPlayerFactory._currentReadFile = FileIO.getOwnerPath()+"/recordings/"+file+"/"+file+".wav";
if(BuildConfig.DEBUG)Log.d(TAG,MediaPlayerFactory._currentReadFile);
// display date in a more convenient way
try {
Date date = new SimpleDateFormat().parse(prefsUserSession.getString("date", "undefined"));
// TODO parsing fails...
((TextView) ll.findViewById(R.id.session_date)).setText(new SimpleDateFormat("dd/MM/yyyy at HH:mm",Locale.FRANCE).format(date));
} catch (ParseException e) {
if(BuildConfig.DEBUG)Log.e(TAG, ""+e);
((TextView) ll.findViewById(R.id.session_date)).setText(prefsUserSession.getString("date", "undefined"));
}
((TextView) ll.findViewById(R.id.session_progress)).setText("" + prefsUserSession.getString("progress", "0"));
// display only filename
String file = new File(prefsUserSession.getString("inputFile", "undefined")).getName();
((TextView) ll.findViewById(R.id.session_input_file)).setText(file);
//Usefull only for Translating and Respeaking ode
MediaPlayerFactory._currentReadFile = FileIO.getOwnerPath()+"/recordings/"+file+"/"+file+".wav";
if(BuildConfig.DEBUG)Log.d(TAG,MediaPlayerFactory._currentReadFile);
}
public void eraseFiles() {
String savedMode = prefsUserSession.getString("mode", null),
savedSubmode = prefsUserSession.getString("submode", "undefined");
if(BuildConfig.DEBUG){Log.d(TAG, "saved mode: "+savedMode);
Log.d(TAG, "saved submode: "+savedSubmode);}
Log.d(TAG, "saved submode: "+savedSubmode);}
/*Check Mode*/
if (savedMode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || savedMode.compareTo(CheckTranscription.TAG) == 0) {
File savedFile = new File(prefsUserSession.getString("checkExportFile","undefined"));
if (savedMode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || savedMode.compareTo(CheckTranscription.TAG) == 0) {
File savedFile = new File(prefsUserSession.getString("checkExportFile","undefined"));
if(BuildConfig.DEBUG)Log.d(TAG, "saved file: "+savedFile);
savedFile.delete();
savedFile.delete();
if(BuildConfig.DEBUG)Log.i(TAG, "saved file erased: "+savedFile);
/*Elicitation Mode*/
} else if (savedMode.compareToIgnoreCase(RecordElicitation.TAG) == 0) {
} else if (savedMode.compareToIgnoreCase(RecordElicitation.TAG) == 0) {
if(BuildConfig.DEBUG)Log.d(TAG, "saved submode: "+savedSubmode);
String idDevice = Aikuma.getDeviceId(), savedDate = prefsUserSession.getString("date", "");
Language savedRecordLang = new Language(prefsUserSession.getString("Language name", ""),
prefsUserSession.getString("LanguageCode", ""));
String name = savedDate + "_" + savedRecordLang.getCode() + "_" + idDevice;
//erase linker
prefsUserSession.getString("LanguageCode", ""));
String name = savedDate + "_" + savedRecordLang.getCode() + "_" + idDevice;
//erase linker
File savedTextFile = new File(FileIO.getOwnerPath()+"/recordings/"+name + "/" + name + "_linker.txt");
if(BuildConfig.DEBUG)Log.d(TAG, "saved linker file: "+savedTextFile);
savedTextFile.delete();
if(BuildConfig.DEBUG)Log.i(TAG, "saved file erased: "+savedTextFile);
//erase metadata and audio files
int savedProgress = prefsUserSession.getInt("currentLine", 0);
//erase metadata and audio files
int savedProgress = prefsUserSession.getInt("currentLine", 0);
if(BuildConfig.DEBUG)Log.d(TAG, "saved progress: "+savedProgress);
for(int i=savedProgress; i>=0; i--) {
for(int i=savedProgress; i>=0; i--) {
File savedMetadataFile = new File(FileIO.getOwnerPath()+"/recordings/"+name + "/" + name + "_" + i + RecordingLig.METADATA_SUFFIX),
savedWavFile = new File(FileIO.getOwnerPath()+"/recordings/"+name + "/" + name + "_" + i +".wav");
if(BuildConfig.DEBUG) {
......@@ -330,11 +293,11 @@ public class ModeSelection extends Activity implements OnClickListener{
Log.i(TAG, "saved audio erased: "+savedWavFile);
}
}
/*Respeaking or Translating Mode*/
/*TODO
* Erase the respeaking or translating files if the
* user does not want to save its session
* user does not want to save its session
* nor its recordings
*/
}// else if (savedMode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0) {
......@@ -342,7 +305,7 @@ public class ModeSelection extends Activity implements OnClickListener{
/*TODO
* erase the _rspk files
*/
// } else if (savedSubmode.compareToIgnoreCase(getString(R.string.translation)) == 0) {
/*TODO
......@@ -350,8 +313,13 @@ public class ModeSelection extends Activity implements OnClickListener{
*/
// }
//}
Toast.makeText(this, R.string.session_and_files_erased, Toast.LENGTH_LONG).show();
Toast.makeText(this, R.string.session_and_files_erased, Toast.LENGTH_LONG).show();
// END OF DIALOG DECLARATION
}
}
......@@ -168,7 +168,7 @@ public class Mapper {
originalEndOfSegment = null;
return true;
}
/** Remap an existing map file with index file, used the create a no speak map file
/** Remap an existing map file with index file, used the create a temp no speak map file
*
* @param index index used for remap
*/
......
......@@ -4,11 +4,6 @@
*/
package org.getalp.ligaikuma.lig_aikuma.audio.record;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.File;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.util.Log;
......@@ -16,6 +11,11 @@ import android.util.Log;
import org.getalp.ligaikuma.lig_aikuma.audio.Sampler;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.BuildConfig;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* A writer that can handle PCM/WAV files.
......
......@@ -182,13 +182,9 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
//
afterBuffer = Arrays.copyOf(afterBuffer, afterBuffer.length + buffer.length);
// Copy the buffer to avoid reference problems.
//
short[] copiedBuffer = Arrays.copyOf(buffer, buffer.length);
// Add the copied current buffer onto the end.
//
System.arraycopy(copiedBuffer, 0, afterBuffer, offset, buffer.length);
System.arraycopy(Arrays.copyOf(buffer, buffer.length), 0, afterBuffer, offset, buffer.length);
}
//TODO Duplicate method. See addToAfterBuffer.
......@@ -204,13 +200,9 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
//
onsetBuffer = Arrays.copyOf(onsetBuffer, onsetBuffer.length + buffer.length);
// Copy the buffer to avoid reference problems.
//
short[] copiedBuffer = Arrays.copyOf(buffer, buffer.length);
// Add the copied current buffer onto the end.
//
System.arraycopy(copiedBuffer, 0, onsetBuffer, offset, buffer.length);
System.arraycopy(Arrays.copyOf(buffer, buffer.length), 0, onsetBuffer, offset, buffer.length);
}
/** Clear the before speech buffer. */
......
......@@ -181,13 +181,14 @@ public class RecordingLig extends Recording {
dir.mkdir();
if(BuildConfig.DEBUG)Log.i(TAG, "start write - iniate directory " + dir.getAbsolutePath());
// Import the wave file into the new recording directory.
Log.d(TAG, "A1");
if(this.isMovie())
// TODO update importMov
super.importMov(recordingUUID, getId());
else
this.importWav(recordingUUID, WAV_EXT);
Log.d(TAG, "A2");
// if the recording is original
if(isOriginal() || isElicit()) {
// Import the sample wave file into the new recording directory
......@@ -203,12 +204,15 @@ public class RecordingLig extends Recording {
}
JSONObject encodedRecording = this.encode();
Log.d(TAG, "A3");
// Write the json metadata.
File metadataFile = new File(getIndividualRecordingPath(), this.name + METADATA_SUFFIX);
File metadataFile = new File(dir.toString(), this.name + METADATA_SUFFIX);
FileIO.writeJSONObject(metadataFile,encodedRecording);
Log.i(TAG, "Saved metadata file to " + metadataFile.getAbsolutePath());
Log.i(TAG, "Saved metadata file to " + metadataFile.getAbsolutePath());
Log.d(TAG, "A4");
}
/**
......@@ -276,7 +280,7 @@ public class RecordingLig extends Recording {
* @return True if the recording is an elicitation.
*/
public boolean isElicit() {
return this.name.contains("_elicit_")/* && !this.name.contains("rspk") || !this.name.contains("trsl")*/;
return this.name.contains("_elicit_") && !this.name.contains("_rspk") && !this.name.contains("_trsl");
}
......
......@@ -46,7 +46,6 @@ public class AddSpeakerActivity1 extends AikumaActivity {
textField.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if(s.toString().length() > 0) {
ImageButton okButton =
(ImageButton) findViewById(R.id.okButton1);
......@@ -74,7 +73,6 @@ public class AddSpeakerActivity1 extends AikumaActivity {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if((event.getAction() == KeyEvent.ACTION_DOWN &&
(event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
onOkButtonPressed(null);
......
......@@ -12,11 +12,10 @@ import android.provider.MediaStore;
import android.view.View;
import android.widget.TextView;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.R;
import org.getalp.ligaikuma.lig_aikuma.model.Language;
import org.getalp.ligaikuma.lig_aikuma.util.ImageUtils;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.R;
import java.io.File;
import java.util.ArrayList;
import java.util.UUID;
......
......@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;