Merge branch 'audiorecorder-3.2.39'

This commit is contained in:
Alexey Kuznetsov 2018-12-09 15:33:48 +03:00
commit 0acd7afe73
20 changed files with 147 additions and 82 deletions

View file

@ -10,8 +10,8 @@ android {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 9
targetSdkVersion 26
versionCode 296
versionName "3.2.38"
versionCode 297
versionName "3.2.39"
}
signingConfigs {
release {
@ -57,5 +57,5 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.github.axet:android-audio-library:1.0.140' // implementation project(':android-audio-library')
implementation 'com.github.axet:android-audio-library:1.0.141' // implementation project(':android-audio-library')
}

View file

@ -28,6 +28,7 @@ import com.github.axet.androidlibrary.app.SuperUser;
import com.github.axet.androidlibrary.services.StorageProvider;
import com.github.axet.androidlibrary.widgets.AboutPreferenceCompat;
import com.github.axet.androidlibrary.widgets.AppCompatThemeActivity;
import com.github.axet.androidlibrary.widgets.ErrorDialog;
import com.github.axet.androidlibrary.widgets.SearchView;
import com.github.axet.audiolibrary.app.Recordings;
import com.github.axet.audiolibrary.app.Storage;
@ -206,7 +207,7 @@ public class MainActivity extends AppCompatThemeActivity {
try {
storage.migrateLocalStorage();
} catch (RuntimeException e) {
Error(e);
ErrorDialog.Error(this, e);
}
final String last = shared.getString(AudioApplication.PREFERENCE_LAST, "");
@ -261,7 +262,7 @@ public class MainActivity extends AppCompatThemeActivity {
try {
storage.migrateLocalStorage();
} catch (RuntimeException e) {
Error(e);
ErrorDialog.Error(MainActivity.this, e);
}
recordings.load(false, null);
checkPending();
@ -292,30 +293,9 @@ public class MainActivity extends AppCompatThemeActivity {
void updateHeader() {
Uri uri = storage.getStoragePath();
long free = storage.getFree(uri);
long free = Storage.getFree(this, uri);
long sec = Storage.average(this, free);
TextView text = (TextView) findViewById(R.id.space_left);
text.setText(AudioApplication.formatFree(this, free, sec));
}
public void Error(Throwable e) {
Error(SuperUser.toMessage(e));
}
public void Error(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Error");
builder.setMessage(msg);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
}

View file

@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioFormat;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@ -23,16 +24,17 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.github.axet.androidlibrary.animations.MarginBottomAnimation;
import com.github.axet.androidlibrary.app.SuperUser;
import com.github.axet.androidlibrary.sound.AudioTrack;
import com.github.axet.androidlibrary.widgets.AppCompatThemeActivity;
import com.github.axet.androidlibrary.widgets.ErrorDialog;
import com.github.axet.androidlibrary.widgets.OpenFileDialog;
import com.github.axet.androidlibrary.widgets.Toast;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
import com.github.axet.audiolibrary.encoders.Factory;
@ -84,7 +86,13 @@ public class RecordingActivity extends AppCompatThemeActivity {
View done;
PitchView pitch;
ScreenReceiver screen;
AudioApplication.RecordingStorage recording;
RecordingReceiver receiver;
AlertDialog muted;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
@ -92,15 +100,57 @@ 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.END)
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();
else
muted = ErrorDialog.Error(RecordingActivity.this, getString(R.string.mic_muted_error));
RecordingActivity.startActivity(RecordingActivity.this, true);
}
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);
}
};
run.run();
muted = null;
}
}
if (msg.what == AudioApplication.RecordingStorage.END) {
pitch.drawEnd();
if (!recording.interrupt.get()) {
stopRecording(getString(R.string.recording_status_pause));
String text = "Error reading from stream";
if (Build.VERSION.SDK_INT >= 28)
new ErrorDialog(RecordingActivity.this, getString(R.string.mic_muted_pie)).setTitle(text).show();
else
ErrorDialog.Error(RecordingActivity.this, getString(R.string.mic_muted_error));
RecordingActivity.startActivity(RecordingActivity.this, true);
}
}
if (msg.what == AudioApplication.RecordingStorage.ERROR)
Error((Exception) msg.obj);
}
};
ScreenReceiver screen;
AudioApplication.RecordingStorage recording;
public static void startActivity(Context context, boolean pause) {
Log.d(TAG, "startActivity");
@ -143,22 +193,6 @@ public class RecordingActivity extends AppCompatThemeActivity {
done.performClick();
return;
}
if (a.equals(AudioApplication.RecordingStorage.PINCH)) {
pitch.add(intent.getDoubleExtra("data", 0));
return;
}
if (a.equals(AudioApplication.RecordingStorage.UPDATESAMPLES)) {
updateSamples(intent.getLongExtra("data", 0));
return;
}
if (a.equals(AudioApplication.RecordingStorage.END)) {
pitch.drawEnd();
return;
}
if (a.equals(AudioApplication.RecordingStorage.ERROR)) {
Error((Throwable) intent.getSerializableExtra("data"));
return;
}
MediaButtonReceiver.handleIntent(msc, intent);
}
}
@ -192,16 +226,6 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
}
public void Post(final Throwable e) {
Log.e(TAG, "error", e);
handler.post(new Runnable() {
@Override
public void run() {
Error(toMessage(e));
}
});
}
public String toMessage(Throwable e) {
Throwable t;
if (encoder == null) {
@ -211,7 +235,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
if (t == null)
t = e;
}
return SuperUser.toMessage(t);
return ErrorDialog.toMessage(t);
}
public void Error(Throwable e) {
@ -220,9 +244,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
public void Error(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Error");
builder.setMessage(msg);
ErrorDialog builder = new ErrorDialog(this, msg);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
@ -289,9 +311,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
receiver.filter.addAction(ACTION_FINISH_RECORDING);
receiver.registerReceiver(this);
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
AudioApplication app = AudioApplication.from(this);
try {
if (app.recording == null)
app.recording = new AudioApplication.RecordingStorage(this, pitch.getPitchTime());
@ -301,7 +321,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
} catch (RuntimeException e) {
Log.d(TAG, "onCreate", e);
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Toast.Error(this, e);
finish();
return;
}
@ -310,6 +330,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
title.setText(Storage.getName(this, recording.targetUri));
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
if (shared.getBoolean(AudioApplication.PREFERENCE_CALL, false)) {
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(pscl, PhoneStateListener.LISTEN_CALL_STATE);
@ -337,7 +358,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
} catch (RuntimeException e) {
Error(e);
}
recording.storage.delete(recording.targetUri);
Storage.delete(RecordingActivity.this, recording.targetUri);
}
Storage.delete(recording.storage.getTempRecording());
finish();
@ -741,6 +762,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = shared.edit();
editor.remove(AudioApplication.PREFERENCE_TARGET);
editor.commit();
}
void startRecording() {
@ -862,7 +884,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}, new Runnable() {
@Override
public void run() { // or error
recording.storage.delete(fly.targetUri); // fly has fd, delete target manually
Storage.delete(RecordingActivity.this, fly.targetUri); // fly has fd, delete target manually
d.cancel();
Error(encoder.getException());
}

View file

@ -58,7 +58,7 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
public static final int RESULT_STORAGE = 1;
public static final int RESULT_CALL = 2;
Handler handler = new Handler();
Storage storage = new Storage(this);
public static String[] PREMS = new String[]{Manifest.permission.READ_PHONE_STATE};
@ -197,7 +197,7 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
}
}
if (key.equals(AudioApplication.PREFERENCE_STORAGE)) {
Storage.migrateLocalStorageDialog(this, handler, new Storage(this));
storage.migrateLocalStorageDialog();
}
if (key.equals(AudioApplication.PREFERENCE_RATE)) {
int sampleRate = Integer.parseInt(sharedPreferences.getString(AudioApplication.PREFERENCE_RATE, ""));

View file

@ -36,6 +36,7 @@ import com.github.axet.audiorecorder.services.RecordingService;
import java.io.File;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
@ -59,6 +60,8 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
public static final int UPDATESAMPLES = 2;
public static final int END = 3;
public static final int ERROR = 4;
public static final int MUTED = 5;
public static final int UNMUTED = 6;
public Context context;
public final ArrayList<Handler> handlers = new ArrayList<>();
@ -191,6 +194,9 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
boolean silenceDetected = false;
long silence = samplesTime; // last silence 0-frame
try {
long start = System.currentTimeMillis();
recorder.startRecording();
@ -242,6 +248,11 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
}
readSizeUpdate = dbSize / samplesUpdateStereo * samplesUpdateStereo;
for (int i = 0; i < readSizeUpdate; i += samplesUpdateStereo) {
for (int k = 0; k < samplesUpdateStereo; k++) {
int off = i + k;
if (dbBuf[off] != 0)
silence = samplesTime + off / Sound.getChannels(context);
}
double dB = RawSamples.getDB(dbBuf, i, samplesUpdateStereo);
Post(PINCH, dB);
}
@ -260,6 +271,16 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
Post(UPDATESAMPLES, m);
samplesTimeCount -= samplesTimeUpdate;
}
if (samplesTime - silence > 2 * sampleRate) { // 2 second of mic muted
if (!silenceDetected) {
silenceDetected = true;
Post(MUTED, null);
}
} else {
Post(UNMUTED, null);
silenceDetected = false;
}
}
}
} catch (final RuntimeException e) {
@ -335,6 +356,12 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
}
}
public boolean isForeground() {
synchronized (bufferSizeLock) {
return bufferSize == this.samplesUpdate * Sound.getChannels(context);
}
}
public void Post(Exception e) {
Post(ERROR, e);
}

