From 97b2502b8298c802824e959d5118e7903d909d21 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Sun, 31 Dec 2017 19:05:50 +0300 Subject: [PATCH 1/3] move onfly --- .../activities/RecordingActivity.java | 89 +++---------------- 1 file changed, 12 insertions(+), 77 deletions(-) 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 3b440e3..471b2ca 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 @@ -41,6 +41,7 @@ import com.github.axet.audiolibrary.encoders.Encoder; import com.github.axet.audiolibrary.encoders.EncoderInfo; import com.github.axet.audiolibrary.encoders.Factory; import com.github.axet.audiolibrary.encoders.FileEncoder; +import com.github.axet.audiolibrary.encoders.OnFlyEncoding; import com.github.axet.audiolibrary.widgets.PitchView; import com.github.axet.audiorecorder.R; import com.github.axet.audiorecorder.app.MainApplication; @@ -154,67 +155,6 @@ public class RecordingActivity extends AppCompatActivity { } } - public class OnFlyEncoding implements Encoder { - Uri targetUri; - Encoder e; - ParcelFileDescriptor fd; - FileDescriptor out; - String s; - - public OnFlyEncoding(Context context, Uri targetUri, EncoderInfo info) { - this.targetUri = targetUri; - - s = targetUri.getScheme(); - if (s.startsWith(ContentResolver.SCHEME_CONTENT)) { - Uri root = Storage.getDocumentTreeUri(targetUri); - Uri o = storage.createFile(root, Storage.getDocumentChildPath(targetUri)); - ContentResolver resolver = context.getContentResolver(); - try { - fd = resolver.openFileDescriptor(o, "rw"); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - out = fd.getFileDescriptor(); - } else if (s.startsWith(ContentResolver.SCHEME_FILE)) { - File f = Storage.getFile(targetUri); - try { - fd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - out = fd.getFileDescriptor(); - } else { - throw new RuntimeException("unkonwn uri"); - } - - final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context); - String ext = shared.getString(MainApplication.PREFERENCE_ENCODING, ""); - - e = Factory.getEncoder(context, ext, info, out); - } - - @Override - public void encode(short[] buf, int pos, int len) { - e.encode(buf, pos, len); - } - - @Override - public void close() { - if (e != null) { - e.close(); - e = null; - } - if (fd != null) { - try { - fd.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - fd = null; - } - } - } - @Override protected void onCreate(Bundle savedInstanceState) { setTheme(((MainApplication) getApplication()).getUserTheme()); @@ -716,7 +656,7 @@ public class RecordingActivity extends AppCompatActivity { final Encoder e; if (shared.getBoolean(MainApplication.PREFERENCE_FLY, false)) { - final OnFlyEncoding fly = new OnFlyEncoding(this, targetUri, getInfo()); + final OnFlyEncoding fly = new OnFlyEncoding(storage, targetUri, getInfo()); e = new Encoder() { @Override public void encode(short[] buf, int pos, int len) { @@ -856,18 +796,8 @@ public class RecordingActivity extends AppCompatActivity { } } } - if (e != null) { - e.close(); - } } catch (final RuntimeException e) { - handle.post(new Runnable() { - @Override - public void run() { - Log.e(TAG, Log.getStackTraceString(e)); - Toast.makeText(RecordingActivity.this, "AudioRecord error: " + e.getMessage(), Toast.LENGTH_SHORT).show(); - finish(); - } - }); + Post(e); } finally { // redraw view, we may add one last pich which is not been drawen because draw tread already interrupted. // to prevent resume recording jump - draw last added pitch here. @@ -878,11 +808,16 @@ public class RecordingActivity extends AppCompatActivity { } }); - if (e != null) - e.close(); - if (recorder != null) recorder.release(); + + if (e != null) { + try { + e.close(); + } catch (RuntimeException e) { + Post(e); + } + } } } }, "RecordingThread"); @@ -950,7 +885,7 @@ public class RecordingActivity extends AppCompatActivity { return; } - final OnFlyEncoding fly = new OnFlyEncoding(this, targetUri, getInfo()); + final OnFlyEncoding fly = new OnFlyEncoding(storage, targetUri, getInfo()); encoder = new FileEncoder(this, in, fly); From 13aff321c3dc024de4a9d801c4a05e3b7a30c8af Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Sun, 31 Dec 2017 20:55:09 +0300 Subject: [PATCH 2/3] set last rec --- app/build.gradle | 2 +- .../axet/audiorecorder/activities/RecordingActivity.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4f31aea..acc91d6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,5 +55,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.github.axet:android-audio-library:1.0.75' // compile project(':android-audio-library') + compile 'com.github.axet:android-audio-library:1.0.76' // compile project(':android-audio-library') } 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 471b2ca..d00ef41 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 @@ -881,7 +881,12 @@ public class RecordingActivity extends AppCompatActivity { final File in = storage.getTempRecording(); if (!in.exists() || in.length() == 0) { - finish(); + final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(RecordingActivity.this); + SharedPreferences.Editor edit = shared.edit(); + edit.putString(MainApplication.PREFERENCE_LAST, Storage.getDocumentName(targetUri)); + edit.commit(); + + done.run(); return; } From 5f60eb141967690dc8f9cbb02516f1275e2c2d27 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Sun, 31 Dec 2017 20:55:16 +0300 Subject: [PATCH 3/3] Bump version audiorecorder-3.0.62 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index acc91d6..a457ac4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.github.axet.audiorecorder" minSdkVersion 9 targetSdkVersion 23 // 24+ file:// unable to open - versionCode 227 - versionName "3.0.61" + versionCode 228 + versionName "3.0.62" } signingConfigs { release {