Merge branch 'audiorecorder-3.1.0'
This commit is contained in:
commit
a679f5ecb7
15 changed files with 176 additions and 28 deletions
|
|
@ -10,8 +10,8 @@ android {
|
|||
applicationId "com.github.axet.audiorecorder"
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23 // 24+ file:// unable to open
|
||||
versionCode 229
|
||||
versionName "3.0.63"
|
||||
versionCode 230
|
||||
versionName "3.1.0"
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@
|
|||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
|
||||
<application
|
||||
android:name=".app.MainApplication"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.axet.audiorecorder.activities;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
|
|
@ -11,6 +10,7 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaRecorder;
|
||||
import android.net.Uri;
|
||||
|
|
@ -20,6 +20,7 @@ import android.os.ParcelFileDescriptor;
|
|||
import android.os.Process;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
|
@ -119,9 +120,29 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
class RecordingReceiver extends BroadcastReceiver {
|
||||
boolean bluetooth = false;
|
||||
boolean pausedByBluetooth = false;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(PAUSE_BUTTON)) {
|
||||
String a = intent.getAction();
|
||||
if (a == null)
|
||||
return;
|
||||
if (a.equals(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED) && bluetooth) {
|
||||
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
|
||||
if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) {
|
||||
if (pausedByBluetooth) {
|
||||
pausedByBluetooth = false;
|
||||
startRecording();
|
||||
}
|
||||
} else if (AudioManager.SCO_AUDIO_STATE_DISCONNECTED == state) {
|
||||
if (thread != null) {
|
||||
pausedByBluetooth = true;
|
||||
stopRecording(getString(R.string.hold_by_bluetooth));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a.equals(PAUSE_BUTTON)) {
|
||||
pauseButton();
|
||||
}
|
||||
}
|
||||
|
|
@ -146,7 +167,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
break;
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
if (pausedByCall) {
|
||||
startRecording();
|
||||
if (isRecordingReady())
|
||||
startRecording();
|
||||
}
|
||||
wasRinging = false;
|
||||
pausedByCall = false;
|
||||
|
|
@ -283,6 +305,7 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
receiver = new RecordingReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(PAUSE_BUTTON);
|
||||
filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
|
||||
registerReceiver(receiver, filter);
|
||||
}
|
||||
|
||||
|
|
@ -339,10 +362,31 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
stopRecording(getString(R.string.recording_status_pause));
|
||||
} else {
|
||||
editCut();
|
||||
startRecording();
|
||||
if (isRecordingReady())
|
||||
startRecording();
|
||||
else
|
||||
Toast.makeText(this, R.string.hold_by_bluetooth, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isRecordingReady() {
|
||||
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (shared.getString(MainApplication.PREFERENCE_BLUETOOTH, MainApplication.SOURCE_MIC).equals(MainApplication.SOURCE_BLUETOOTH)) {
|
||||
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
if (am.isBluetoothScoAvailableOffCall()) {
|
||||
receiver.bluetooth = true;
|
||||
am.stopBluetoothSco(); // stop previous connection (in case of disconnect) seems like bluetooth stack counts
|
||||
am.startBluetoothSco();
|
||||
if (!am.isBluetoothScoOn()) {
|
||||
receiver.pausedByBluetooth = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -354,7 +398,10 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
if (start) {
|
||||
start = false;
|
||||
if (Storage.permitted(this, PERMISSIONS, RESULT_START)) { // audio perm
|
||||
startRecording();
|
||||
if (isRecordingReady())
|
||||
startRecording();
|
||||
else
|
||||
stopRecording(getString(R.string.hold_by_bluetooth));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -414,6 +461,11 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
pitch.stop();
|
||||
sound.unsilent();
|
||||
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
if (receiver.bluetooth) {
|
||||
am.stopBluetoothSco();
|
||||
receiver.bluetooth = false;
|
||||
}
|
||||
}
|
||||
|
||||
void edit(boolean show, boolean animate) {
|
||||
|
|
@ -863,7 +915,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
switch (requestCode) {
|
||||
case RESULT_START:
|
||||
if (Storage.permitted(this, permissions)) {
|
||||
startRecording();
|
||||
if (isRecordingReady())
|
||||
startRecording();
|
||||
} else {
|
||||
Toast.makeText(this, R.string.not_permitted, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
|
|
@ -880,13 +933,20 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
void encoding(final Runnable done) {
|
||||
final File in = storage.getTempRecording();
|
||||
|
||||
if (!in.exists() || in.length() == 0) {
|
||||
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(RecordingActivity.this);
|
||||
SharedPreferences.Editor edit = shared.edit();
|
||||
edit.putString(MainApplication.PREFERENCE_LAST, Storage.getDocumentName(targetUri));
|
||||
edit.commit();
|
||||
final Runnable last = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(RecordingActivity.this);
|
||||
SharedPreferences.Editor edit = shared.edit();
|
||||
edit.putString(MainApplication.PREFERENCE_LAST, Storage.getDocumentName(targetUri));
|
||||
edit.commit();
|
||||
|
||||
done.run();
|
||||
done.run();
|
||||
}
|
||||
};
|
||||
|
||||
if (!in.exists() || in.length() == 0) {
|
||||
last.run();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -915,12 +975,7 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
public void run() { // success
|
||||
Storage.delete(in); // delete raw recording
|
||||
|
||||
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(RecordingActivity.this);
|
||||
SharedPreferences.Editor edit = shared.edit();
|
||||
edit.putString(MainApplication.PREFERENCE_LAST, Storage.getDocumentName(targetUri));
|
||||
edit.commit();
|
||||
|
||||
done.run();
|
||||
last.run();
|
||||
|
||||
d.cancel();
|
||||
}
|
||||
|
|
@ -935,16 +990,16 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
void Post(final Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Error(e);
|
||||
Error(toMessage(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Error(Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
public String toMessage(Throwable e) {
|
||||
String msg = e.getMessage();
|
||||
if (msg == null || msg.isEmpty()) {
|
||||
Throwable t;
|
||||
|
|
@ -957,9 +1012,16 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
while (t.getCause() != null)
|
||||
t = t.getCause();
|
||||
msg = t.getClass().getSimpleName();
|
||||
msg = t.getMessage();
|
||||
if (msg == null || msg.isEmpty())
|
||||
msg = t.getClass().getSimpleName();
|
||||
}
|
||||
Error(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void Error(Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
Error(toMessage(e));
|
||||
}
|
||||
|
||||
void Error(String msg) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
|
@ -258,6 +259,13 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere
|
|||
s.setPermissionsDialog(this, Storage.PERMISSIONS_RW, RESULT_STORAGE);
|
||||
if (Build.VERSION.SDK_INT >= 21)
|
||||
s.setStorageAccessFramework(this, RESULT_STORAGE);
|
||||
|
||||
AudioManager am = (AudioManager) context.getSystemService(AUDIO_SERVICE);
|
||||
Preference bluetooth = pm.findPreference(MainApplication.PREFERENCE_BLUETOOTH);
|
||||
if (!am.isBluetoothScoAvailableOffCall()) {
|
||||
bluetooth.setVisible(false);
|
||||
}
|
||||
bindPreferenceSummaryToValue(bluetooth);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ public class MainApplication extends com.github.axet.audiolibrary.app.MainApplic
|
|||
public static final String PREFERENCE_TARGET = "target";
|
||||
public static final String PREFERENCE_FLY = "fly";
|
||||
|
||||
public static final String PREFERENCE_BLUETOOTH = "bluetooth";
|
||||
|
||||
public static final String SOURCE_BLUETOOTH = "bluetooth";
|
||||
public static final String SOURCE_MIC = "mic";
|
||||
|
||||
public int getUserTheme() {
|
||||
return getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,4 +251,3 @@ public class RecordingService extends Service {
|
|||
Log.d(TAG, "onTaskRemoved");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<item>8 kHz (Telefon)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>Theme Weiß (Standard)</item>
|
||||
<item>Theme Dunkel</item>
|
||||
|
|
@ -58,4 +63,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Encoding on fly disable editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<item>8 kHz (téléphone)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>Thème Clair</item>
|
||||
<item>Thème Sombre</item>
|
||||
|
|
@ -58,4 +63,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Encoding on fly disable editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<item>8 kHz (telefono)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>Tema Bianco (prefedinito)</item>
|
||||
<item>Tema Scuro</item>
|
||||
|
|
@ -58,4 +63,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Encoding on fly disable editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<item>8 kHz (電話)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>テーマ ホワイト (デフォルト)</item>
|
||||
<item>テーマ ダーク</item>
|
||||
|
|
@ -58,4 +63,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Encoding on fly disable editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<item>8 kHz (ligação de tel.)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>Claro (padrão)</item>
|
||||
<item>Escuro</item>
|
||||
|
|
@ -58,4 +63,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Encoding on fly disable editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@
|
|||
<item>8 kHz (телефон)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Микрофон</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="channels_text">
|
||||
<item>Моно (по умолчанию)</item>
|
||||
<item>Стерео</item>
|
||||
|
|
@ -23,6 +28,7 @@
|
|||
|
||||
<string name="no_folder_app">Программа для просмотра папок не установлена</string>
|
||||
<string name="hold_by_call">пауза (звонок)</string>
|
||||
<string name="hold_by_bluetooth">пауза (bluetooth отключен)</string>
|
||||
<string name="recording_status_recording">запись</string>
|
||||
<string name="recording_status_encoding">кодировка</string>
|
||||
<string name="recording_status_pause">пауза</string>
|
||||
|
|
@ -58,4 +64,5 @@
|
|||
<string name="pref_recordings">Записи</string>
|
||||
<string name="pref_fly_title">Кодирование на лету</string>
|
||||
<string name="pref_fly_summary">Кодирование на лету отключает редактирование и восстановление в случае ошибок</string>
|
||||
<string name="pref_source_title">Источник</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<item>8 kHz (telefón)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>Theme Svetlá (predvolené)</item>
|
||||
<item>Theme Tmavá</item>
|
||||
|
|
@ -58,4 +63,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Encoding on fly disable editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,16 @@
|
|||
<item>8000</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_text">
|
||||
<item>Mic</item>
|
||||
<item>Bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="source_values" translatable="false">
|
||||
<item>mic</item>
|
||||
<item>bluetooth</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
<item>Theme White (default)</item>
|
||||
<item>Theme Dark</item>
|
||||
|
|
@ -90,4 +100,6 @@
|
|||
<string name="pref_recordings">Recordings</string>
|
||||
<string name="pref_fly_title">Encoding on Fly</string>
|
||||
<string name="pref_fly_summary">Enabling encoding on fly disables editing, and crash recovery</string>
|
||||
<string name="pref_source_title">Source</string>
|
||||
<string name="hold_by_bluetooth">pause (bluetooth disconnected)</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,16 @@
|
|||
android:summary="/sdcard/some/"
|
||||
android:title="@string/pref_storage_title" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="mic"
|
||||
android:entries="@array/source_text"
|
||||
android:entryValues="@array/source_values"
|
||||
android:key="bluetooth"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:summary=""
|
||||
android:title="@string/pref_source_title" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="16000"
|
||||
android:entries="@array/sample_rate_text"
|
||||
|
|
@ -46,15 +56,15 @@
|
|||
android:positiveButtonText="@null"
|
||||
android:summary="2015-12-31 22:11:34"
|
||||
android:title="@string/pref_nameformat_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_application">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="fly"
|
||||
android:summary="@string/pref_fly_summary"
|
||||
android:title="@string/pref_fly_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_application">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="call"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue