Merge branch 'audiorecorder-3.2.42'

This commit is contained in:
Alexey Kuznetsov 2018-12-11 11:21:27 +03:00
commit 3c6c835903
6 changed files with 29 additions and 103 deletions

View file

@ -10,8 +10,8 @@ android {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 9
targetSdkVersion 26
versionCode 299
versionName "3.2.41"
versionCode 300
versionName "3.2.42"
}
signingConfigs {
release {

View file

@ -39,6 +39,8 @@ import com.github.axet.audiorecorder.services.RecordingService;
public class MainActivity extends AppCompatThemeActivity {
public final static String TAG = MainActivity.class.getSimpleName();
public static final int RESULT_PERMS = 1;
FloatingActionButton fab;
Handler handler = new Handler();
@ -170,12 +172,8 @@ public class MainActivity extends AppCompatThemeActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar base clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
@ -257,7 +255,7 @@ public class MainActivity extends AppCompatThemeActivity {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 1:
case RESULT_PERMS:
if (Storage.permitted(MainActivity.this, permissions)) {
try {
storage.migrateLocalStorage();

View file

@ -783,8 +783,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
RecordingService.startService(this, Storage.getName(this, recording.targetUri), true, encoder != null, duration);
} catch (RuntimeException e) {
Log.d(TAG, "unable to start", e);
Toast.makeText(RecordingActivity.this, "Unable to initialize AudioRecord", Toast.LENGTH_SHORT).show();
Toast.Error(RecordingActivity.this, e);
finish();
}
}

View file

@ -6,11 +6,9 @@ import android.annotation.TargetApi;
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;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.support.annotation.NonNull;
@ -22,13 +20,13 @@ import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.SwitchPreferenceCompat;
import android.view.MenuItem;
import android.widget.Toast;
import com.github.axet.androidlibrary.widgets.AppCompatSettingsThemeActivity;
import com.github.axet.androidlibrary.widgets.NameFormatPreferenceCompat;
import com.github.axet.androidlibrary.widgets.SeekBarPreference;
import com.github.axet.androidlibrary.widgets.SilencePreferenceCompat;
import com.github.axet.androidlibrary.widgets.StoragePathPreferenceCompat;
import com.github.axet.androidlibrary.widgets.Toast;
import com.github.axet.audiolibrary.app.Sound;
import com.github.axet.audiolibrary.encoders.Factory;
import com.github.axet.audiolibrary.widgets.RecordingVolumePreference;
@ -42,17 +40,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p/>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
public class SettingsActivity extends AppCompatSettingsThemeActivity implements PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback {
public static final int RESULT_STORAGE = 1;
@ -70,71 +57,6 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
return ll.toArray((T[]) Array.newInstance(c, ll.size()));
}
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
String key = preference.getKey();
if (preference instanceof SeekBarPreference) {
preference.setSummary(((SeekBarPreference) preference).format((Float) value));
} else if (preference instanceof NameFormatPreferenceCompat) {
preference.setSummary(((NameFormatPreferenceCompat) preference).getFormatted(stringValue));
} else if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
};
/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getAll().get(preference.getKey()));
}
@Override
public int getAppTheme() {
return AudioApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark);
@ -198,12 +120,12 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
}
}
if (key.equals(AudioApplication.PREFERENCE_STORAGE)) {
storage.migrateLocalStorageDialog();
storage.migrateLocalStorageDialog(this);
}
if (key.equals(AudioApplication.PREFERENCE_RATE)) {
int sampleRate = Integer.parseInt(sharedPreferences.getString(AudioApplication.PREFERENCE_RATE, ""));
if (sampleRate != Sound.getValidRecordRate(Sound.getInMode(this), sampleRate)) {
Toast.makeText(this, "Not supported Hz", Toast.LENGTH_SHORT).show();
Toast.Error(this, "Not supported Hz");
}
}
}

View file

@ -194,7 +194,7 @@ 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
long silence = samplesTime; // last non silence frame
try {
long start = System.currentTimeMillis();
@ -247,12 +247,10 @@ 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);
double a = RawSamples.getAmplitude(dbBuf, i, samplesUpdateStereo);
if (a != 0)
silence = samplesTime + (i + samplesUpdateStereo) / Sound.getChannels(context);
double dB = RawSamples.getDB(a);
Post(PINCH, dB);
}
int readSizeLen = dbSize - readSizeUpdate;
@ -266,8 +264,7 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
samplesTime += samples;
samplesTimeCount += samples;
if (samplesTimeCount > samplesTimeUpdate) {
final long m = samplesTime;
Post(UPDATESAMPLES, m);
Post(UPDATESAMPLES, samplesTime);
samplesTimeCount -= samplesTimeUpdate;
}
@ -278,8 +275,8 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
}
} else {
if (silenceDetected) {
Post(UNMUTED, null);
silenceDetected = false;
Post(UNMUTED, null);
}
}
}

View file

@ -11,11 +11,11 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.os.TransactionTooLargeException;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import com.github.axet.androidlibrary.app.NotificationManagerCompat;
import com.github.axet.androidlibrary.widgets.OptimizationPreferenceCompat;
@ -101,6 +101,14 @@ public class RecordingService extends Service {
context.stopService(new Intent(context, RecordingService.class));
}
public static void mergeRemoteViews(RemoteViews view, RemoteViews a) {
try {
view.getClass().getDeclaredMethod("mergeRemoteViews", RemoteViews.class).invoke(view, a);
} catch (Exception e) {
Log.e(TAG, "merge", e);
}
}
public RecordingService() {
}
@ -183,9 +191,11 @@ public class RecordingService extends Service {
if (duration != null) {
title += " (" + duration + ")";
if (notificationIntent != null && notificationIntent.hasExtra("duration") && notificationIntent.getBooleanExtra("recording", false)) { // speed up
notification.contentView.setTextViewText(R.id.title, title);
RemoteViews a = new RemoteViews(getPackageName(), notification.contentView.getLayoutId());
a.setTextViewText(R.id.title, title);
mergeRemoteViews(notification.contentView, a);
if (Build.VERSION.SDK_INT >= 16 && notification.bigContentView != null)
notification.bigContentView.setTextViewText(R.id.title, title);
mergeRemoteViews(notification.bigContentView, a);
return notification;
}
}