Commit 132407ab authored by mistermad's avatar mistermad

- Merge file import buttons

- Added "Unspecified" gender
- Fixed a bug affecting seekbar
- Global rewriting for performance and stability
parent 0c4d01ce
......@@ -224,7 +224,7 @@
android:configChanges="orientation|screenSize" />
<!--<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RecordElicitationImage"
android:configChanges="orientation|screenSize" /> Introuvqable dans le projet-->
android:configChanges="orientation|screenSize" /> Not found in project-->
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.CheckMode"
android:configChanges="orientation|screenSize" />
......
......@@ -34,7 +34,7 @@ public class Audio {
*/
public static void playThroughEarpiece(Activity activity, boolean toSetMode) {
AudioManager audioManager = getAudioManager(activity);
if (toSetMode)
if(toSetMode)
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(false);
}
......
......@@ -19,8 +19,8 @@ import java.io.IOException;
* @author Oliver Adams <oliver.adams@gmail.com>
* @author Florian hanke <florian.hanke@gmail.com>
*/
public class MarkedPlayer extends SimplePlayer {
public class MarkedPlayer extends SimplePlayer
{
/**
* Constructor
*
......@@ -101,15 +101,15 @@ public class MarkedPlayer extends SimplePlayer {
else unsetNotificationMarkerPosition();
}
/**
* Sets the notificaiton marker position to be at the specified sample.
*
* @param sample The sample at which the notification marker is to be
* set.
*/
public void setNotificationMarkerPositionSample(Long sample) {
///**
// * Sets the notificaiton marker position to be at the specified sample.
// *
// * @param sample The sample at which the notification marker is to be
// * set.
// */
/*public void setNotificationMarkerPositionSample(Long sample) {
setNotificationMarkerPositionMsec(sampleToMsec(sample));
}
}*/
/**
* Removes the marker if it has been set.
......@@ -167,8 +167,7 @@ public class MarkedPlayer extends SimplePlayer {
*
* @param onMarkerReachedListener the listener to be notified.
*/
public void setOnMarkerReachedListener(OnMarkerReachedListener
onMarkerReachedListener) {
public void setOnMarkerReachedListener(OnMarkerReachedListener onMarkerReachedListener) {
this.onMarkerReachedListener = onMarkerReachedListener;
}
......@@ -177,12 +176,10 @@ public class MarkedPlayer extends SimplePlayer {
// Stops the notification marker loop.
private void stopNotificationMarkerLoop() {
if (notificationMarkerLoop != null) {
if(notificationMarkerLoop != null)
notificationMarkerLoop.interrupt();
}
}
private static int count = 0;
/**
* Implements a run that polls the current position to check
......@@ -229,6 +226,7 @@ public class MarkedPlayer extends SimplePlayer {
private Thread notificationMarkerLoop;
private static final String TAG = "MarkedPlayer";
private static int count = 0;
//////////////////////////////////////////////////////////////////////////
......
......@@ -9,11 +9,9 @@ import android.media.MediaPlayer;
import android.util.Log;
import org.getalp.ligaikuma.lig_aikuma.model.Recording;
import org.getalp.ligaikuma.lig_aikuma.util.FileIO;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
/**
* A wrapper class for android.media.MediaPlayer that makes simpler the task of
......@@ -106,9 +104,8 @@ public class SimplePlayer extends Player implements Sampler
* @param rewindAmount in msec
*/
public void rewind(int rewindAmount) {
int currentPos = getCurrentMsec(), rewindedPos = (currentPos-rewindAmount);
rewindedPos = (rewindedPos < 0)? 0 : rewindedPos;
seekToMsec(rewindedPos);
int rewindedPos = (getCurrentMsec()-rewindAmount);
seekToMsec((rewindedPos < 0)? 0 : rewindedPos);
}
/**
......@@ -148,9 +145,6 @@ public class SimplePlayer extends Player implements Sampler
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;
}
}
......@@ -223,12 +217,12 @@ public class SimplePlayer extends Player implements Sampler
});
}
/**
* Increment the view count by adding a view file to the Recording's view
* directory.
*/
///**
// * Increment the view count by adding a view file to the Recording's view
// * directory.
// */
//Never use
private void incrementViewCount() throws IOException {
/*private void incrementViewCount() throws IOException {
String versionName = recording.getVersionName();
String ownerId = recording.getOwnerId();
File viewDir = new File(FileIO.getOwnerPath(versionName, ownerId),
......@@ -238,7 +232,7 @@ public class SimplePlayer extends Player implements Sampler
File viewFile = new File(viewDir, UUID.randomUUID() + ".view");
viewFile.createNewFile();
}
}*/
/**
* Returns the sample rate of this recording
......@@ -248,7 +242,7 @@ public class SimplePlayer extends Player implements Sampler
public long getSampleRate() {
//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)
if(sampleRate <= 0l)
throw new RuntimeException("The sampleRate of the recording is not known.");
return sampleRate;
}
......
......@@ -17,8 +17,8 @@ import java.io.IOException;
*
* @author Oliver Adams <oliver.adams@gmail.com
*/
public class TranscriptPlayer extends MarkedPlayer {
public class TranscriptPlayer extends MarkedPlayer
{
/**
* Constructor
*
......@@ -38,7 +38,6 @@ public class TranscriptPlayer extends MarkedPlayer {
if(transcript != null) {
updateTranscriptStatus(getCurrentSample());
OnMarkerReachedListener onTranscriptMarkerReachedListener =
new OnMarkerReachedListener() {
public void onMarkerReached(MarkedPlayer p) {
......@@ -49,7 +48,6 @@ public class TranscriptPlayer extends MarkedPlayer {
});
}
};
setOnMarkerReachedListener(onTranscriptMarkerReachedListener);
}
......@@ -69,34 +67,35 @@ public class TranscriptPlayer extends MarkedPlayer {
}
// Update the UI such that the transcript reflects the current sample.
private void updateTranscriptUi(long sample) {
// Never use
/*private void updateTranscriptUi(long sample) {
Segment segment = transcript.getSegmentOfSample(sample);
updateTranscriptUi(segment);
}
}*/
// Update the UI such that the transcript reflects the current segment.
private void updateTranscriptUi(Segment segment) {
transcriptView = (TextView) activity.findViewById(R.id.transcriptView);
transcriptView2 = (TextView) activity.findViewById(R.id.transcriptView2);
TextView transcriptView = (TextView) activity.findViewById(R.id.transcriptView);
TextView transcriptView2 = (TextView) activity.findViewById(R.id.transcriptView2);
if (segment != null) {
transcriptView.setText(transcript.getTranscriptPair(segment).transcript);
transcriptView2.setText(transcript.getTranscriptPair(segment).translation);
} else {
transcriptView.setText("");
}
else
transcriptView.setText("");
}
@Override
public void seekToMsec(int msec) {
super.seekToMsec(msec);
//Find the transcript segment that corresponds to this point in time
long sample = msecToSample(msec);
//Update the UI to reflect the current transcript.
updateTranscriptStatus(sample);
// and update the UI to reflect the current transcript.
updateTranscriptStatus(msecToSample(msec));
}
//private static Segment segment;
private TempTranscript transcript;
private Activity activity;
/*
/**
......@@ -108,9 +107,4 @@ public class TranscriptPlayer extends MarkedPlayer {
}
}
*/
private static Segment segment;
private static TextView transcriptView, transcriptView2; // TODO: A placer en local dans updateTranscriptUi ???
private TempTranscript transcript;
private Activity activity;
}
......@@ -10,7 +10,6 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.R;
......@@ -25,13 +24,13 @@ import java.util.List;
class InterleavedSeekBar extends android.support.v7.widget.AppCompatSeekBar {
public InterleavedSeekBar(Context context) {
super(context);
super(context, null, R.attr.seekBarStyle);
//this.getThumb().setColorFilter(0xff4c516d, Mode.SRC_IN);
initDawables(context);
}
public InterleavedSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
super(context, attrs, R.attr.seekBarStyle);
initDawables(context);
}
......@@ -56,6 +55,7 @@ class InterleavedSeekBar extends android.support.v7.widget.AppCompatSeekBar {
}
this.setThumb(thumb);
this.setThumbOffset(0);
this.setProgressDrawable(progressColor);
}
......@@ -92,16 +92,15 @@ class InterleavedSeekBar extends android.support.v7.widget.AppCompatSeekBar {
* @param x The place to put the line, as a percentage of the seekbar.
*/
public void addLine(Float x) {
if (x < 0 || x > 100) {
if (x < 0 || x > 100)
throw new IllegalArgumentException(
"The line location must be a percentage of the seekbar " +
"between 0 and 100.");
}
lines.add(x);
}
//Not used
//public void setLines(List<Float> lines) {this.lines = lines;}
private List<Float> lines = new ArrayList<Float>();
private List<Float> lines = new ArrayList<>();
}
......@@ -26,7 +26,6 @@ import android.widget.VideoView;
import org.getalp.ligaikuma.lig_aikuma.Aikuma;
import org.getalp.ligaikuma.lig_aikuma.audio.InterleavedPlayer;
import org.getalp.ligaikuma.lig_aikuma.audio.MarkedPlayer;
import org.getalp.ligaikuma.lig_aikuma.audio.Player;
import org.getalp.ligaikuma.lig_aikuma.audio.SimplePlayer;
import org.getalp.ligaikuma.lig_aikuma.audio.TranscriptPlayer;
......@@ -227,8 +226,7 @@ public class ListenActivity extends AikumaActivity {
// If there is a transcript for the recording
// TranscriptPlayer is loaded
if(recording.getTranscript() != null) {
TranscriptPlayer player =
new TranscriptPlayer(recording, this);
TranscriptPlayer player = new TranscriptPlayer(recording, this);
// TODO: How to deal with transcripts needs to be decided
findViewById(R.id.topLine).setVisibility(View.VISIBLE);
......@@ -262,10 +260,11 @@ public class ListenActivity extends AikumaActivity {
fragment.setPlayer(player);
}
private void setPlayer(MarkedPlayer player) {
// never use
/*private void setPlayer(MarkedPlayer player) {
this.player = player;
fragment.setPlayer(player);
}
}*/
private void setPlayer(TranscriptPlayer player) {
this.player = player;
......@@ -433,11 +432,7 @@ public class ListenActivity extends AikumaActivity {
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (proximityDetector.isNear()) {
return false;
} else {
return super.dispatchTouchEvent(event);
}
return (!proximityDetector.isNear() && super.dispatchTouchEvent(event));
}
/**
......@@ -450,7 +445,7 @@ public class ListenActivity extends AikumaActivity {
// viewCount.setText("# views: " + numViews);
// }
private boolean phoneRespeaking = false;
//private boolean phoneRespeaking = false;
private Player player;
private ListenFragment fragment;
private VideoView videoView;
......
......@@ -68,9 +68,8 @@ public class ListenFragment extends Fragment implements OnClickListener {
int originalProgress;
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
if (fromUser) {
if (fromUser)
seekBar.setProgress(originalProgress);
}
}
public void onStopTrackingTouch(SeekBar _seekBar) {};
public void onStartTrackingTouch(SeekBar _seekBar) {
......@@ -149,9 +148,8 @@ public class ListenFragment extends Fragment implements OnClickListener {
if (v == playPauseButton) {
if (player.isPlaying()) {
pause();
if(otherPlayer != null) {
otherPlayer.setEnabled(true);
}
if(otherPlayer != null)
otherPlayer.setEnabled(true);
} else {
if(otherPlayer != null)
......@@ -192,7 +190,8 @@ public class ListenFragment extends Fragment implements OnClickListener {
seekBarThread = new Thread(new Runnable() {
public void run() {
int currentPosition;
while (true) {
while(true)
{
currentPosition = player.getCurrentMsec();
seekBar.setProgress(
(int)(((float)currentPosition/(float)
......@@ -204,9 +203,8 @@ public class ListenFragment extends Fragment implements OnClickListener {
seekBar.setProgress(
(int)(((float)currentPosition/(float)
player.getDurationMsec())*100));
if(otherPlayer != null) {
if(otherPlayer != null)
otherPlayer.setProgress(currentPosition);
}
return;
}
}
......@@ -223,8 +221,7 @@ public class ListenFragment extends Fragment implements OnClickListener {
*/
public void setProgress(int msec) {
player.seekToMsec(msec);
seekBar.setProgress(
(int)(((float)msec / (float)player.getDurationMsec())*100));
seekBar.setProgress((int)(((float)msec / (float)player.getDurationMsec())*100));
}
/**
......@@ -271,14 +268,11 @@ public class ListenFragment extends Fragment implements OnClickListener {
public void setPlayer(InterleavedPlayer interleavedPlayer) {
this.player = interleavedPlayer;
Segments segments = new Segments(interleavedPlayer.getRecording());
Iterator<Segment> originalSegmentIterator =
segments.getOriginalSegmentIterator();
Iterator<Segment> originalSegmentIterator = segments.getOriginalSegmentIterator();
while (originalSegmentIterator.hasNext()) {
Segment segment = originalSegmentIterator.next();
float fraction =
player.sampleToMsec(segment.getEndSample()) /
(float) player.getDurationMsec();
float fraction = player.sampleToMsec(segment.getEndSample())
/ (float) player.getDurationMsec();
seekBar.addLine(fraction*100);
}
player.setOnCompletionListener(onCompletionListener);
......@@ -309,11 +303,8 @@ public class ListenFragment extends Fragment implements OnClickListener {
*/
private void setEnabled(boolean isEnabled) {
playPauseButton.setEnabled(isEnabled);
if(isEnabled) {
playPauseButton.setImageResource(R.drawable.play_g);
} else {
playPauseButton.setImageResource(R.drawable.play_grey);
}
if(isEnabled) playPauseButton.setImageResource(R.drawable.play_g);
else playPauseButton.setImageResource(R.drawable.play_grey);
}
public Player getPlayer() {
......
......@@ -67,65 +67,47 @@ public class MenuBehaviour {
* @return Always true.
*/
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
switch (item.getItemId())
{
case android.R.id.home:
goToMainActivity();
return true;
case R.id.search:
if(AikumaSettings.getCurrentUserToken() == null) {
Aikuma.showAlertDialog(activity, "You need to be online using your account");
return true;
}
intent = new Intent(activity, CloudSearchActivity.class);
activity.startActivity(intent);
if(AikumaSettings.getCurrentUserToken() == null)
Aikuma.showAlertDialog(activity, "You need to be online using your account");
else activity.startActivity(new Intent(activity, CloudSearchActivity.class));
return true;
case R.id.record:
if(AikumaSettings.getCurrentUserId() == null) {
Aikuma.showAlertDialog(activity, "You need to select your account");
return true;
}
intent = new Intent(activity, RecordActivity.class);
activity.startActivity(intent);
if(AikumaSettings.getCurrentUserId() == null)
Aikuma.showAlertDialog(activity, "You need to select your account");
else activity.startActivity(new Intent(activity, RecordActivity.class));
return true;
case R.id.speakers:
if(AikumaSettings.getCurrentUserId() == null) {
Aikuma.showAlertDialog(activity, "You need to select your account");
return true;
}
intent = new Intent(activity, MainSpeakersActivity.class);
activity.startActivity(intent);
if(AikumaSettings.getCurrentUserId() == null)
Aikuma.showAlertDialog(activity, "You need to select your account");
else activity.startActivity(new Intent(activity, MainSpeakersActivity.class));
return true;
case R.id.help:
intent = new Intent(activity, HowtoActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, HowtoActivity.class));
return true;
case R.id.language_setting_menu:
intent = new Intent(activity, DefaultLanguagesActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, DefaultLanguagesActivity.class));
return true;
case R.id.settings:
intent = new Intent(activity, SettingsActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, SettingsActivity.class));
return true;
case R.id.about:
intent = new Intent(activity, AboutActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, AboutActivity.class));
return true;
case R.id.start_http_server:
intent = new Intent(activity, HttpServerActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, HttpServerActivity.class));
return true;
case R.id.audio_import_menu:
((MainActivity)activity).audioImport(null);
return true;
case R.id.gplus_signin_menu:
if(signInState) {
((MainActivity)activity).clearAccountToken();
} else {
((MainActivity)activity).getAccountToken();
}
if(signInState) ((MainActivity)activity).clearAccountToken();
else ((MainActivity)activity).getAccountToken();
return true;
case R.id.cloud_sync_menu:
((MainActivity)activity).syncRefresh(true);
......@@ -133,12 +115,10 @@ public class MenuBehaviour {
//activity.startActivity(intent);
return true;
case R.id.cloud_sync_setting_menu:
intent = new Intent(activity, CloudSettingsActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, CloudSettingsActivity.class));
return true;
case R.id.ftp_sync_setting_menu:
intent = new Intent(activity, SyncSettingsActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, SyncSettingsActivity.class));
return true;
case R.id.indexing_menu:
try {
......@@ -148,8 +128,7 @@ public class MenuBehaviour {
}
return true;
case R.id.debugInfo:
intent = new Intent(activity, DebugInfo.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, DebugInfo.class));
return true;
default:
return true;
......@@ -166,31 +145,26 @@ public class MenuBehaviour {
* @return Always true.
*/
public boolean safeOnOptionsItemSelected(MenuItem item,
String safeActivityTransitionMessage) {
Intent intent;
switch (item.getItemId()) {
String safeActivityTransitionMessage)
{
switch (item.getItemId())
{
case android.R.id.home:
safeGoToMainActivity(safeActivityTransitionMessage);
return true;
case R.id.record:
if(AikumaSettings.getCurrentUserId() == null) {
Aikuma.showAlertDialog(activity, "You need to select an account to make a recording");
return true;
}
intent = new Intent(activity, RecordActivity.class);
activity.startActivity(intent);
if(AikumaSettings.getCurrentUserId() == null)
Aikuma.showAlertDialog(activity, "You need to select an account to make a recording");
else activity.startActivity(new Intent(activity, RecordActivity.class));
return true;
case R.id.help:
intent = new Intent(activity, HowtoActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, HowtoActivity.class));
return true;
case R.id.settings:
intent = new Intent(activity, SettingsActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, SettingsActivity.class));
return true;
case R.id.about:
intent = new Intent(activity, AboutActivity.class);
activity.startActivity(intent);
activity.startActivity(new Intent(activity, AboutActivity.class));
return true;
default:
return true;
......@@ -212,24 +186,17 @@ public class MenuBehaviour {
*/
public void setSignInState(boolean state) {
this.signInState = state;
if(state) {
//TODO: get emailAccount from AikumaSettings
String signOutString = "Sign-out: "; // + activity.emailAccount;
findItem(R.id.gplus_signin_menu).setTitle(signOutString);
} else {
String signInString =
activity.getResources().getString(R.string.gplus_signin_menu_label);
findItem(R.id.gplus_signin_menu).setTitle(signInString);
}
if(state)
findItem(R.id.gplus_signin_menu).setTitle("Sign-out: "/*+ activity.emailAccount*/);
else
findItem(R.id.gplus_signin_menu).setTitle(activity.getResources().getString(R.string.gplus_signin_menu_label));
}
/**
* Opens the howto from lp20.org in a browser.
* Opens the howto from rickroll in a browser, you can change the uri to use it.
*/
private void openHelpInBrowser() {
Uri uri = Uri.parse("http://lp20.org/aikuma/howto.html");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent);
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=dQw4w9WgXcQ")));
}
/**
......@@ -249,10 +216,10 @@ public class MenuBehaviour {
* @param safeActivityTransitionMessage The string to display in a warning message.
*/
public void safeGoToMainActivity(String safeActivityTransitionMessage) {
String message = DEFAULT_MESSAGE;
if (safeActivityTransitionMessage != null) {
message = safeActivityTransitionMessage;
}
String message = (safeActivityTransitionMessage == null)?
DEFAULT_MESSAGE:
safeActivityTransitionMessage;
new AlertDialog.Builder(activity)
.setMessage(message)
.setPositiveButton("Discard",
......@@ -260,8 +227,7 @@ public class MenuBehaviour {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent intent =
new Intent(activity, MainActivity.class);
Intent intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);
}
......@@ -281,9 +247,8 @@ public class MenuBehaviour {
public void safeGoBack(String safeActivityTransitionMessage,
final BackButtonBehaviour safeBehaviour) {
String message = DEFAULT_MESSAGE;
if (safeActivityTransitionMessage != null) {
if(safeActivityTransitionMessage != null)
message = safeActivityTransitionMessage;
}
new AlertDialog.Builder(activity)
.setMessage(message)
.setPositiveButton("Discard",
......@@ -306,11 +271,11 @@ public class MenuBehaviour {
* @author Sangyeop Lee
*
*/
public static interface BackButtonBehaviour {
public interface BackButtonBehaviour {
/**
* The function called for safe back-button action
*/
public void onSafeBackButton();
void onSafeBackButton();
}
private Activity activity;
......
......@@ -42,7 +42,7 @@ public class PhoneRespeakActivity extends AikumaActivity {
//are not willing to discard new data on an activity transition via the
//menu.
safeActivityTransition = true;
fragment = (PhoneRespeakFragment)
PhoneRespeakFragment fragment = (PhoneRespeakFragment)
getFragmentManager().findFragmentById(R.id.PhoneRespeakFragment);
setUpPhoneRespeaker();
fragment.setPhoneRespeaker(respeaker);
......@@ -58,8 +58,8 @@ public class PhoneRespeakActivity extends AikumaActivity {
private void setUpPhoneRespeaker() {
Intent intent = getIntent();
sourceId = (String) intent.getExtras().get("sourceId");
ownerId = (String) intent.getExtras().get("ownerId");
versionName = (String) intent.getExtras().get("versionName");
String ownerId = (String) intent.getExtras().get("ownerId");
String