Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for unlimited audio recording by pressing headset button twice #42

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Everyone can contribute to the development of the app, and that's great!. Since we'll be using [gitflow](https://datasift.github.io/gitflow/IntroducingGitFlow.html), it's recommended to have feature branches that will eventually be merged back to the `develop` via pull requests, and later `develop` will be merged back to master when we're ready for a new release.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ OSMTracker for Android™ official source code repository is [https://github.com

For more information about the project, documentation and bug reports please visit https://github.com/labexp/osmtracker-android/wiki

If you are interested in contribute to this project, please visit https://github.com/labexp/osmtracker-android/blob/master/CONTRIBUTING.md to know the way you could do it.

To help translate OSMTracker, please visit https://www.transifex.com/projects/p/osmtracker-android/
27 changes: 26 additions & 1 deletion app/src/main/java/net/osmtracker/activity/WaypointList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.db.WaypointListAdapter;

import android.app.ListActivity;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.net.Uri;
import android.view.View;
import android.widget.CursorAdapter;
import android.widget.ListView;

import java.io.File;

/**
* Activity that lists the previous waypoints tracked by the user.
Expand All @@ -26,6 +31,26 @@ protected void onResume() {

super.onResume();
}

@Override
protected void onListItemClick(ListView lv, View v, int pos, long id) {


WaypointListAdapter wpa = (WaypointListAdapter)getListAdapter();

if (wpa != null) {
String audioFile = getIntent().getExtras().getString(TrackContentProvider.Schema.COL_LINK);
if (audioFile!=null && audioFile.endsWith(".3gpp")) {
Uri u = Uri.fromFile(new File(audioFile));
MediaPlayer player = MediaPlayer.create(this, u);
if (player != null) {
player.setLooping(false);
player.start();
}
}
}

}

@Override
protected void onPause() {
Expand Down
53 changes: 39 additions & 14 deletions app/src/main/java/net/osmtracker/view/VoiceRecDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider.Schema;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -88,6 +89,8 @@ public class VoiceRecDialog extends ProgressDialog implements OnInfoListener{
* This is needed to check if a key was pressed before the dialog was shown
*/
private long dialogStartTime = 0;

private static final int UNLIMITED_REC_LENGTH = 600; // 10 minutes max

public VoiceRecDialog(Context context, long trackId) {
super(context);
Expand All @@ -98,17 +101,18 @@ public VoiceRecDialog(Context context, long trackId) {
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

this.setTitle(context.getResources().getString(R.string.tracklogger_voicerec_title));
this.setButton(context.getResources().getString(R.string.tracklogger_voicerec_stop), new DialogInterface.OnClickListener() {

this.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.tracklogger_voicerec_stop), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mediaRecorder.stop();
// redundant with the safeClose that is triggered when the dialog closes
// mediaRecorder.stop();
VoiceRecDialog.this.dismiss();
}
});
}


/**
* @link android.app.Dialog#onStart()
*/
Expand All @@ -119,18 +123,30 @@ public void onStart() {

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

if (!isRecording)
recordingDuration = Integer.parseInt(
preferences.getString(OSMTracker.Preferences.KEY_VOICEREC_DURATION,
OSMTracker.Preferences.VAL_VOICEREC_DURATION));
if (!isRecording) {

String recLen = preferences.getString(OSMTracker.Preferences.KEY_VOICEREC_DURATION, OSMTracker.Preferences.VAL_VOICEREC_DURATION);

if (recLen.equals(context.getResources().getString(R.string.unlimited_time_to_recording_option))){

this.setMessage(null);
recordingDuration = UNLIMITED_REC_LENGTH;

}
else{

recordingDuration = Integer.parseInt(recLen);

this.setMessage(context.getResources().getString(R.string.tracklogger_voicerec_text)
.replace("{0}", recLen));
}

}
else {

if (recordingDuration <= 0)
recordingDuration = Integer.parseInt(OSMTracker.Preferences.VAL_VOICEREC_DURATION);
}

this.setMessage(
context.getResources().getString(R.string.tracklogger_voicerec_text)
.replace("{0}", String.valueOf(recordingDuration)));

// we need to avoid screen orientation change during recording because this causes some strange behavior
try{
Expand Down Expand Up @@ -254,7 +270,9 @@ public void onInfo(MediaRecorder mr, int what, int extra) {
protected void onStop() {
Log.d(TAG, "onStop() called");

safeClose(mediaRecorder, false);
// why was it set to false ? We definitely want the audio recorder to stop when the dialog disappears !
safeClose(mediaRecorder, true);
// This is weird to stop the "beeps" in such a hard way. TODO: let them finish and release their resources afterwards
safeClose(mediaPlayerStart);
safeClose(mediaPlayerStop);

Expand Down Expand Up @@ -354,6 +372,13 @@ private void safeClose(MediaRecorder mr, boolean stopIt) {
try {
if (stopIt) {
mr.stop();
if (mediaPlayerStop != null) {
// short "beep" when we stop to record
mediaPlayerStop.start();
// gives it a small amount of time for the beeps to run
// TODO: wait for the beep to finish, or for a timeout
Thread.sleep(200);
}
}
} catch (Exception e) {
Log.w(TAG, "Failed to stop media recorder",e);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,6 @@
<string name="github_repository_settings_valid_server">Github Repository valid</string>
<string name="github_repository_settings_invalid_server">Github Repository invalid</string>

<!-- Audio recording -->
<string name="unlimited_time_to_recording_option">Unlimited</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/values-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</string-array>

<string-array name="prefs_voicerec_durations">
<item>@string/unlimited_time_to_recording_option</item>
<item>2</item>
<item>3</item>
<item>4</item>
Expand Down