Commit 0052cb14 authored by mistermad's avatar mistermad
Browse files

- Bugs fix on Elicitation mode

parent 00cc5c41
......@@ -2,12 +2,12 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.getalp.ligaikuma.lig_aikuma.lig_aikuma"
android:versionCode="1"
android:versionName="1.0"
>
android:versionName="1.0">
<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"/>
......
......@@ -106,12 +106,10 @@ public class Aikuma extends android.app.Application {
public static boolean isDeviceOnline() {
if(preferences == null) {
preferences = PreferenceManager.getDefaultSharedPreferences(appContext);
AikumaSettings.isOnlyWifi =
preferences.getBoolean(AikumaSettings.WIFI_MODE_KEY, true);
AikumaSettings.isOnlyWifi = preferences.getBoolean(AikumaSettings.WIFI_MODE_KEY, true);
}
ConnectivityManager connMgr = (ConnectivityManager)
appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
ConnectivityManager connMgr = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = (AikumaSettings.isOnlyWifi)?
connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI):
connMgr.getActiveNetworkInfo();
......@@ -130,12 +128,10 @@ public class Aikuma extends android.app.Application {
public static boolean isArchived(String emailAccount, FileModel fm) {
String itemCloudId = fm.getCloudIdentifier(0);
Set<String> approvedSet;
Set<String> archivedSet;
Set<String> approvedSet, archivedSet;
int archiveProgress = -1;
SharedPreferences privatePreferences =
appContext.getSharedPreferences(emailAccount, MODE_PRIVATE);
SharedPreferences privatePreferences = appContext.getSharedPreferences(emailAccount, MODE_PRIVATE);
String fileType = fm.getFileType();
switch (fileType) {
case "source":
......@@ -148,19 +144,13 @@ public class Aikuma extends android.app.Application {
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>());
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)) {
String[] requestArchiveState =
privatePreferences.getString(itemCloudId, "").split("\\|");
archiveProgress =
Integer.parseInt(requestArchiveState[1]);
}
if(approvedSet.contains(itemCloudId))
archiveProgress = Integer.parseInt(privatePreferences.getString(itemCloudId, "").split("\\|")[1]);
return archivedSet.contains(itemCloudId) || (archiveProgress >= 0 && archiveProgress <= 3);
}
......@@ -171,9 +161,8 @@ public class Aikuma extends android.app.Application {
*/
public static ArrayList<String> getGoogleAccounts() {
ArrayList<String> accountList = new ArrayList<>();
Account[] accounts = AccountManager.get(appContext).getAccountsByType("com.google");
for(Account ac : accounts)
for(Account ac : AccountManager.get(appContext).getAccountsByType("com.google"))
accountList.add(ac.name);
return accountList;
......@@ -245,26 +234,4 @@ public class Aikuma extends android.app.Application {
* main thread.
*/
public static Thread loadLangCodesThread;
}
/*
public class Aikuma extends android.app.Application {
private static Context context;
public void onCreate() {
super.onCreate();
Aikuma.context = getApplicationContext();
}
public static Context getAppContext() {
return Aikuma.context;
}
public static String getAndroidID() {
return Secure.getString(
getAppContext().getContentResolver(), Secure.ANDROID_ID);
}
}
*/
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentTransaction;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
......@@ -69,8 +68,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.UUID;
//import android.support.v4.app.DialogFragment; //Un peu old mais on ne va pas refaire le monde
// For audio imports
/**
......@@ -102,8 +99,7 @@ public class MainActivity extends ListActivity {
actionBar.setDisplayShowTitleEnabled(false);
// Load setting values
SharedPreferences settings =
PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
// settings.edit().clear().commit();
emailAccount = settings.getString(AikumaSettings.SETTING_OWNER_ID_KEY, null);
......@@ -114,23 +110,18 @@ public class MainActivity extends ListActivity {
AikumaSettings.setUserId(emailAccount);
showUserAccount(emailAccount, null);
AikumaSettings.isBackupEnabled =
settings.getBoolean(AikumaSettings.BACKUP_MODE_KEY, false);
AikumaSettings.isAutoDownloadEnabled =
settings.getBoolean(AikumaSettings.AUTO_DOWNLOAD_MODE_KEY, false);
AikumaSettings.isBackupEnabled = settings.getBoolean(AikumaSettings.BACKUP_MODE_KEY, false);
AikumaSettings.isAutoDownloadEnabled = settings.getBoolean(AikumaSettings.AUTO_DOWNLOAD_MODE_KEY, false);
// Automatic validation
if(emailAccount != null) {
// Validate access token
// (And if there are items to be archived, upload them)
if (Aikuma.isDeviceOnline()) {
new GetTokenTask(emailAccount, googleAPIScope,
settings, false).execute();
} else {
Toast.makeText(this, "Network is disconnected",
Toast.LENGTH_SHORT).show();
}
if (Aikuma.isDeviceOnline())
new GetTokenTask(emailAccount, googleAPIScope, settings, false).execute();
else
Toast.makeText(this, "Network is disconnected", Toast.LENGTH_SHORT).show();
} else if(AikumaSettings.isBackupEnabled
|| AikumaSettings.isAutoDownloadEnabled) {
......@@ -147,18 +138,14 @@ public class MainActivity extends ListActivity {
public void onReceive(Context context, Intent intent) {
String status = intent.getStringExtra(GoogleCloudService.SYNC_STATUS);
if(status.equals("start")) {
if(status.equals("start"))
showProgressStatus(View.VISIBLE);
} else if(status.equals("end")) {
else if(status.equals("end"))
showProgressStatus(View.GONE);
} else if(status.endsWith("source")) { //source-download
else if(status.endsWith("source")) { //source-download
String[] splitName = status.split("-");
String verName = splitName[0];
String ownerId = splitName[2];
String recordingId = status.substring(4);
try {
updateRecordingView(Recording.read(verName, ownerId, recordingId));
updateRecordingView(Recording.read(splitName[0], splitName[2], status.substring(4)));
} catch (IOException e) {
if(BuildConfig.DEBUG)Log.e(TAG, e.getMessage());
}
......@@ -176,8 +163,7 @@ public class MainActivity extends ListActivity {
//TODO: Update existing files
/*
String appVersionName =
settings.getString(AikumaSettings.SETTING_VERSION_KEY, "");
String appVersionName = settings.getString(AikumaSettings.SETTING_VERSION_KEY, "");
if(!appVersionName.equals(AikumaSettings.getLatestVersion())) {
// Update the file structure and metadata
new UpdateUtils(this).update();
......@@ -209,12 +195,11 @@ public class MainActivity extends ListActivity {
if(BuildConfig.DEBUG)Log.i(TAG, "num: " +recordings.size());
// Filter the recordings for originals
originals = new ArrayList<Recording>();
for (Recording recording : recordings) {
if (recording.isOriginal()) {
originals = new ArrayList<>();
for(Recording recording : recordings)
if(recording.isOriginal())
originals.add(recording);
}
}
if(BuildConfig.DEBUG)Log.i(TAG, "original num: " + originals.size());
adapter = new RecordingArrayAdapter(this, originals);
......@@ -223,7 +208,7 @@ public class MainActivity extends ListActivity {
adapter.getFilter().filter(searchView.getQuery());
}*/
setListAdapter(adapter);
if (listViewState != null)
if(listViewState != null)
getListView().onRestoreInstanceState(listViewState);
MainActivity.locationDetector.start();
......@@ -232,8 +217,7 @@ public class MainActivity extends ListActivity {
@Override
protected void onStart() {
super.onStart();
LocalBroadcastManager.getInstance(this).registerReceiver(
syncReceiver, new IntentFilter(GoogleCloudService.SYNC_RESULT));
LocalBroadcastManager.getInstance(this).registerReceiver(syncReceiver, new IntentFilter(GoogleCloudService.SYNC_RESULT));
showProgressStatus(View.GONE);
}
......@@ -254,7 +238,6 @@ public class MainActivity extends ListActivity {
Recording recording = (Recording) getListAdapter().getItem(position);
if(emailAccount == null) {
Aikuma.showAlertDialog(this, "You need to select your account");
return;
}
......@@ -278,9 +261,7 @@ public class MainActivity extends ListActivity {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent intent = new Intent(
android.provider.Settings.ACTION_DATE_SETTINGS);
Intent intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
startActivityForResult(intent, PICK_DATE_REQUEST_CODE);
}
}).show();
......@@ -392,16 +373,13 @@ public class MainActivity extends ListActivity {
else {
Intent syncIntent = new Intent(this, GoogleCloudService.class);
syncIntent.putExtra(GoogleCloudService.ACTION_KEY, "sync");
syncIntent.putExtra(GoogleCloudService.ACCOUNT_KEY,
AikumaSettings.getCurrentUserId());
syncIntent.putExtra(GoogleCloudService.TOKEN_KEY,
AikumaSettings.getCurrentUserToken());
syncIntent.putExtra(GoogleCloudService.ACCOUNT_KEY, AikumaSettings.getCurrentUserId());
syncIntent.putExtra(GoogleCloudService.TOKEN_KEY, AikumaSettings.getCurrentUserToken());
syncIntent.putExtra("forceSync", true);
startService(syncIntent);
}
} else {
SharedPreferences settings =
getSharedPreferences(AikumaSettings.getCurrentUserId(), MODE_PRIVATE);
SharedPreferences settings = getSharedPreferences(AikumaSettings.getCurrentUserId(), MODE_PRIVATE);
int sz = 0;
sz += settings.getStringSet(AikumaSettings.APPROVED_RECORDING_KEY, new HashSet<String>()).size();
......@@ -428,7 +406,8 @@ public class MainActivity extends ListActivity {
private List<Recording> originals;
SearchView searchView;
//TODO: START CLEANING
MenuBehaviour menuBehaviour;
private RecordingArrayAdapter adapter;
......@@ -449,17 +428,13 @@ public class MainActivity extends ListActivity {
int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (statusCode == ConnectionResult.SUCCESS) {
if(BuildConfig.DEBUG)Log.i(TAG, "getAccountToken");
//TODO: Sign-out, Sign-in with other accounts
if(AikumaSettings.getCurrentUserId() == null)
pickUserAccount();
} else if (GooglePlayServicesUtil.isUserRecoverableError(statusCode)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, this, 0 /* request code not used */);
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode, this, 0 );/* request code not used */
dialog.show();
} else {
} else
Toast.makeText(this, "Unrecoverable Google-Play Services error", Toast.LENGTH_LONG).show();
}
}
/**
......@@ -480,56 +455,45 @@ public class MainActivity extends ListActivity {
/**
* Start an activity which allows a user to pick up an account
*/
private void pickUserAccount() {
String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
accountTypes, false, " (Default Google-account)",
null, null, null);
startActivityForResult(intent, PICK_ACCOUNT_REQUEST_CODE);
private void pickUserAccount()
{
startActivityForResult(AccountPicker.newChooseAccountIntent(null, null,
new String[]{"com.google"}, false, " (Default Google-account)",
null, null, null), PICK_ACCOUNT_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_ACCOUNT_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
SharedPreferences settings =
PreferenceManager.getDefaultSharedPreferences(this);
emailAccount =
data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
emailAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
// Stores the account for next-use
AikumaSettings.setUserId(emailAccount);
showUserAccount(emailAccount, null);
menuBehaviour.setSignInState(true);
settings.edit().putString(AikumaSettings.SETTING_OWNER_ID_KEY, emailAccount).commit();
settings.edit().putString(AikumaSettings.SETTING_OWNER_ID_KEY, emailAccount).apply();
if (Aikuma.isDeviceOnline()) {
new GetTokenTask(emailAccount, googleAPIScope,
settings, false).execute();
} else {
Toast.makeText(this, "Network is disconnected",
Toast.LENGTH_SHORT).show();
}
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "You must pick up an account",
Toast.LENGTH_SHORT).show();
}
if(Aikuma.isDeviceOnline())
new GetTokenTask(emailAccount, googleAPIScope, settings, false).execute();
else
Toast.makeText(this, "Network is disconnected", Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED)
Toast.makeText(this, "You must pick up an account", Toast.LENGTH_SHORT).show();
} else if ((requestCode == RECOVER_FROM_AUTH_ERROR_REQUEST_CODE ||
requestCode == RECOVER_FROM_GOOGLEPLAY_ERROR_REQUEST_CODE)
&& resultCode == RESULT_OK) {
handleReRequestResult(resultCode, data);
return;
} else if(requestCode == PICK_DATE_REQUEST_CODE) {
} else if(requestCode == PICK_DATE_REQUEST_CODE)
checkDate();
}
super.onActivityResult(requestCode, resultCode, data);
}
private void handleReRequestResult(int resultCode, Intent data) {
if (data == null) {
Toast.makeText(this, "Unknown error, Retry it",
Toast.LENGTH_LONG).show();
Toast.makeText(this, "Unknown error, Retry it", Toast.LENGTH_LONG).show();
return;
}
if (resultCode == RESULT_OK) {
......@@ -546,8 +510,7 @@ public class MainActivity extends ListActivity {
// show("User rejected authorization.");
// return;
// }
Toast.makeText(this, "Unknown error, Retry it",
Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Unknown error, Retry it", Toast.LENGTH_SHORT).show();
}
/**
......@@ -571,10 +534,8 @@ public class MainActivity extends ListActivity {
// When authenticate failed
// (User has not yet accessed to the account)
// Show an activity for user's re-login Google Play services.
Intent intent =
((UserRecoverableAuthException)e).getIntent();
startActivityForResult(intent,
RECOVER_FROM_AUTH_ERROR_REQUEST_CODE);
Intent intent = ((UserRecoverableAuthException)e).getIntent();
startActivityForResult(intent, RECOVER_FROM_AUTH_ERROR_REQUEST_CODE);
}
}
});
......@@ -612,15 +573,16 @@ public class MainActivity extends ListActivity {
preferences.edit()
.putString(AikumaSettings.SETTING_AUTH_TOKEN_KEY, googleAuthToken)
.putString(AikumaSettings.SETTING_ID_TOKEN_KEY, googleIdToken)
.commit();
.apply();
AikumaSettings.setUserToken(googleAuthToken);
AikumaSettings.setUserIdToken(googleIdToken);
} catch (IOException e) {
if(BuildConfig.DEBUG)Log.e(TAG, e.getMessage());
return false;
}
if(BuildConfig.DEBUG)Log.i(TAG, "access token: " + googleAuthToken);
if(BuildConfig.DEBUG)Log.i(TAG, "identity token: " + googleIdToken);
if(BuildConfig.DEBUG){Log.i(TAG, "access token: " + googleAuthToken);
Log.i(TAG, "identity token: " + googleIdToken);
}
return true;
}
......@@ -692,7 +654,15 @@ public class MainActivity extends ListActivity {
* for.
*/
private void loadFileList(File dir, final String fileType) {
if(dir.exists()) {
mFileList = (dir.exists())?
mPath.list(new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.contains(fileType) || new File(dir, filename).isDirectory();
}}):
new String[0];
}
/* OLD
if(dir.exists()) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String filename) {
File sel = new File(dir, filename);
......@@ -703,15 +673,14 @@ public class MainActivity extends ListActivity {
}
else
mFileList = new String[0];
}
*/
/**
* Presents the dialog for choosing audio files to the user.
*/
private void showAudioFilebrowserDialog()
{
FragmentTransaction ft = getFragmentManager().beginTransaction();
new FilebrowserDialogFragment().show(ft, "dialog");
new FilebrowserDialogFragment().show(getFragmentManager().beginTransaction(), "dialog");
}
......@@ -724,14 +693,12 @@ public class MainActivity extends ListActivity {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Import audio file");
if(mFileList == null) {
if(BuildConfig.DEBUG)Log.e("importfile", "Showing file picker before loading the file list");
dialog = builder.create();
return dialog;
return builder.create();
}
builder.setItems(mFileList, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
......@@ -750,20 +717,16 @@ public class MainActivity extends ListActivity {
try {
Wave wave = new Wave(new FileInputStream(mPath));
String format = wave.getWaveHeader().getFormat();
int sampleRate = wave.getWaveHeader().getSampleRate();
int durationMsec = (int) wave.length() * 1000;
int bitsPerSample = wave.getWaveHeader().getBitsPerSample();
int numChannels = wave.getWaveHeader().getChannels();
int sampleRate = wave.getWaveHeader().getSampleRate(),
durationMsec = (int) wave.length() * 1000,
bitsPerSample = wave.getWaveHeader().getBitsPerSample(),
numChannels = wave.getWaveHeader().getChannels();
//Copy the file to the no-sync directory.
try {
FileUtils.copyFile(mPath,
new File(Recording.getNoSyncRecordingsPath(),
uuid.toString() + ".wav"));
FileUtils.copyFile(mPath, new File(Recording.getNoSyncRecordingsPath(), uuid.toString() + ".wav"));
} catch (IOException e) {
Toast.makeText(getActivity(),
"Failed to import the recording.",
Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), "Failed to import the recording.", Toast.LENGTH_LONG).show();
}
// Pass the info along to RecordingMetadataActivity.
......@@ -780,12 +743,10 @@ public class MainActivity extends ListActivity {
// This shouldn't be happening.
throw new RuntimeException(e);
}
}
}
});
dialog = builder.show();
return dialog;
return builder.show();
}
}
......@@ -799,5 +760,4 @@ public class MainActivity extends ListActivity {
* Location-service variable which can be accessed by all other activities
*/
public static LocationDetector locationDetector;
}
......@@ -44,6 +44,8 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.semantive.waveformandroid.waveform.MediaPlayerFactory;
public class ModeSelection extends Activity implements OnClickListener{
private static final String TAG = "ModeSelection";
......@@ -163,7 +165,7 @@ public class ModeSelection extends Activity implements OnClickListener{
DialogFragment dialog = new UserSessionDiaglogFragment();
dialog.show(getFragmentManager(), "SessionDialogFragment");
}
@SuppressLint("ValidFragment")
public class UserSessionDiaglogFragment extends DialogFragment {
@Override
......@@ -210,7 +212,8 @@ public class ModeSelection extends Activity implements OnClickListener{
return builder.create();
}
public void retrieveSession() {
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) == 0)
......@@ -243,17 +246,22 @@ public class ModeSelection extends Activity implements OnClickListener{
String mode = prefsUserSession.getString("mode", "undefined");
String submode = prefsUserSession.getString("submode", "undefined");
String modeDialog = null, submodeDialog = null;
if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || mode.compareTo(CheckTranscription.TAG) == 0) {
modeDialog = getString(R.string.check_mode);
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) {
modeDialog = getString(R.string.elicitation);
}
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
{
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) {
if (submode.compareToIgnoreCase(getString(R.string.respeak)) == 0) modeDialog = "Respeaking";
else if (submode.compareToIgnoreCase(getString(R.string.translation)) == 0) modeDialog = "Translation";
}
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
{
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);
......@@ -273,7 +281,11 @@ public class ModeSelection extends Activity implements OnClickListener{
// display only filename
String file = new File(prefsUserSession.getString("inputFile", "undefined")).getName();
((TextView) ll.findViewById(R.id.session_input_file)).setText(file);
((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";
Log.d(TAG,MediaPlayerFactory._currentReadFile);