|
3 | 3 | import android.content.Context;
|
4 | 4 | import android.content.SharedPreferences;
|
5 | 5 | import android.media.MediaRecorder;
|
| 6 | +import android.os.Handler; |
| 7 | +import android.os.Looper; |
6 | 8 | import android.util.Log;
|
7 | 9 | import android.widget.Toast;
|
8 | 10 |
|
@@ -55,33 +57,33 @@ public void startRecoding() {
|
55 | 57 | recorder.start();
|
56 | 58 |
|
57 | 59 | if (preferences.getBoolean("start_toast", false)) {
|
58 |
| - Toast.makeText(context, "Recording started", Toast.LENGTH_SHORT).show(); |
| 60 | + new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, "Recording started!", Toast.LENGTH_SHORT).show()); |
59 | 61 | }
|
60 |
| - |
61 | 62 | } catch (Exception e) {
|
62 | 63 | Log.e(TAG, "startVoiceRecoding: ", e);
|
63 |
| - Toast.makeText(context, "Recording start failed! " + e.getMessage(), Toast.LENGTH_SHORT).show(); |
| 64 | + recorder = null; |
| 65 | + new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, "Recording start failed!", Toast.LENGTH_SHORT).show()); |
64 | 66 | }
|
65 | 67 | }
|
66 | 68 | //--------------------------------------------------------------------------------------------------
|
67 | 69 |
|
68 | 70 | public void stopVoiceRecoding() {
|
69 | 71 |
|
70 | 72 | try {
|
71 |
| - recorder.release(); |
72 | 73 | recorder.stop();
|
73 | 74 | recorder.reset();
|
| 75 | + recorder.release(); |
74 | 76 | recorder = null;
|
75 | 77 |
|
76 | 78 | if (preferences.getBoolean("saved_toast", false)) {
|
77 |
| - Toast.makeText(context, "Recording saved successfully!", Toast.LENGTH_SHORT).show(); |
| 79 | + new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, "Recording saved successfully!", Toast.LENGTH_SHORT).show()); |
78 | 80 | }
|
79 | 81 | } catch (Exception e) {
|
80 | 82 | Log.e(TAG, "stopVoiceRecoding:", e);
|
81 | 83 | recorder = null;
|
82 | 84 |
|
83 | 85 | if (preferences.getBoolean("saved_toast", false)) {
|
84 |
| - Toast.makeText(context, "Recording saved!", Toast.LENGTH_SHORT).show(); |
| 86 | + new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, "Recording saved!", Toast.LENGTH_SHORT).show()); |
85 | 87 | }
|
86 | 88 | }
|
87 | 89 | }
|
|
0 commit comments