From f27a5c3b2ebdcee491a6b0b5010d7772d630d11e Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 19 Dec 2018 11:59:11 +0300 Subject: [PATCH 1/2] add error check for mic paused --- .../activities/MainActivity.java | 6 +- .../activities/RecordingActivity.java | 56 +++++++++++-------- .../audiorecorder/app/AudioApplication.java | 27 ++++++--- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-id/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-zh-rCH/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 16 files changed, 69 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java index c150bc5..3a307d4 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java @@ -7,7 +7,6 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; import android.support.v4.view.MenuItemCompat; @@ -40,7 +39,6 @@ public class MainActivity extends AppCompatThemeActivity { public static final int RESULT_PERMS = 1; FloatingActionButton fab; - Handler handler = new Handler(); ListView list; Recordings recordings; @@ -211,7 +209,7 @@ public class MainActivity extends AppCompatThemeActivity { if (selected != -1) { recordings.select(selected); list.smoothScrollToPosition(selected); - handler.post(new Runnable() { + runOnUiThread(new Runnable() { @Override public void run() { list.setSelection(selected); @@ -267,7 +265,7 @@ public class MainActivity extends AppCompatThemeActivity { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - handler.post(new Runnable() { + runOnUiThread(new Runnable() { @Override public void run() { list.smoothScrollToPosition(recordings.getSelected()); diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java index f8036a4..7f583a7 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java @@ -100,6 +100,12 @@ public class RecordingActivity extends AppCompatThemeActivity { pitch.add((Double) msg.obj); if (msg.what == AudioApplication.RecordingStorage.UPDATESAMPLES) updateSamples((Long) msg.obj); + if (msg.what == AudioApplication.RecordingStorage.PAUSED) { + muted = ErrorDialog.Error(RecordingActivity.this, getString(R.string.mic_paused)); + RecordingActivity.startActivity(RecordingActivity.this); + AutoClose run = new AutoClose(muted); + run.run(); + } if (msg.what == AudioApplication.RecordingStorage.MUTED) { if (Build.VERSION.SDK_INT >= 28) muted = new ErrorDialog(RecordingActivity.this, getString(R.string.mic_muted_pie)).setTitle(getString(R.string.mic_muted_error)).show(); @@ -109,28 +115,7 @@ public class RecordingActivity extends AppCompatThemeActivity { } if (msg.what == AudioApplication.RecordingStorage.UNMUTED) { if (muted != null) { - Runnable run = new Runnable() { - int count = 5; - AlertDialog d = muted; - - @Override - public void run() { - if (count <= 0) { - d.dismiss(); - return; - } - Button b = d.getButton(DialogInterface.BUTTON_NEUTRAL); - b.setText(getString(R.string.auto_close, count)); - b.setVisibility(View.VISIBLE); - b.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - } - }); - count--; - handler.postDelayed(this, 1000); - } - }; + AutoClose run = new AutoClose(muted); run.run(); muted = null; } @@ -169,6 +154,33 @@ public class RecordingActivity extends AppCompatThemeActivity { context.startActivity(i); } + public class AutoClose implements Runnable { + int count = 5; + AlertDialog d; + + public AutoClose(AlertDialog muted) { + d = muted; + } + + @Override + public void run() { + if (count <= 0) { + d.dismiss(); + return; + } + Button b = d.getButton(DialogInterface.BUTTON_NEUTRAL); + b.setText(d.getContext().getString(R.string.auto_close, count)); + b.setVisibility(View.VISIBLE); + b.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + } + }); + count--; + handler.postDelayed(this, 1000); + } + } + class RecordingReceiver extends BluetoothReceiver { @Override public void onConnected() { diff --git a/app/src/main/java/com/github/axet/audiorecorder/app/AudioApplication.java b/app/src/main/java/com/github/axet/audiorecorder/app/AudioApplication.java index cfecb57..6d0ac85 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/app/AudioApplication.java +++ b/app/src/main/java/com/github/axet/audiorecorder/app/AudioApplication.java @@ -61,6 +61,7 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli public static final int ERROR = 4; public static final int MUTED = 5; public static final int UNMUTED = 6; + public static final int PAUSED = 7; public Context context; public final ArrayList handlers = new ArrayList<>(); @@ -196,8 +197,11 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli boolean silenceDetected = false; long silence = samplesTime; // last non silence frame + long start = System.currentTimeMillis(); // recording start time + long session = 0; // samples count from start of recording + try { - long start = System.currentTimeMillis(); + long last = System.currentTimeMillis(); recorder.startRecording(); int samplesTimeCount = 0; @@ -216,19 +220,22 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli int readSize = recorder.read(buffer, 0, buffer.length); if (readSize < 0) return; - long end = System.currentTimeMillis(); + long now = System.currentTimeMillis(); + long diff = (now - last) * sampleRate / 1000; + last = now; - long diff = (end - start) * sampleRate / 1000; - - start = end; - - int samples = readSize / Sound.getChannels(context); + int samples = readSize / Sound.getChannels(context); // mono samples (for booth channels) if (stableRefresh || diff >= samples) { stableRefresh = true; e.encode(buffer, 0, readSize); + try { + Thread.sleep(100); + }catch(InterruptedException e) { + } + short[] dbBuf; int dbSize; int readSizeUpdate; @@ -267,6 +274,7 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli Post(UPDATESAMPLES, samplesTime); samplesTimeCount -= samplesTimeUpdate; } + session += samples; if (samplesTime - silence > 2 * sampleRate) { // 2 second of mic muted if (!silenceDetected) { @@ -279,6 +287,11 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli Post(UNMUTED, null); } } + diff = (now - start) * sampleRate / 1000; // number of samples we expect by this moment + if (diff - session > 2 * sampleRate) { // 2 second of silence / paused by os + Post(PAUSED, null); + session = diff; // reset + } } } } catch (final RuntimeException e) { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 747ca4e..c95a176 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 9174425..b6b765c 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -64,4 +64,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ea95c66..bfa8398 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8556288..2c48180 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 9acc6cc..7dcc162 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e923b68..abbc863 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ecef4f5..1bcc3cc 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 1d38aae..682778b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 63c48dc..0c5418c 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index da00e03..35c7a68 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index a72fa6d..8d35509 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -72,4 +72,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values-zh-rCH/strings.xml b/app/src/main/res/values-zh-rCH/strings.xml index f9abea7..d4fbd76 100644 --- a/app/src/main/res/values-zh-rCH/strings.xml +++ b/app/src/main/res/values-zh-rCH/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4194e73..04737a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,4 +70,5 @@ Auto close in (%1$d) Mic muted Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version! + Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enough for selected settings From 6b18a7aa4de9d77e1d0243f6b3f08353e21e220b Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Wed, 19 Dec 2018 11:59:19 +0300 Subject: [PATCH 2/2] Bump version audiorecorder-3.2.46 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4a8ea9a..d8b0bb2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.github.axet.audiorecorder" minSdkVersion 9 targetSdkVersion 26 - versionCode 303 - versionName "3.2.45" + versionCode 304 + versionName "3.2.46" } signingConfigs { release {