Skip to content

Commit

Permalink
* Device vibrates when finished recording
Browse files Browse the repository at this point in the history
* Audio recording will be interrupted when conditions change while recording
* A alert box will be displayed in case the recording has to be interrupted - telling the user what went wrong
* Further adjusted the instructional screen
* Some more cleaning up under the hood
  • Loading branch information
rizz360 committed Oct 26, 2015
1 parent e704cee commit 7cf6602
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:allowBackup="true"
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/rizz/pdf/pdfsensing/ArcRecordTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.CountDownTimer;
Expand All @@ -11,6 +10,7 @@
import android.util.Log;

import com.rizz.pdf.pdfsensing.Handlers.AudioHandler;
import com.rizz.pdf.pdfsensing.Handlers.StatusHandler;

/**
* Created by Rizz on 02/10/2015.
Expand All @@ -31,6 +31,8 @@ public class ArcRecordTimer extends ArcTimer {
private float start = 0f;
private float sweep = 360;
private int secondsRemaining = (int)TIMER_DURATION_MS/1000;
private float radius = 30;
private boolean growing = false;

public ArcRecordTimer(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
Expand Down Expand Up @@ -77,11 +79,13 @@ public void onTick(long l) { //l = ms until finish
@Override
public void onFinish() {
stopCountDown();
StatusHandler.vibrate();
}
}.start();
}

private void stopCountDown() {
public void stopCountDown() {
if (!AudioHandler.isRecording()) return;
cdt.cancel();
AudioHandler.stopRecording();
Log.i(LOG_TAG, "Timer stopped");
Expand All @@ -98,8 +102,6 @@ public void setEnabled(boolean state) {
isEnabled = state;
}

private float radius = 30;
private boolean growing = false;
@Override
protected void onDraw(@NonNull Canvas canvas) {
//Draw the actual countdown arc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class AudioHandler {
private static ArcPlayTimer playButton = null;
private static MediaPlayer mediaPlayer = null;
private static MediaRecorder mediaRecorder = null;
private static boolean isRecording = false;

private AudioHandler() {
}
Expand Down Expand Up @@ -70,14 +71,23 @@ public static void startRecording() {
}

mediaRecorder.start();
isRecording = true;

}

public static boolean isRecording() {
return isRecording;
}


public static void stopRecording() {
if (!isRecording()) return;
mediaRecorder.stop();
mediaRecorder.release();
playButton.setEnabled(true);
FileHandler.writeMetaFile();
mediaRecorder = null;
isRecording = false;
}

public static void onPause() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.rizz.pdf.pdfsensing.Handlers;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.CountDownTimer;
import android.util.Log;
import android.os.Vibrator;
import android.view.OrientationEventListener;
import android.widget.ImageView;

Expand Down Expand Up @@ -98,7 +100,44 @@ private static void updateReadyState() {
}

public static boolean checkReadyState() {
return (isStatusReady(gpsView) && isStatusReady(orientationView) && isStatusReady(shakeView));
if (isStatusReady(gpsView) && isStatusReady(orientationView) && isStatusReady(shakeView))
return true;
else {
if (AudioHandler.isRecording()) displayAlert();
recordButton.stopCountDown();
return false;
}
}

public static void displayAlert() {
String message = "Es kam zu folgenden Problemen:\n";
if (!isStatusReady(gpsView)) message += "* Das GPS Signal ist zu schwach.\n";
if (!isStatusReady(orientationView))
message += "* Das Gerät ist nicht korrekt orientiert.\n";
if (!isStatusReady(shakeView)) message += "* Das Gerät wurde zu sehr bewegt.\n";
message += "Bitte achten Sie auf diese Fehlerquellen und versuchen Sie es erneut.";

Activity a = activity;
while (a.getParent() != null) {
a = a.getParent();
}
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(a);
alertBuilder.setMessage(message);
alertBuilder.setCancelable(true);
alertBuilder.setNeutralButton("Okay",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = alertBuilder.create();
alert.show();
}

//TODO this should not be in this class
public static void vibrate() {
Vibrator v = (Vibrator) baseContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(300);
}

private static boolean isStatusReady(ImageView view) {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
android:layout_width="299dp"
android:layout_height="107dp"
android:layout_gravity="center_horizontal|bottom"
android:enabled="true"
android:onClick="startButtonAction"
android:text="@string/intro_button"
android:textColor="@color/background_text"
android:textSize="50dp"
android:enabled="true" />
android:textSize="50sp" />

<TextView
android:id="@+id/instruction_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/instruction_title"
android:id="@+id/instruction_title"
android:layout_gravity="center_horizontal|top"
android:text="@string/instruction_title"
android:textSize="@dimen/question_text_size" />

<TextView
android:id="@+id/instruction_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/instruction_list"
android:id="@+id/instruction_list"
android:layout_gravity="center"
android:text="@string/instruction_list"
android:textSize="@dimen/question_text_size" />
</FrameLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="help_shake">Schütteln</string>
<string name="instruction_list">* Es regnet nicht \n* Sie sind draußen \n* Sie nehmen mit gestrecktem Arm auf \n* Sie sind ruhig während der Aufnhame \n</string>
<string name="instruction_list">* Es regnet nicht \n* Sie sind draußen \n* Sie nehmen mit gestrecktem Arm auf \n* Es wird nicht geredet während der Aufnhame \n</string>
<string name="instruction_title">Bitte fahren Sie nur unter folgenden Bedingungen fort:</string>
<string name="help_record">Aufnehmen</string>
<string name="help_play">Wiedergeben</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<string name="splashScreenButtonText">Get started!</string>
<string name="instruction_title">Please continue only if the following conditions are met:</string>
<string name="instruction_list">* It\'s not raining \n*You\'re outside \n* You\'re recording with your arm stretched\n* You\'re silent while recording \n</string>
<string name="instruction_list">* It\'s not raining \n*You\'re outside \n* You\'re recording with your arm stretched\n* No talking while recording \n</string>
<string name="help_shake">Shake</string>
<string name="help_record">Record</string>
<string name="help_play">Play</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<string name="splashScreenButtonText">Get started!</string>
<string name="instruction_title">Bitte fahren Sie nur unter folgenden Bedingungen fort:</string>
<string name="instruction_list">
* Es regnet nicht \n* Sie sind draußen \n* Sie nehmen mit gestrecktem Arm auf \n* Sie sind ruhig während der Aufnhame \n
* Es regnet nicht \n* Sie sind draußen \n* Sie nehmen mit gestrecktem Arm auf \n* Es wird nicht geredet während der Aufnhame \n
</string>
<string name="help_orientation">Orientation</string>
<string name="help_shake">Schütteln</string>
Expand Down

0 comments on commit 7cf6602

Please sign in to comment.