View file

@ -23,6 +23,7 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
super(context);
}
@Override
public Uri getNewFile() {
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
String ext = shared.getString(AudioApplication.PREFERENCE_ENCODING, "");
@ -36,21 +37,19 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
Uri path = getStoragePath();
String s = path.getScheme();
if (Build.VERSION.SDK_INT >= 21 && s.startsWith(ContentResolver.SCHEME_CONTENT)) {
Uri n = getNextFile(path, format, ext);
return n;
} else if (s.startsWith(ContentResolver.SCHEME_FILE)) {
if (Build.VERSION.SDK_INT >= 21 && s.equals(ContentResolver.SCHEME_CONTENT)) {
return getNextFile(context, path, format, ext);
} else if (s.equals(ContentResolver.SCHEME_FILE)) {
File f = getFile(path);
if (!f.exists() && !f.mkdirs()) {
if (!f.exists() && !f.mkdirs())
throw new RuntimeException("Unable to create: " + path);
}
return Uri.fromFile(getNextFile(f, format, ext));
} else {
throw new UnknownUri();
}
}
public File getNewFile(File path, String ext) {
public File getNewFile(File f, String ext) {
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
String format = "%s";
@ -59,10 +58,8 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
format = getFormatted(format, new Date());
File f = path;
if (!f.exists() && !f.mkdirs()) {
throw new RuntimeException("Unable to create: " + path);
}
if (!f.exists() && !f.mkdirs())
throw new RuntimeException("Unable to create: " + f);
return getNextFile(f, format, ext);
}

View file

@ -168,7 +168,7 @@ public class RecordingService extends Service {
if (targetFile == null) {
title = getString(R.string.app_name);
Uri f = storage.getStoragePath();
long free = storage.getFree(f);
long free = Storage.getFree(this, f);
long sec = Storage.average(this, free);
text = AudioApplication.formatFree(this, free, sec);
builder = new RemoteNotificationCompat.Low(this, R.layout.notifictaion);

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
<string name="menu_search">Search</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -61,4 +61,7 @@
<string name="hold_by_bluetooth">παύση (αποσύνδεση bluetooth)</string>
<string name="menu_search">Αναζήτηση</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pausar (bluetooth desconectado)</string>
<string name="menu_search">Buscar</string>
<string name="save_as_wav">Guardar como WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
<string name="menu_search">Search</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">jeda (bluetooth terputus)</string>
<string name="menu_search">Cari</string>
<string name="save_as_wav">Simpan sebagai WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
<string name="menu_search">Search</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
<string name="menu_search">Search</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pauza (bluetooth rozłaczony)</string>
<string name="menu_search">Szukaj</string>
<string name="save_as_wav">Zapisz jako WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
<string name="menu_search">Search</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="pref_fly_summary">Кодирование на лету отключает редактирование и восстановление в случае ошибок</string>
<string name="menu_search">Поиск</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -69,4 +69,7 @@
<string name="hold_by_bluetooth">Pozastavené (odpojené bluetooth)</string>
<string name="menu_search">Hľadať</string>
<string name="save_as_wav">Uložiť vo formáte WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">暂停 (蓝牙未连接)</string>
<string name="menu_search">搜索</string>
<string name="save_as_wav">另存为WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>

View file

@ -67,4 +67,7 @@
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
<string name="menu_search">Search</string>
<string name="save_as_wav">Save as WAV</string>
<string name="auto_close">Auto close in (%1$d)</string>
<string name="mic_muted_error">Mic muted</string>
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
</resources>