Commit 3a27e201 authored by hanriaca's avatar hanriaca

remove setMetadataSession function because useless + adding pupup when back...

remove setMetadataSession function because useless + adding pupup when back button is pressed + fix bug of unplayed file in elicitation mode + fix some errors into the PCMWriter and the ThumbRespeakActivityLig
parent 7b20bebb
......@@ -321,6 +321,11 @@ public class PCMWriter implements Sampler {
// Data chunk size, 0 = unknown.
//
randomAccessWriter.writeInt(0);
} else {
Log.d("payLoadSize", "payLoadSize = " + getPayloadSize());
Log.d("length", "length = " + (this.randomAccessWriter.length()-44));
//randomAccessWriter.seek(getPayloadSize()+44);
randomAccessWriter.seek(this.randomAccessWriter.length()+44);
}
......
......@@ -32,12 +32,16 @@ import org.lp20.aikuma.util.AikumaSettings;
import org.lp20.aikuma.util.FileIO;
import org.lp20.aikuma2.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewDebug.FlagToString;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;
......@@ -74,6 +78,8 @@ public class RecordElicitation extends AikumaActivity {
setContentView(R.layout.elicitation);
recordUUID = UUID.randomUUID();
ImageButton nextButton = (ImageButton) findViewById(R.id.btn_next);
nextButton.setEnabled(false);
// retrieving metadata
prefsUserSession = getSharedPreferences(getString(R.string.userSession), MODE_PRIVATE);
initSession();
......@@ -158,9 +164,15 @@ public class RecordElicitation extends AikumaActivity {
// TODO Auto-generated catch block
e1.printStackTrace();
}
setMetadataSession();
recordLang = MetadataSession.getMetadataSession().getRecordLanguage();
Bundle bundle = getIntent().getBundleExtra(RecordingMetadataLig.metaBundle);
try {
date = new SimpleDateFormat().parse(bundle.getString(RecordingMetadataLig.metaDate));
} catch (ParseException e1) {
date = new Date();
}
strFolderDate = new SimpleDateFormat("yyMMdd-HHmmss").format(date);
}
}
......@@ -185,39 +197,6 @@ public class RecordElicitation extends AikumaActivity {
}
/**
* Called to create the metadata session
*/
private void setMetadataSession() {
if (getIntent() != null) {
Intent metadataIntent = getIntent();
Bundle respeakingBundle = metadataIntent.getBundleExtra(RecordingMetadataLig.metaBundle);
int gender = respeakingBundle.getInt(RecordingMetadataLig.metaSpkrGender);
Language recordLang = respeakingBundle.getParcelable(RecordingMetadataLig.metaRecordLang);
Language motherTong = respeakingBundle.getParcelable(RecordingMetadataLig.metaMotherTong);
ArrayList<Language> rspkLanguages = respeakingBundle.getParcelableArrayList(RecordingMetadataLig.metaLanguages);
String regionOrigin = respeakingBundle.getString(RecordingMetadataLig.metaOrigin);
String speakerName = respeakingBundle.getString(RecordingMetadataLig.metaSpkrName);
int speakerAge = respeakingBundle.getInt(RecordingMetadataLig.metaSpkrBirthYr);
Log.d("gender", ""+gender);
int speakerGender = gender == 1 ?
RecordingMetadataLig.GENDER_MALE : RecordingMetadataLig.GENDER_FEMALE;
MetadataSession.getMetadataSession().setSession(recordLang, motherTong,
rspkLanguages, regionOrigin, speakerName, speakerAge, speakerGender);
Bundle bundle = getIntent().getBundleExtra(RecordingMetadataLig.metaBundle);
try {
date = new SimpleDateFormat().parse(bundle.getString(RecordingMetadataLig.metaDate));
} catch (ParseException e1) {
date = new Date();
} catch (Exception e) {
Log.e(TAG, "Exception caught: " + e);
}
}
}
/**
* called when we want to save one record. Used when we touch newt button
*/
......@@ -309,11 +288,12 @@ public class RecordElicitation extends AikumaActivity {
} else {
Toast.makeText(this, "Going to next sentence...", Toast.LENGTH_LONG).show();
}
_view.setEnabled(false);
}
public void onValidate(View _view) {
if (saveRecording())
this.finish();
saveRecording();
this.finish();
}
/**
......@@ -346,8 +326,6 @@ public class RecordElicitation extends AikumaActivity {
ArrayList<String> speakerIds = new ArrayList<String>();
Double latitude = MainActivity.locationDetector.getLatitude();
Double longitude = MainActivity.locationDetector.getLongitude();
String suffix = new File(eliciTextFile).getName().replace(".txt", "").length() >= 10 ? new File(eliciTextFile).getName().substring(0, 10)
: new File(eliciTextFile).getName().replace(".txt", "");
String idDevice = Aikuma.getDeviceId();
String name = strFolderDate + "_" +
MetadataSession.getMetadataSession().getRecordLanguage().getCode()
......@@ -364,15 +342,18 @@ public class RecordElicitation extends AikumaActivity {
recordingLig = new RecordingLig(recordUUID, name, date,
AikumaSettings.getLatestVersion(),
AikumaSettings.getCurrentUserId(), MetadataSession.getMetadataSession().getRecordLanguage(),
MetadataSession.getMetadataSession().getMotherTongue(),
AikumaSettings.getCurrentUserId(), recordLang, MetadataSession.getMetadataSession().getMotherTongue(),
MetadataSession.getMetadataSession().getExtraLanguages(), speakerIds, deviceName, androidID,
null, null, sampleRate, duration,
recorder.getFormat(), recorder.getNumChannels(),
recorder.getBitsPerSample(), latitude, longitude,
MetadataSession.getMetadataSession().getRegionOrigin(), MetadataSession.getMetadataSession().getSpeakerName(),
MetadataSession.getMetadataSession().getRegionOrigin(),
MetadataSession.getMetadataSession().getSpeakerName(),
MetadataSession.getMetadataSession().getSpeakerAge(), gender);
Log.d("passage", "setRecordingLig first session");
} else{
Log.d("passage", "setRecordingLig restore session");
restoreMetaDataFromJson();
}
}
......@@ -390,10 +371,13 @@ public class RecordElicitation extends AikumaActivity {
return false;
}
setRecordingLig();
if (recorder != null && recorder.getFile().getPayloadSize() == 0) {
Log.d("recorder1", "recorder <= 50");
return false;
}
try {
// Move the wave file from the nosync directory to
// the synced directory and write the metadata
......@@ -507,36 +491,109 @@ public class RecordElicitation extends AikumaActivity {
ed.putInt(getString(R.string.currentLine), phraseId);
ed.putString(getString(R.string.sessionInputFile), eliciTextFile);
ed.putString(getString(R.string.sessionProgress), phraseId + " / " + numberOfLines);
ed.putString(getString(R.string.session_submode), "Text");
ed.commit();
}
public void onButtonBackPressed(View v) {
if (phraseId<numberOfLines) {
saveCurrentState();
String message = "a session is in progress. Do you want save the progression?";
if (safeActivityTransitionMessage != null) {
message = safeActivityTransitionMessage;
}
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
if (phraseId<numberOfLines) {
saveCurrentState();
}
if (isNewSession)
this.finish();
else
{
Intent intent = new Intent(this, ElicitationMode.class);
startActivity(intent);
}
if (isNewSession)
RecordElicitation.this.finish();
else
{
Intent intent = new Intent(RecordElicitation.this, ElicitationMode.class);
startActivity(intent);
}
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File metadataFile = new File(FileIO.getNoSyncPath(),
RecordElicitation.this.recordUUID + RecordingLig.METADATA_SUFFIX);
File mapFile = new File(FileIO.getNoSyncPath(),
RecordElicitation.this.recordUUID + RecordingLig.MAP_EXT);
File wavFile = new File(FileIO.getNoSyncPath() + "/items/" + RecordElicitation.this.recordUUID
+ ".wav");
mapFile.delete();
metadataFile.delete();
wavFile.delete();
if (isNewSession)
RecordElicitation.this.finish();
else {
Intent intent = new Intent(RecordElicitation.this, ElicitationMode.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
})
.setNeutralButton("Cancel", null)
.show();
}
@Override
public void onBackPressed() {
if (phraseId<numberOfLines) {
saveCurrentState();
}
String message = "a session is in progress. Do you want save the progression?";
if (safeActivityTransitionMessage != null) {
message = safeActivityTransitionMessage;
}
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
if (phraseId<numberOfLines) {
saveCurrentState();
}
if (isNewSession)
this.finish();
else
{
Intent intent = new Intent(this, ElicitationMode.class);
startActivity(intent);
}
if (isNewSession)
RecordElicitation.this.finish();
else
{
Intent intent = new Intent(RecordElicitation.this, ElicitationMode.class);
startActivity(intent);
}
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File metadataFile = new File(FileIO.getNoSyncPath(),
RecordElicitation.this.recordUUID + RecordingLig.METADATA_SUFFIX);
File mapFile = new File(FileIO.getNoSyncPath(),
RecordElicitation.this.recordUUID + RecordingLig.MAP_EXT);
File wavFile = new File(FileIO.getNoSyncPath() + "/items/" + RecordElicitation.this.recordUUID
+ ".wav");
mapFile.delete();
metadataFile.delete();
wavFile.delete();
if (isNewSession)
RecordElicitation.this.finish();
else {
Intent intent = new Intent(RecordElicitation.this, ElicitationMode.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
})
.setNeutralButton("Cancel", null)
.show();
}
}
......@@ -28,6 +28,8 @@ import org.lp20.aikuma.util.AikumaSettings;
import org.lp20.aikuma.util.FileIO;
import org.lp20.aikuma2.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
......@@ -149,13 +151,7 @@ public class ThumbRespeakActivityLig extends AikumaActivity {
fragment.setThumbRespeaker(respeaker, isNewSession);
fragment.getRespeaker().getRecorder().setTotalAudioLength(totalAudioLength);
fragment.getRespeaker().getRecorder().getFile().setCurrentSample(curSampl);
fragment.getRespeaker().getRecorder().getFile().setPayloadSize(payLoadSize);
try {
fragment.getRespeaker().getRecorder().getFile().getRandomAccessWriter().seek((long) payLoadSize + 44);
} catch (IOException e) {
e.printStackTrace();
}
fragment.getRespeaker().getRecorder().getFile().setPayloadSize(payLoadSize);
}
/**
......@@ -357,27 +353,62 @@ public class ThumbRespeakActivityLig extends AikumaActivity {
@Override
public void onBackPressed() {
setRecordingLig();
saveRecordingJsonInNoSync();
saveCurrentState();
try {
fragment.getRespeaker().stop();
} catch (MicException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
String message = "a session is in progress. Do you want save the progression?";
if (safeActivityTransitionMessage != null) {
message = safeActivityTransitionMessage;
}
fragment.getRespeaker().saveRespeaking();
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
setRecordingLig();
fragment.getRespeaker().saveRespeaking();
saveRecordingJsonInNoSync();
saveCurrentState();
try {
fragment.getRespeaker().stop();
} catch (MicException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (isNewSession)
this.finish();
else {
Intent intent = new Intent(this, RespeakingSelection.class);
startActivity(intent);
}
if (isNewSession)
ThumbRespeakActivityLig.this.finish();
else {
Intent intent = new Intent(ThumbRespeakActivityLig.this, RespeakingSelection.class);
startActivity(intent);
}
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File metadataFile = new File(FileIO.getNoSyncPath(),
ThumbRespeakActivityLig.this.respeakingUUID + RecordingLig.METADATA_SUFFIX);
File mapFile = new File(FileIO.getNoSyncPath(),
ThumbRespeakActivityLig.this.respeakingUUID + RecordingLig.MAP_EXT);
File wavFile = new File(FileIO.getNoSyncPath() + "/items/" + ThumbRespeakActivityLig.this.respeakingUUID
+ ".wav");
ThumbRespeakActivityLig.this.fragment.deleteLastTempFile();
mapFile.delete();
metadataFile.delete();
wavFile.delete();
if (isNewSession)
ThumbRespeakActivityLig.this.finish();
else {
Intent intent = new Intent(ThumbRespeakActivityLig.this, RespeakingSelection.class);
startActivity(intent);
}
}
})
.setNeutralButton("Cancel", null)
.show();
}
@Override
......
......@@ -332,7 +332,7 @@ public class ThumbRespeakFragment extends Fragment {
* called when we need to delete last temp file and
* decrements the count attribute
*/
private void deleteLastTempFile() {
public void deleteLastTempFile() {
String filename = FileIO.getOwnerPath().getAbsolutePath() +
"/recordings/" + "temp.rspk.wav";
try {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment