Commit f597ed01 authored by mistermad's avatar mistermad

- Finalize previous commit cleanup

parent e100c387
......@@ -4,9 +4,7 @@
*/
package org.getalp.ligaikuma.lig_aikuma;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.AlertDialog;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
......@@ -14,9 +12,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;
import org.getalp.ligaikuma.lig_aikuma.util.AikumaSettings;
import org.getalp.ligaikuma.lig_aikuma.util.FileIO;
......@@ -24,10 +20,8 @@ import org.getalp.ligaikuma.lig_aikuma.util.FileIO;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Offers a collection of static methods that require a context independently
......@@ -85,6 +79,7 @@ public class Aikuma extends android.app.Application {
*
* @return The android ID as a String.
*/
@SuppressLint("HardwareIds")
public static String getAndroidID() {
return Secure.getString(appContext.getContentResolver(), Secure.ANDROID_ID);
}
......@@ -114,68 +109,7 @@ public class Aikuma extends android.app.Application {
return networkInfo != null && networkInfo.isConnected();
}
/**
* Check if the file is already archived/in the progress of archiving or not
*
* @param emailAccount Owner account of the file
* @param fm The file's model
* @return boolean of the archive status
*/
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static boolean isArchived(String emailAccount, FileModel fm) {
String itemCloudId = fm.getCloudIdentifier(0);
Set<String> approvedSet, archivedSet;
int archiveProgress = -1;
SharedPreferences privatePreferences = appContext.getSharedPreferences(emailAccount, MODE_PRIVATE);
String fileType = fm.getFileType();
switch (fileType) {
case "source":
case "respeaking":
approvedSet = privatePreferences.getStringSet(AikumaSettings.APPROVED_RECORDING_KEY, new HashSet<String>());
archivedSet = privatePreferences.getStringSet(AikumaSettings.ARCHIVED_RECORDING_KEY, new HashSet<String>());
break;
case "speaker":
approvedSet = privatePreferences.getStringSet(AikumaSettings.APPROVED_SPEAKERS_KEY, new HashSet<String>());
archivedSet = privatePreferences.getStringSet(AikumaSettings.ARCHIVED_SPEAKERS_KEY, new HashSet<String>());
break;
default:
approvedSet = privatePreferences.getStringSet(AikumaSettings.APPROVED_OTHERS_KEY, new HashSet<String>());
archivedSet = privatePreferences.getStringSet(AikumaSettings.ARCHIVED_OTHERS_KEY, new HashSet<String>());
break;
}
if(approvedSet.contains(itemCloudId))
archiveProgress = Integer.parseInt(privatePreferences.getString(itemCloudId, "").split("\\|")[1]);
return archivedSet.contains(itemCloudId) || (archiveProgress >= 0 && archiveProgress <= 3);
}
/**
* Return an arraylist of available google-accounts in a device
* @return ArrayList of google-accounts
*/
public static ArrayList<String> getGoogleAccounts() {
ArrayList<String> accountList = new ArrayList<>();
for(Account ac : AccountManager.get(appContext).getAccountsByType("com.google"))
accountList.add(ac.name);
return accountList;
}
/**
* Show the warning dialog with the message
* @param activity The activity where the message will be shown
* @param message the message shown in the dialog
*/
public static void showAlertDialog(Context activity, String message) {
new AlertDialog.Builder(activity).setMessage(message).show();
}
/**
* Returns the ISO 639-3 languages once they are loaded.
*
......@@ -209,7 +143,7 @@ public class Aikuma extends android.app.Application {
if(languages != null)
return;
languages = new ArrayList<>();
languageCodeMap = new HashMap<String, String>();
languageCodeMap = new HashMap<>();
setAppContext(context);
if(loadLangCodesThread == null || !loadLangCodesThread.isAlive()) {
loadLangCodesThread = new Thread(new Runnable() {
......
......@@ -97,12 +97,6 @@ public class ModeSelection extends Activity implements OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()) {
// DONE add a button for respeaking and link to the corresponding activity
// DONE create a selection view with 2 buttons: one for recording and one for importing audio
// DONE link the "recording" button to existing recording structure
// (link to recordingMetadataLig activity and allow RecordActivityLig to link to Respeaking)
// DONE study how resepaking is done and reuse it (only the respeaking view and its process)
// (in particular, beware to check the storage location of the respeaking and mapping files)
// TODO the last existing view of respeaking (summary) should allow to link back to the record/import selection view
// TODO then adapt the respeaking interface to allow the edition of latest segments
// TODO then adapt the summary view to allow the edition and playing of every segment
......@@ -127,9 +121,6 @@ public class ModeSelection extends Activity implements OnClickListener{
startActivity(new Intent(ModeSelection.this, CheckMode.class));
if(BuildConfig.DEBUG)Log.i(TAG, "Mode verification selected; view id: " + v.getId());
break;
// case R.id.button_mode_slct_old_aikuma:
// startActivity(new Intent(this,MainActivity.class));
// break;
}
}
......
......@@ -35,14 +35,10 @@ public class InterleavedPlayer extends Player {
public InterleavedPlayer(Recording recording) throws IOException {
setRecording(recording);
if (recording.isOriginal())
throw new IllegalArgumentException("The supplied Recording is " +
"not a respeaking. Use SimplePlayer instead.");
throw new IllegalArgumentException("The supplied Recording is " + "not a respeaking. Use SimplePlayer instead.");
setSampleRate(recording.getSampleRate());
original = new MarkedPlayer(
recording.getOriginal(),
new OriginalMarkerReachedListener(), true);
respeaking = new MarkedPlayer(recording,
new RespeakingMarkerReachedListener(), true);
original = new MarkedPlayer(recording.getOriginal(), new OriginalMarkerReachedListener(), true);
respeaking = new MarkedPlayer(recording, new RespeakingMarkerReachedListener(), true);
segments = new Segments(recording);
initializeCompletionListeners();
completedOnce = false;
......@@ -148,11 +144,10 @@ public class InterleavedPlayer extends Player {
// Plays the specified segment in the specified player.
private void playSegment(Segment segment, MarkedPlayer player) {
if(segment != null) {
player.seekTo(segment);
player.setNotificationMarkerPosition(segment);
player.play();
}
if(segment == null) return;
player.seekTo(segment);
player.setNotificationMarkerPosition(segment);
player.play();
}
// Moves forward to the next original segment in the recording.
......@@ -223,8 +218,7 @@ public class InterleavedPlayer extends Player {
//If the sample rate is less than zero, then this indicates that there
//wasn't a sample rate found in the metadata file.
if (sampleRate <= 0l)
throw new RuntimeException(
"The sampleRate of the recording is not known.");
throw new RuntimeException("The sampleRate of the recording is not known.");
return sampleRate;
}
......@@ -252,10 +246,9 @@ public class InterleavedPlayer extends Player {
reset();
while(getOriginalSegmentIterator().hasNext()) {
currentOriginalSegment = getOriginalSegmentIterator().next();
int start = sampleToMsec(currentOriginalSegment.getStartSample());
int end = sampleToMsec(currentOriginalSegment.getEndSample());
//Log.i("interleaved", msec + " / " + this.getDurationMsec() + ": (" + start + ", " + end + ")");
if(msec >= start && msec <= end) break; // TODO: What ! ? !
if(msec >= sampleToMsec(currentOriginalSegment.getStartSample()) &&
msec <= sampleToMsec(currentOriginalSegment.getEndSample()))
break;
}
}
......@@ -264,8 +257,7 @@ public class InterleavedPlayer extends Player {
*
* @param listener The callback to call when playing is complete.
*/
public void setOnCompletionListener(
final Player.OnCompletionListener listener) {
public void setOnCompletionListener(final Player.OnCompletionListener listener) {
this.onCompletionListener = listener;
}
......
/*
Copyright (C) 2013, The Aikuma Project
AUTHORS: Oliver Adams and Florian Hanke
*/
package org.getalp.ligaikuma.lig_aikuma.audio;
/**
* Provides methods to process audio buffers - at the moment a single method to
* determine the average amplitude.
*
* @author Florian Hanke <florian.hanke@gmail.com>
* @author Oliver Adams <oliver.adams@gmail.com>
*/
public class Processor {
/** Evaluates the average amplitude.
*
* @param buffer The buffer containing the audio data.
* @return Average amplitude of the buffer.
*/
public int getAverage(short[] buffer) {
int sum = 0, amount = 0;
for(int i = 0; i < buffer.length; i++)
if (buffer[i] < 0) {
sum += buffer[i];
amount++;
}
return amount == 0 ? 0 : sum/amount;
}
}
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;
import java.io.File;
import java.io.IOException;
public class SegmentPlayer extends MarkedPlayer
{
private Segment segment;
private OnMarkerReachedListener onMarkerReachedListener;
public SegmentPlayer(SimplePlayer player, Segment s, boolean playThroughSpeaker,
final Activity activity) throws IOException {
super(player, playThroughSpeaker);
......
......@@ -6,7 +6,6 @@ package org.getalp.ligaikuma.lig_aikuma.audio.record.recognizers;
import android.util.Log;
import org.getalp.ligaikuma.lig_aikuma.audio.Processor;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.BuildConfig;
/**
......@@ -21,11 +20,6 @@ public class AverageRecognizer extends Recognizer {
/** The threshold above which sound is detected.*/
protected int speechThreshold;
/**
* Sets up the processor that tells us the average amplitude.
*/
protected Processor processor = new Processor();
/**
* Default Constructor.
*
......@@ -54,16 +48,27 @@ public class AverageRecognizer extends Recognizer {
@Override
public boolean isSilence(short[] buffer) {
int reading = processor.getAverage(buffer);
int reading = getAverage(buffer);
if(BuildConfig.DEBUG)Log.i("sound", "reading: " + reading + ", silenceThreshold: " + silenceThreshold);
return reading < silenceThreshold;
}
@Override
public boolean isSpeech(short[] buffer) {
int reading = processor.getAverage(buffer);
int reading = getAverage(buffer);
if(BuildConfig.DEBUG)Log.i("sound", "silent reading: " + reading + ", silenceThreshold: " + silenceThreshold);
return reading > speechThreshold;
}
private int getAverage(short[] buffer) {
int sum = 0, amount = 0;
for (short aBuffer : buffer)
if (aBuffer < 0) {
sum += aBuffer;
amount++;
}
return amount == 0 ? 0 : sum / amount;
}
}
......@@ -29,65 +29,8 @@ public class AikumaSettings {
* Setting value for sync-only-over-wifi
*/
public static boolean isOnlyWifi;
// Current default owner_id(== default Google account)
private static String DEFAULT_USER_ID = null;
// Current default owner_auth_token(== default Google API access_token)
private static String DEFAULT_USER_AUTH_TOKEN = null;
private static String DEFAULT_USER_ID_TOKEN = null;
private static String DEFAULT_INDEX_SERVER = "https://aikuma.info:443/index";
private static String DEFAULT_INDEX_SERVER_CLIENT_ID = "530026557211-46brcqr1p4ltlru6j6duc0am14oh83ei.apps.googleusercontent.com";
/**
* Account of central fusion table
*/
public static String CENTRAL_USER_ID = "lp20.org@gmail.com";
/**
* Temporary ID for all root-folder (TODO: might be changed depending on project folder structures)
*/
public static String ROOT_FOLDER_ID = "asdf";
private static int numOfUsers;
private static int numOfSpeakers;
private static int numOfItems;
private static float ratioOfFtpSync;
private static float ratioOfCloudSync;
private static float ratioOfCentralSync;
/**
* Key for a versionName in default SharedPreferences
*/
public static final String SETTING_VERSION_KEY = "version";
/**
* Key for a current user ID in default SharedPreferences
*/
public static final String SETTING_OWNER_ID_KEY = "ownersID";
/**
* Key for a current user ID's auth_token in default SharedPreferences
*/
public static final String SETTING_AUTH_TOKEN_KEY = "userToken";
/**
* Key for current user ID's google ID token in default SharedPreferences
*/
public static final String SETTING_ID_TOKEN_KEY = "userIdToken";
/**
* Key for a ratio of backup to Google Drive in default SharedPreferences
*/
public static final String SETTING_CLOUD_RATIO_KEY = "cloudSyncRatio";
/**
* Key for a ratio of central-archive in default SharedPreferences
*/
public static final String SETTING_CENTRAL_RATIO_KEY = "centralSyncRatio";
/**
* Key for index server url
*/
public static final String SETTING_INDEX_SERVER_URL = "indexServerUrl";
/**
* Sync time interval (30min)
*/
public static final long SYNC_INTERVAL = 30 * 60 * 1000;
/**
* Extra audio recording duration after a thumb is lifted or head becomes far away
*/
......@@ -137,26 +80,14 @@ public class AikumaSettings {
*/
public static final String APPROVED_RECORDING_KEY = "approvedRecordings";
/** */
public static final String DOWNLOAD_RECORDING_KEY = "downloadRecordings";
/** */
public static final String UPLOAD_RECORDING_KEY = "uploadRecordings";
/** */
public static final String ARCHIVED_RECORDING_KEY = "archivedRecordings";
/** */
public static final String APPROVED_SPEAKERS_KEY = "approvedSpeakers";
/** */
public static final String DOWNLOAD_SPEAKERS_KEY = "downloadSpeakers";
/** */
public static final String UPLOAD_SPEAKERS_KEY = "uploadSpeakers";
/** */
public static final String ARCHIVED_SPEAKERS_KEY = "archivedSpeakers";
/** */
public static final String APPROVED_OTHERS_KEY = "approvedOthers";
/** */
public static final String DOWNLOAD_OTHERS_KEY = "downloadOthers";
/** */
public static final String UPLOAD_OTHERS_KEY = "uploadOthers";
/** */
public static final String ARCHIVED_OTHERS_KEY = "archivedOthers";
......@@ -186,151 +117,5 @@ public class AikumaSettings {
public static void setUserId(String Id) {
DEFAULT_USER_ID = Id;
}
/**
* Return current default owner account's auth-token
* @return String of default owner account's auth-token
*/
public static String getCurrentUserToken() {
return DEFAULT_USER_AUTH_TOKEN;
}
/**
* Set the default owner account's auth-token
* @param token String of default owner account's auth-token
*/
public static void setUserToken(String token) {
DEFAULT_USER_AUTH_TOKEN = token;
}
/**
* Return current default owner account's ID token.
* @return String of default owner account's ID token.
*/
public static String getCurrentUserIdToken() {
return DEFAULT_USER_ID_TOKEN;
}
/**
* Set the default owner account's ID token.
* @param token String of default owner account's ID token.
*/
public static void setUserIdToken(String token) {
DEFAULT_USER_ID_TOKEN = token;
}
/**
* Return current number of users
* @return the number of users
*/
public static int getNumberOfUsers() {
return numOfUsers;
}
/**
* Set the number of users
* @param num the number of users
*/
public static void setNumberOfUsers(int num) {
numOfUsers = num;
}
/**
* Return current number of speakers
* @return the number of speakers
*/
public static int getNumberOfSpeakers() {
return numOfSpeakers;
}
/**
* Set the number of speakers
* @param num the number of speakers
*/
public static void setNumberOfSpeakers(int num) {
numOfSpeakers = num;
}
/**
* Return current number of items
* @return the number of items
*/
public static int getNumberOfItems() {
return numOfItems;
}
/**
* Set the number of items
* @param num the number of items
*/
public static void setNumberOfItems(int num) {
numOfItems = num;
}
/**
* Return current ftp upload ratio
* @return the ratio of ftp-upload success
*/
public static float getFtpRatio() {
return ratioOfFtpSync;
}
/**
* Set the current ftp upload ratio
* @param ratio the ratio of ftp-upload success
*/
public static void setFtpRatio(float ratio) {
ratioOfFtpSync = ratio;
}
/**
* Return current Cloud upload ratio
* @return the ratio of Cloud-upload success
*/
public static float getCloudRatio() {
return ratioOfCloudSync;
}
/**
* Set the current cloud upload ratio
* @param ratio the ratio of cloud-upload success
*/
public static void setCloudRatio(float ratio) {
ratioOfCloudSync = ratio;
}
/**
* Return current central upload ratio
* @return the ratio of central-upload success
*/
public static float getCentralRatio() {
return ratioOfCentralSync;
}
/**
* Set the current central upload ratio
* @param ratio the ratio of central-upload success
*/
public static void setCentralRatio(float ratio) {
ratioOfCentralSync = ratio;
}
/**
* Return the URL of the index server.
* @return the URL of the index server.
*/
public static String getIndexServerUrl() {
return DEFAULT_INDEX_SERVER;
}
/**
* Set the URL of the index server.
* @param url URL of central index-server
*/
public static void setIndexServerUrl(String url) {
DEFAULT_INDEX_SERVER = url;
}
/**
* Return a scope for a client ID of web-application
* @return The scope for the web-application(central index-server)
*/
public static String getIdTokenScope() {
return "audience:server:client_id:" + DEFAULT_INDEX_SERVER_CLIENT_ID;
}
}
......@@ -83,14 +83,8 @@
<string name="no">No</string>
<string name="an_error_occurred_the_text_file_could_not_be_found">An error occurred, the text file could not be found.</string>
<string name="something_weird_happened_it_might_be_that_the_text_file_was_empty">Something weird happened. It might be that the text file was empty.</string>
<string name="items_are_queued_to_be_downloaded">items are queued to be downloaded.</string>
<string name="the_session_has_been_saved">The session has been saved.</string>
<string name="no_more_words_to_display_file_saved_in">No more words to display. File saved in</string>
<string name="sample_is_downloaded">Sample downloaded.</string>
<string name="failed_to_read_recording_metadata">Failed to read recording metadata.</string>
<string name="failed_to_create_player_from_recording">Failed to create player from recording.</string>
<string name="Failed_to_read_recording_metadata">Failed to read recording metadata.</string>
<string name="this_will_discard_the_new_data_are_you_sure">This will discard the new data. Are you sure?</string>
<string name="error_setting_up_microphone">Error setting up microphone.</string>
<string name="discard_udio">Discard Audio?</string>
<string name="male">Male</string>
......@@ -126,7 +120,6 @@
<string name="please_fill_the_translating_language_field">Please, fill in the translating language field.</string>
<string name="please_fill_the_name_of_the_speaker">Please, fill in the name of the speaker.</string>
<string name="failed_to_import_the_recording_">Failed to import the recording.</string>
<string name="failed_to_write_default_sensitivity_setting_to_file">Failed to write default sensitivity setting to file</string>
<string name="there_has_been_an_error_stopping_the_microphone">There has been an error stopping the microphone.</string>
<string name="there_has_been_an_error_writing_the_mapping_between_original_and_respeaking_to_file">There has been an error writing the mapping between original and respeaking to file</string>
<string name="respeaking_saved_into_the_file">Respeaking saved into the file: </string>
......
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