From 8c60348939dd92202596d19e5a2804f8a4c124ba Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 27 Jul 2023 13:57:29 +0200 Subject: [PATCH] voice messages for Android 10+ --- .../mastodon/activities/ComposeActivity.java | 6 ++++++ .../app/fedilab/android/mastodon/helper/Helper.java | 6 +++--- .../android/mastodon/helper/MediaHelper.java | 13 ++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index 5a30b66a..45904a8b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -304,6 +304,12 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana public boolean onCreateOptionsMenu(@NonNull Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_compose, menu); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + MenuItem micro = menu.findItem(R.id.action_microphone); + if (micro != null) { + micro.setVisible(false); + } + } return true; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index 6d331a37..bd9b1e40 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -1282,9 +1282,9 @@ public class Helper { MimeTypeMap mime = MimeTypeMap.getSingleton(); String extension = mime.getExtensionFromMimeType(cR.getType(uri)); - if (uri.toString().endsWith("fedilab_recorded_audio.m4a")) { - extension = ".m4a"; - attachment.mimeType = "audio/mp4"; + if (uri.toString().endsWith("fedilab_recorded_audio.ogg")) { + extension = "ogg"; + attachment.mimeType = "audio/ogg"; } SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_" + counter, Locale.getDefault()); counter++; diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/MediaHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/MediaHelper.java index 4acca2b5..b3ad328d 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/MediaHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/MediaHelper.java @@ -274,7 +274,8 @@ public class MediaHelper { * @param listener ActionRecord */ public static void recordAudio(Activity activity, ActionRecord listener) { - String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.m4a"; + //String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/fedilab_recorded_audio.ogg"; + String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.ogg"; AudioRecorder mAudioRecorder = AudioRecorder.getInstance(); File mAudioFile = new File(filePath); PopupRecordBinding binding = PopupRecordBinding.inflate(activity.getLayoutInflater()); @@ -306,16 +307,18 @@ public class MediaHelper { binding.counter.setText(String.format(Locale.getDefault(), "%s:%s", minutes, seconds)); }); } - }, 1000, 1000); + }, 0, 1000); binding.record.setOnClickListener(v -> { mAudioRecorder.stopRecord(); timer.cancel(); alert.dismiss(); listener.onRecorded(filePath); }); - mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC, - MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.AudioEncoder.AAC, - mAudioFile); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC, + MediaRecorder.OutputFormat.OGG, MediaRecorder.AudioEncoder.OPUS, 48000, 384000, + mAudioFile); + } mAudioRecorder.startRecord(); }