Fix audio note recording

pull/467/head
Alex Baker 8 years ago
parent 50416d0673
commit 5b3530306f

@ -4,6 +4,7 @@ import org.tasks.activities.CalendarSelectionDialog;
import org.tasks.dialogs.AccountSelectionDialog;
import org.tasks.dialogs.AddAttachmentDialog;
import org.tasks.dialogs.ColorPickerDialog;
import org.tasks.dialogs.RecordAudioDialog;
import org.tasks.dialogs.SortDialog;
import org.tasks.reminders.MissedCallDialog;
import org.tasks.reminders.NotificationDialog;
@ -28,4 +29,6 @@ public interface DialogFragmentComponent {
void inject(SortDialog sortDialog);
void inject(ColorPickerDialog colorPickerDialog);
void inject(RecordAudioDialog recordAudioDialog);
}

@ -4,6 +4,7 @@ import org.tasks.activities.CalendarSelectionDialog;
import org.tasks.dialogs.AccountSelectionDialog;
import org.tasks.dialogs.AddAttachmentDialog;
import org.tasks.dialogs.ColorPickerDialog;
import org.tasks.dialogs.RecordAudioDialog;
import org.tasks.dialogs.SortDialog;
import org.tasks.reminders.MissedCallDialog;
import org.tasks.reminders.NotificationDialog;
@ -28,4 +29,6 @@ public interface DialogFragmentComponent {
void inject(SortDialog sortDialog);
void inject(ColorPickerDialog colorPickerDialog);
void inject(RecordAudioDialog recordAudioDialog);
}

@ -5,6 +5,7 @@ import org.tasks.activities.SupportGoogleTaskListPicker;
import org.tasks.dialogs.AccountSelectionDialog;
import org.tasks.dialogs.AddAttachmentDialog;
import org.tasks.dialogs.ColorPickerDialog;
import org.tasks.dialogs.RecordAudioDialog;
import org.tasks.dialogs.SortDialog;
import org.tasks.reminders.MissedCallDialog;
import org.tasks.reminders.NotificationDialog;
@ -32,4 +33,6 @@ public interface DialogFragmentComponent {
void inject(SortDialog sortDialog);
void inject(ColorPickerDialog colorPickerDialog);
void inject(RecordAudioDialog recordAudioDialog);
}

@ -380,7 +380,7 @@
android:name="com.todoroo.astrid.files.AACRecordingActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/TasksDialog" />
android:theme="@style/TranslucentDialog" />
<activity
android:name=".files.MyFilePickerActivity"

