From 627688ae4c581422be6f5e3ed3be46b0256cff66 Mon Sep 17 00:00:00 2001 From: 12aw Date: Sun, 18 Feb 2024 14:58:53 +0100 Subject: [PATCH] blinking timer when pause voice recording --- git/release/output-metadata.json | 32 +++---- .../ui/ConversationFragment.java | 93 ++++++++++++++++--- 2 files changed, 98 insertions(+), 27 deletions(-) diff --git a/git/release/output-metadata.json b/git/release/output-metadata.json index 5bdd5f6e83..94196877f0 100644 --- a/git/release/output-metadata.json +++ b/git/release/output-metadata.json @@ -15,19 +15,6 @@ "versionName": "1.7.8.9", "outputFile": "monocles chat-1.7.8.9-git-universal-release.apk" }, - { - "type": "ONE_OF_MANY", - "filters": [ - { - "filterType": "ABI", - "value": "x86_64" - } - ], - "attributes": [], - "versionCode": 16003, - "versionName": "1.7.8.9", - "outputFile": "monocles chat-1.7.8.9-git-x86_64-release.apk" - }, { "type": "ONE_OF_MANY", "filters": [ @@ -46,13 +33,13 @@ "filters": [ { "filterType": "ABI", - "value": "arm64-v8a" + "value": "x86_64" } ], "attributes": [], - "versionCode": 16004, + "versionCode": 16003, "versionName": "1.7.8.9", - "outputFile": "monocles chat-1.7.8.9-git-arm64-v8a-release.apk" + "outputFile": "monocles chat-1.7.8.9-git-x86_64-release.apk" }, { "type": "ONE_OF_MANY", @@ -66,6 +53,19 @@ "versionCode": 16002, "versionName": "1.7.8.9", "outputFile": "monocles chat-1.7.8.9-git-x86-release.apk" + }, + { + "type": "ONE_OF_MANY", + "filters": [ + { + "filterType": "ABI", + "value": "arm64-v8a" + } + ], + "attributes": [], + "versionCode": 16004, + "versionName": "1.7.8.9", + "outputFile": "monocles chat-1.7.8.9-git-arm64-v8a-release.apk" } ], "elementType": "File" diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index a7ade33ddd..5022c2eb8f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -101,6 +101,8 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewConfiguration; import android.view.ViewGroup; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.view.WindowManager; @@ -298,20 +300,19 @@ public class ConversationFragment extends XmppFragment MessageAdapter.OnInlineImageLongClicked { //Voice recoder - private MediaRecorder mRecorder; private Integer oldOrientation; - private long mStartTime = 0; + private int mStartTime = 0; private boolean recording = false; - private CountDownLatch outputFileWrittenLatch = new CountDownLatch(1); + private final CountDownLatch outputFileWrittenLatch = new CountDownLatch(1); - private Handler mHandler = new Handler(); - private Runnable mTickExecutor = new Runnable() { + private final Handler mHandler = new Handler(); + private final Runnable mTickExecutor = new Runnable() { @Override public void run() { tick(); - mHandler.postDelayed(mTickExecutor, 100); + mHandler.postDelayed(mTickExecutor, 1000); } }; @@ -789,6 +790,17 @@ public class ConversationFragment extends XmppFragment } }; + private final OnClickListener mTimerClickListener = new OnClickListener() { + @Override + public void onClick(View v) { + if (recording && binding.recordingVoiceActivity.getVisibility() == VISIBLE) { + pauseRecording(); + } else if (!recording && binding.recordingVoiceActivity.getVisibility() == VISIBLE) { + resumeRecording(); + } + } + }; + private final OnClickListener mRecordVoiceButtonListener = v -> attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); @@ -858,7 +870,8 @@ public class ConversationFragment extends XmppFragment //binding.shareButton.setEnabled(false); //binding.shareButton.setText(R.string.please_wait); mHandler.removeCallbacks(mTickExecutor); - mHandler.postDelayed(() -> stopRecording(true), 500); + resumeRecording(); + mHandler.postDelayed(() -> stopRecording(true), 100); } }; @@ -1749,6 +1762,7 @@ public class ConversationFragment extends XmppFragment binding.recordVoiceButton.setOnClickListener(this.mRecordVoiceButtonListener); binding.emojiButton.setOnClickListener(this.memojiButtonListener); binding.keyboardButton.setOnClickListener(this.mkeyboardButtonListener); + binding.timer.setOnClickListener(this.mTimerClickListener); binding.takePictureButton.setOnClickListener(this.mtakePictureButtonListener); binding.messagesView.setOnScrollListener(mOnScrollListener); binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); @@ -3211,13 +3225,13 @@ public class ConversationFragment extends XmppFragment } setupOutputFile(); mRecorder.setOutputFile(mOutputFile.getAbsolutePath()); - + binding.timer.clearAnimation(); try { mRecorder.prepare(); mRecorder.start(); recording = true; - mStartTime = SystemClock.elapsedRealtime(); - mHandler.postDelayed(mTickExecutor, 100); + //mStartTime = SystemClock.elapsedRealtime(); + mHandler.postDelayed(mTickExecutor, 0); Log.d("Voice Recorder", "started recording to " + mOutputFile.getAbsolutePath()); return true; } catch (Exception e) { @@ -3236,7 +3250,44 @@ public class ConversationFragment extends XmppFragment } } + private void StartTimerAnimation() { + Animation anim = new AlphaAnimation(0.0f, 1.0f); + anim.setDuration(500); //You can manage the blinking time with this parameter + anim.setStartOffset(20); + anim.setRepeatMode(Animation.REVERSE); + anim.setRepeatCount(Animation.INFINITE); + binding.timer.startAnimation(anim); + } + + protected void pauseRecording() { + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + mRecorder.pause(); + mHandler.removeCallbacks(mTickExecutor); + recording = false; + StartTimerAnimation(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void resumeRecording() { + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + mRecorder.resume(); + mHandler.postDelayed(mTickExecutor, 0); + binding.timer.clearAnimation(); + } + recording = true; + Log.e("Voice Recorder", "resume recording"); + } catch (Exception e) { + e.printStackTrace(); + } + } + protected void stopRecording(final boolean saveFile) { + binding.timer.clearAnimation(); try { if (recording) { stopRecording(); @@ -3249,6 +3300,7 @@ public class ConversationFragment extends XmppFragment } finally { mRecorder = null; mStartTime = 0; + mHandler.removeCallbacks(mTickExecutor); } if (!saveFile && mOutputFile != null) { if (mOutputFile.delete()) { @@ -3367,7 +3419,26 @@ public class ConversationFragment extends XmppFragment } private void tick() { - this.binding.timer.setText(TimeFrameUtils.formatTimePassed(mStartTime, true)); + //this.binding.timer.setText(TimeFrameUtils.formatTimePassed(mStartTime, true)); + int minutes = (mStartTime % 3600) / 60; + int seconds = mStartTime % 60; + + // Format the seconds into hours, minutes, + // and seconds. + String time + = String + .format(Locale.getDefault(), + "%02d:%02d", minutes, + seconds); + + // Set the text view text. + this.binding.timer.setText(time); + + // If running is true, increment the + // seconds variable. + if (recording) { + mStartTime++; + } } @Override