Commit 0c4d01ce authored by mistermad's avatar mistermad

- Bug removal

- Translate metadata Activity: modified title and deletion of autorefill
- Change the position of the "Note" field
- Updated existing geo-location system
- Preparing xml files for translation
parent a81bc5b9
*.class
*.json
aikuma-cloud-storage-*.jar
.metadata
*.swp
*~
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.getalp.ligaikuma.lig_aikuma.lig_aikuma">
package="org.getalp.ligaikuma.lig_aikuma.lig_aikuma"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk android:minSdkVersion="14"/>
......@@ -14,6 +16,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
......
......@@ -76,7 +76,11 @@ public class Aikuma extends android.app.Application {
return Build.MANUFACTURER + "-" + Build.MODEL;
}
/**
* Set the application context, use it before call all other functions (except getLanguages)
*
* @param context
*/
public static void setAppContext(Context context) { appContext = context;}
/**
......@@ -109,12 +113,9 @@ public class Aikuma extends android.app.Application {
ConnectivityManager connMgr = (ConnectivityManager)
appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
if(AikumaSettings.isOnlyWifi) {
networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
} else {
networkInfo = connMgr.getActiveNetworkInfo();
}
NetworkInfo networkInfo = (AikumaSettings.isOnlyWifi)?
connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI):
connMgr.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
}
......@@ -173,9 +174,8 @@ public class Aikuma extends android.app.Application {
ArrayList<String> accountList = new ArrayList<>();
Account[] accounts = AccountManager.get(appContext).getAccountsByType("com.google");
for(Account ac : accounts) {
for(Account ac : accounts)
accountList.add(ac.name);
}
return accountList;
}
......
......@@ -60,7 +60,7 @@ public class ModeSelection extends Activity implements OnClickListener{
SharedPreferences settings =
PreferenceManager.getDefaultSharedPreferences(this);
//AikumaSettings.setUserId(settings.getString(AikumaSettings.SETTING_OWNER_ID_KEY, null));
if (AikumaSettings.getCurrentUserId() == null) {
if(AikumaSettings.getCurrentUserId() == null) {
Random r = new Random();
AikumaSettings.setUserId(Integer.toString(r.nextInt()));
Log.i(TAG, AikumaSettings.getCurrentUserId());
......@@ -68,7 +68,7 @@ public class ModeSelection extends Activity implements OnClickListener{
// DEBUG
Map<String,?> mapPrefs = settings.getAll();
for (String key : mapPrefs.keySet())
for(String key : mapPrefs.keySet())
Log.i(TAG, "DEBUG - Shared Preferences - " + key + " -> " + mapPrefs.get(key));
// hides the action bar instead of removing it
......@@ -95,9 +95,8 @@ public class ModeSelection extends Activity implements OnClickListener{
// check the existing session and show popup to propose retrieving it
prefsUserSession = getSharedPreferences(getString(R.string.userSession), MODE_PRIVATE);
ed = prefsUserSession.edit();
if (prefsUserSession.getBoolean(getString(R.string.sessionActive), false)) {
if(prefsUserSession.getBoolean(getString(R.string.sessionActive), false))
showSessionDialog();
}
}
@Override
......
......@@ -60,9 +60,8 @@ public class InterleavedPlayer extends Player {
if (onCompletionListener != null)
onCompletionListener.onCompletion(p);
reset();
completedOnce = false;
} else
completedOnce = true;
}
completedOnce = !completedOnce;
}
};
original.setOnCompletionListener(bothCompletedListener);
......@@ -98,8 +97,8 @@ public class InterleavedPlayer extends Player {
/** Pauses the playback. */
public void pause() {
if (original.isPlaying()) original.pause();
if (respeaking.isPlaying()) respeaking.pause();
if(original.isPlaying()) original.pause();
if(respeaking.isPlaying()) respeaking.pause();
}
/**
......@@ -132,7 +131,7 @@ public class InterleavedPlayer extends Player {
}
private Segment getCurrentOriginalSegment() {
if (currentOriginalSegment == null)
if(currentOriginalSegment == null)
advanceOriginalSegment();
return currentOriginalSegment;
}
......@@ -148,7 +147,7 @@ public class InterleavedPlayer extends Player {
// Plays the specified segment in the specified player.
private void playSegment(Segment segment, MarkedPlayer player) {
if (segment != null) {
if(segment != null) {
player.seekTo(segment);
player.setNotificationMarkerPosition(segment);
player.play();
......@@ -157,10 +156,9 @@ public class InterleavedPlayer extends Player {
// Moves forward to the next original segment in the recording.
private void advanceOriginalSegment() {
if (getOriginalSegmentIterator().hasNext())
currentOriginalSegment = getOriginalSegmentIterator().next();
else
currentOriginalSegment = new Segment((currentOriginalSegment != null)? currentOriginalSegment.getEndSample(): 0l, Long.MAX_VALUE);
currentOriginalSegment = (getOriginalSegmentIterator().hasNext())?
getOriginalSegmentIterator().next():
new Segment((currentOriginalSegment != null)? currentOriginalSegment.getEndSample(): 0l, Long.MAX_VALUE);
}
// Gets an iterator over the segments of the original recording.
......
......@@ -97,12 +97,8 @@ public class MarkedPlayer extends SimplePlayer {
* @param segment The segment whose end is to be marked.
*/
public void setNotificationMarkerPosition(Segment segment) {
if (segment != null) {
setNotificationMarkerPositionMsec(
sampleToMsec(segment.getEndSample()));
} else {
unsetNotificationMarkerPosition();
}
if (segment != null) setNotificationMarkerPositionMsec(sampleToMsec(segment.getEndSample()));
else unsetNotificationMarkerPosition();
}
/**
......
......@@ -3,13 +3,13 @@ package org.getalp.ligaikuma.lig_aikuma.audio;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import org.getalp.ligaikuma.lig_aikuma.model.Segments.Segment;
import org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakSummaryLig;
public class SegmentPlayer extends MarkedPlayer {
public class SegmentPlayer extends MarkedPlayer
{
private Segment segment;
private OnMarkerReachedListener onMarkerReachedListener;
......
......@@ -22,7 +22,13 @@ import java.util.UUID;
* @author Oliver Adams <oliver.adams@gmail.com>
* @author Florian Hanke <florian.hanke@gmail.com>
*/
public class SimplePlayer extends Player implements Sampler {
public class SimplePlayer extends Player implements Sampler
{
/** The MediaPlayer used to play the recording. **/
private MediaPlayer mediaPlayer;
private long sampleRate;
private boolean finishedPlaying;
private Recording recording;
/**
* Creates a player to play the supplied recording.
......@@ -139,15 +145,26 @@ public class SimplePlayer extends Player implements Sampler {
* @return The duration of the audio in milliseconds as an int.
*/
public int getDurationMsec() {
return mediaPlayer.getDuration();
/*try {
try { return mediaPlayer.getDuration();
} catch (IllegalStateException e) {
//If this fails then we won't be in an activity where a duration is
//actually required. 0 is returned so we at least know it was
//erroneous if we ever need to.
return 0;
}
}
/*Old
public int getDurationMsec() {
return mediaPlayer.getDuration();
//try {
//} catch (IllegalStateException e) {
//If this fails then we won't be in an activity where a duration is
//actually required. -1 is returned so we at least know it was
//erroneous if we ever need to.
return -1;
}*/
}
//}
}*/
/**
* Seek to a given point in the recording in milliseconds.
......@@ -171,14 +188,12 @@ public class SimplePlayer extends Player implements Sampler {
public void release() {
mediaPlayer.release();
}
protected MediaPlayer getMediaPlayer() {
return mediaPlayer;
}
protected void setFinishedPlaying(boolean finished) {
this.finishedPlaying = finished;
}
//Never use
//protected MediaPlayer getMediaPlayer() {return mediaPlayer;}
//Never use
//protected void setFinishedPlaying(boolean finished) {this.finishedPlaying = finished;}
protected Recording getRecording() {
return recording;
......@@ -212,6 +227,7 @@ public class SimplePlayer extends Player implements Sampler {
* Increment the view count by adding a view file to the Recording's view
* directory.
*/
//Never use
private void incrementViewCount() throws IOException {
String versionName = recording.getVersionName();
String ownerId = recording.getOwnerId();
......@@ -267,10 +283,4 @@ public class SimplePlayer extends Player implements Sampler {
public boolean isFinishedPlaying() {
return this.finishedPlaying;
}
/** The MediaPlayer used to play the recording. **/
protected MediaPlayer mediaPlayer;
private long sampleRate;
private boolean finishedPlaying;
private Recording recording;
}
......@@ -74,21 +74,21 @@ public class FileModel implements Parcelable {
int index = splitCloudId[6].lastIndexOf('.');
String fileName = splitCloudId[6].substring(0, index);
String ext = splitCloudId[6].substring(index+1);
if(ext.equals("json")) //metadata
return null;
else if(ext.equals("jpg")) { //speaker small image
return new FileModel(splitCloudId[0], splitCloudId[3], splitCloudId[5], "speaker", ext);
} else if(ext.equals("txt")) { //mapping, transcript
String[] splitName = fileName.split("-");
return new FileModel(splitCloudId[0], splitCloudId[3], fileName, splitName[splitName.length-1], ext);
} else { //source, respeaking, preview
String[] splitName = fileName.split("-");
if(splitName[splitName.length-1].equals("preview")) {
return new FileModel(splitCloudId[0], splitCloudId[3], fileName, "preview", ext);
} else {
return new FileModel(splitCloudId[0], splitCloudId[3], fileName, splitName[2], ext);
}
switch (ext) {
case "json"://metadata
return null;
case "jpg": //speaker small image
return new FileModel(splitCloudId[0], splitCloudId[3], splitCloudId[5], "speaker", ext);
case "txt": //mapping, transcript
String[] splitName = fileName.split("-");
return new FileModel(splitCloudId[0], splitCloudId[3], fileName, splitName[splitName.length - 1], ext);
default: //source, respeaking, preview
String[] splitName2 = fileName.split("-");
if(splitName2[splitName2.length - 1].equals("preview"))
return new FileModel(splitCloudId[0], splitCloudId[3], fileName, "preview", ext);
return new FileModel(splitCloudId[0], splitCloudId[3], fileName, splitName2[2], ext);
}
}
......@@ -97,8 +97,7 @@ public class FileModel implements Parcelable {
* @param in Parcel where the speaker will be created
*/
protected FileModel(Parcel in) {
String versionName = in.readString();
String ownerId = in.readString();
String versionName = in.readString(), ownerId = in.readString();
setVersionName(versionName);
setOwnerId(ownerId);
this.fileType = "speaker";
......@@ -118,11 +117,9 @@ public class FileModel implements Parcelable {
* @return The ID + extension of the file-model
*/
public String getIdExt() {
if(fileType.equals("speaker")) {
return (id + "-image-small.jpg");
} else {
return (id + getExtension());
}
return (fileType.equals("speaker"))?
(id + "-image-small.jpg"):
(id + getExtension());
}
/**
......@@ -141,7 +138,8 @@ public class FileModel implements Parcelable {
* 1: metadata (return null if metadata doesn't exist)
* @return File's cloudId (a relative-path of recording to 'aikuma/')
*/
public String getCloudIdentifier(int option) {
public String getCloudIdentifier(int option)
{
if(option != 0 && option != 1)
return null;
......@@ -152,23 +150,17 @@ public class FileModel implements Parcelable {
String suffix;
if(fileType.equals("speaker")) {
if(option == 0)
suffix = "-image-small.jpg";
else
suffix = METADATA_SUFFIX;
suffix = (option == 0) ? "-image-small.jpg" : METADATA_SUFFIX;
return (ownerDirStr + Speaker.PATH + getId() + "/" + getId() + suffix);
} else {
if(option == 0)
suffix = getExtension();
else if(format.equals("txt") || fileType.equals("preview")) // No metadata for transcript/mapping/preview
return null;
else
suffix = METADATA_SUFFIX;
String groupId = getId().split("-")[0];
return (ownerDirStr + Recording.PATH + groupId + "/" + getId() + suffix);
}
if(option == 0)
suffix = getExtension();
else if(format.equals("txt") || fileType.equals("preview")) // No metadata for transcript/mapping/preview
return null;
else
suffix = METADATA_SUFFIX;
return (ownerDirStr + Recording.PATH + getId().split("-")[0] + "/" + getId() + suffix);
}
/**
......@@ -177,26 +169,21 @@ public class FileModel implements Parcelable {
* @param option 0: file, 1: metadata-file
* @return The file/metadata-file of the item
*/
public File getFile(int option) {
public File getFile(int option)
{
if(option != 0 && option != 1)
return null;
File itemPath;
String suffix;
if(fileType.equals("speaker")) {
itemPath = new File(
FileIO.getOwnerPath(versionName, ownerId), Speaker.PATH);
itemPath = new File(FileIO.getOwnerPath(versionName, ownerId), Speaker.PATH);
itemPath.mkdirs();
if(option == 0)
suffix = "-image-small.jpg";
else
suffix = METADATA_SUFFIX;
suffix = (option == 0)? "-image-small.jpg": METADATA_SUFFIX;
return new File(itemPath, getId() + "/" + getId() + suffix);
} else {
itemPath = new File(
FileIO.getOwnerPath(versionName, ownerId), Recording.PATH);
itemPath = new File(FileIO.getOwnerPath(versionName, ownerId), Recording.PATH);
itemPath.mkdirs();
if(option == 0)
......@@ -205,9 +192,8 @@ public class FileModel implements Parcelable {
return null;
else
suffix = METADATA_SUFFIX;
String groupId = getId().split("-")[0];
return new File(itemPath, groupId + "/" + getId() + suffix);
return new File(itemPath, getId().split("-")[0] + "/" + getId() + suffix);
}
}
......@@ -248,14 +234,11 @@ public class FileModel implements Parcelable {
}
private String getExtension() {
if(format.equals("mp4")) {
return ".mp4";
} else if(format.equals("jpg")) {
return ".jpg";
} else if(format.equals("txt")) {
return ".txt";
} else {
return ".wav";
switch (format) {
case "mp4": return ".mp4";
case "jpg": return ".jpg";
case "txt": return ".txt";
default: return ".wav";
}
}
......
......@@ -6,6 +6,7 @@ package org.getalp.ligaikuma.lig_aikuma.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.getalp.ligaikuma.lig_aikuma.Aikuma;
......@@ -123,6 +124,7 @@ public class Language implements Parcelable, Comparable<Language> {
*
* @return A representation of the language as a JSONObject.
*/
// Never use
public JSONObject encode() {
JSONObject encodedLanguage = new JSONObject();
encodedLanguage.put("name", getName());
......@@ -157,17 +159,14 @@ public class Language implements Parcelable, Comparable<Language> {
for (Object langObj : languageArray) {
if (langObj instanceof JSONObject) {
JSONObject jsonLangObj = (JSONObject) langObj;
Language lang = null;
lang = new Language(
languages.add(new Language(
jsonLangObj.get("name").toString(),
jsonLangObj.get("code").toString());
languages.add(lang);
jsonLangObj.get("code").toString()));
} else {
String langCode = (String) langObj;
Language lang = new Language(
languages.add(new Language(
Aikuma.getLanguageCodeMap().get(langCode),
langCode);
languages.add(lang);
langCode));
}
}
......@@ -198,7 +197,7 @@ public class Language implements Parcelable, Comparable<Language> {
* @param that Language object compared with this object
* @return compare result of language
*/
public int compareTo(Language that) {
public int compareTo(@NonNull Language that) {
return name.compareTo(that.getName());
}
......
......@@ -15,7 +15,7 @@ public class MetadataSession {
private int speakerGender = 0;
private MetadataSession() {
extralanguages = new ArrayList<Language>();
extralanguages = new ArrayList<>();
regionOrigin = "";
speakerName = "";
}
......@@ -30,7 +30,8 @@ public class MetadataSession {
ref = new MetadataSession();
return ref;
}
// Never use
public static void clearSession() {
ref = null;
}
......@@ -61,7 +62,7 @@ public class MetadataSession {
return speakerName;
}
public String getSpeakerNote() {return speakerName;}
public String getSpeakerNote() {return speakerNote;}
public int getSpeakerAge() {
return speakerAge;
......@@ -85,20 +86,20 @@ public class MetadataSession {
}
private void setRecordLanguage(Language recordLang) {
recordLanguage = (recordLang != null) ? new Language(recordLang.getName(), recordLang.getCode())
: new Language("", "");
recordLanguage = (recordLang != null)? new Language(recordLang.getName(), recordLang.getCode()):
new Language("", "");
}
private void setMotherTongue(Language motherTong) {
motherTongue = (motherTong != null) ? new Language(motherTong.getName(), motherTong.getCode())
: new Language("", "");
motherTongue = (motherTong != null)? new Language(motherTong.getName(), motherTong.getCode()):
new Language("", "");
}
private void setExtraLanguages(ArrayList<Language> l) {
extralanguages = new ArrayList<Language>();
if (l != null)
for (Language lang : l)
extralanguages.add(new Language(lang.getName(), lang.getCode()));
extralanguages = new ArrayList<>();
if(l == null) return;
for(Language lang : l)
extralanguages.add(new Language(lang.getName(), lang.getCode()));
}
private void setRegionOrigin(String r) {
......@@ -122,7 +123,8 @@ public class MetadataSession {
public String toString() {
return "name : " + getSpeakerName() + " age : " + getSpeakerAge() + "speaker gender : " + getSpeakerGender() +
" region origin : " + getRegionOrigin() + " record lang : "+ getRecordLanguage().getName() +
" mother tongue : " + getMotherTongue().getName() + " rspk languages : " + getExtraLanguages().toString();
" mother tongue : " + getMotherTongue().getName() + " rspk languages : " + getExtraLanguages().toString() +
" note : " + getSpeakerNote();
}
}
......@@ -20,7 +20,7 @@ public class RecordingLig extends Recording {
public static final String TAG = "RecordingLig";
public static final String RECORDINGS = "recordings/";
public static final String WAV_EXT = ".wav";
public static final String PRVW_WAV_EXT = SAMPLE_SUFFIX;
public static final String PRVW_WAV_EXT = SAMPLE_SUFFIX; // Never use
public static final String MAP_EXT = ".map";
private Language recordLang;
......@@ -105,7 +105,8 @@ public class RecordingLig extends Recording {
this.motherTong = (motherTong != null) ? new Language(motherTong.getName(),motherTong.getCode())
: new Language("", "");
}
// Never use
public RecordingLig(UUID recordingUUID, String name, Date date,
String versionName, String ownerId,
List<Language> languages, List<String> speakersIds,
......
......@@ -74,8 +74,7 @@ public class Segments {
* @param respeakingSegment A respeaking segment corresponding to
* originalSegment.
*/
public void put(Segment originalSegment,
Segment respeakingSegment) {
public void put(Segment originalSegment, Segment respeakingSegment) {
segmentMap.put(originalSegment, respeakingSegment);
}
......@@ -105,8 +104,7 @@ public class Segments {
private void readSegments(File path) throws IOException {
String mapString = FileIO.read(path);
String[] lines = mapString.split("\n");
segmentMap =
new LinkedHashMap<Segment, Segment>();
segmentMap = new LinkedHashMap<Segment, Segment>();
for (String line : lines) {
String[] segmentMatch = line.split(":");
if (segmentMatch.length != 2) {
......@@ -146,12 +144,10 @@ public class Segments {
* @param endSample The sample at which the segment ends.
*/
public Segment(Long startSample, Long endSample) {
if (startSample == null) {
if(startSample == null)
throw new IllegalArgumentException("Null start of sample");
}
if (endSample == null) {
if(endSample == null)
throw new IllegalArgumentException("Null end of sample");
}
this.pair = new Pair<Long, Long>(startSample, endSample);
}
......@@ -179,11 +175,9 @@ public class Segments {
@Override
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;
Segment rhs = (Segment) obj;
return new EqualsBuilder()
.append(getStartSample(), rhs.getStartSample())
......@@ -199,7 +193,7 @@ public class Segments {
@Override
public String toString() {
String mapString = new String();
String mapString = "";
Segment respeakingSegment;
for (Segment originalSegment : segmentMap.keySet()) {
respeakingSegment = getRespeakingSegment(originalSegment);
......@@ -212,6 +206,7 @@ public class Segments {
return mapString;
}
// Never use
/**
* An exception thrown if the segment mapping file is incorrectly