@ -9,101 +9,65 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.widget.Chronometer;
import com.todoroo.astrid.voice.AACRecorder;
import com.todoroo.astrid.voice.AACRecorder.AACRecorderCallbacks;
import org.tasks.R;
import org.tasks.dialogs.RecordAudioDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.ActivityPermissionRequestor;
import org.tasks.preferences.PermissionRequestor;
import org.tasks.preferences.Preferences;
import java.util.concurrent.atomic.AtomicReference;
import org.tasks.themes.Theme;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class AACRecordingActivity extends InjectingAppCompatActivity implements AACRecorderCallbacks {
import static org.tasks.dialogs.RecordAudioDialog.newRecordAudioDialog;
public static final String RESULT_OUTFILE = "outfile"; //$NON-NLS-1$
public class AACRecordingActivity extends InjectingAppCompatActivity implements RecordAudioDialog.RecordAudioDialogCallback {
private static final String FRAG_TAG_RECORD_AUDIO = "frag_tag_record_audio";
private final AtomicReference<String> nameRef = new AtomicReference<>();
private AACRecorder recorder;
private String tempFile;
public static final String RESULT_OUTFILE = "outfile"; //$NON-NLS-1$
@Inject Preferences preferences;
@Inject ActivityPermissionRequestor permissionRequestor;
@Inject Theme theme;
@BindView(R.id.timer) Chronometer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theme.applyToContext(this);
if (permissionRequestor.requestMic()) {
startRecording();
}
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
private void startRecording() {
setContentView(R.layout.aac_record_activity);
ButterKnife.bind(this);
tempFile = preferences.getNewAudioAttachmentPath(nameRef);
recorder = new AACRecorder();
recorder.setListener(this);
recorder.startRecording(tempFile);
timer.start();
}
@OnClick(R.id.stop_recording)
void stopRecording() {
if (recorder != null) {
recorder.stopRecording();
timer.stop();
showDialog();
}
}
@OnClick(R.id.dismiss)
void dismiss() {
if (recorder != null) {
recorder.setListener(null);
recorder.stopRecording();
private void showDialog() {
FragmentManager supportFragmentManager = getSupportFragmentManager();
RecordAudioDialog dialog = (RecordAudioDialog) supportFragmentManager.findFragmentByTag(FRAG_TAG_RECORD_AUDIO);
if (dialog == null) {
dialog = newRecordAudioDialog();
dialog.show(supportFragmentManager, FRAG_TAG_RECORD_AUDIO);
}
finish();
}
@Override
protected void onPause() {
super.onPause();
stopRecording();
}
@Override
public void encodingFinished() {
Intent result = new Intent();
result.putExtra(RESULT_OUTFILE, tempFile);
setResult(RESULT_OK, result);
finish();
public void inject(ActivityComponent component) {
component.inject(this);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_MIC) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startRecording();
showDialog();
} else {
finish();
}
@ -111,4 +75,12 @@ public class AACRecordingActivity extends InjectingAppCompatActivity implements
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@Override
public void finished(String path) {
Intent result = new Intent();
result.putExtra(RESULT_OUTFILE, path);
setResult(RESULT_OK, result);
finish();
}
}

@ -0,0 +1,102 @@
package org.tasks.dialogs;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Chronometer;
import com.todoroo.astrid.voice.AACRecorder;
import org.tasks.R;
import org.tasks.injection.DialogFragmentComponent;
import org.tasks.injection.InjectingDialogFragment;
import org.tasks.preferences.Preferences;
import org.tasks.themes.Theme;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class RecordAudioDialog extends InjectingDialogFragment implements AACRecorder.AACRecorderCallbacks {
public static RecordAudioDialog newRecordAudioDialog() {
return new RecordAudioDialog();
}
public interface RecordAudioDialogCallback {
void finished(String path);
}
@Inject Preferences preferences;
@Inject DialogBuilder dialogBuilder;
@Inject Theme theme;
@BindView(R.id.timer) Chronometer timer;
private final AtomicReference<String> nameRef = new AtomicReference<>();
private AACRecorder recorder;
private String tempFile;
private RecordAudioDialogCallback callback;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater layoutInflater = theme.getLayoutInflater(getContext());
View view = layoutInflater.inflate(R.layout.aac_record_activity, null);
ButterKnife.bind(this, view);
startRecording();
return dialogBuilder.newDialog()
.setTitle(R.string.audio_recording_title)
.setView(view)
.create();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
callback = (RecordAudioDialogCallback) activity;
}
@Override
public void onPause() {
super.onPause();
stopRecording();
}
@OnClick(R.id.stop_recording)
void stopRecording() {
if (recorder != null) {
recorder.stopRecording();
timer.stop();
}
}
private void startRecording() {
tempFile = preferences.getNewAudioAttachmentPath(nameRef);
recorder = new AACRecorder();
recorder.setListener(this);
recorder.startRecording(tempFile);
timer.start();
}
@Override
protected void inject(DialogFragmentComponent component) {
component.inject(this);
}
@Override
public void encodingFinished() {
callback.finished(tempFile);
}
}

@ -5,72 +5,33 @@
** See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:id="@+id/reminder_root"
android:layout_width="match_parent"
android:id="@+id/reminder_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:orientation="vertical">
<Chronometer
android:id="@+id/timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:textColor="@color/text_primary"
android:textSize="24sp"
android:gravity="center" />
<TextView
android:id="@+id/stop_recording"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:orientation="vertical"
android:background="@drawable/reminder_dialog_background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dip"
android:layout_marginRight="5dip"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:layout_marginStart="10dp">
<TextView
android:id="@+id/reminder_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="1dip"
android:textSize="24sp"
android:textColor="@android:color/white"
android:layout_weight="1"
android:text="@string/audio_recording_title" />
<ImageView
android:id="@+id/dismiss"
android:layout_width="25dip"
android:layout_height="25dip"
android:scaleType="fitCenter"
android:tint="@android:color/white"
android:src="@drawable/ic_close_24dp" />
</LinearLayout>
<Chronometer
android:id="@+id/timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:textSize="24sp"
android:gravity="center" />
<TextView
android:id="@+id/stop_recording"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:background="@color/overdue"
android:textSize="24sp"
android:gravity="center"
android:text="@string/audio_stop_recording" />
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:background="@color/overdue"
android:textSize="24sp"
android:gravity="center"
android:text="@string/audio_stop_recording" />
</LinearLayout>
</LinearLayout>

Loading…
Cancel
Save