mirror of
https://codeberg.org/monocles/monocles_chat.git
synced 2025-01-27 07:24:13 +01:00
blinking timer when pause voice recording
This commit is contained in:
parent
20b546a2d3
commit
627688ae4c
2 changed files with 98 additions and 27 deletions
|
@ -15,19 +15,6 @@
|
||||||
"versionName": "1.7.8.9",
|
"versionName": "1.7.8.9",
|
||||||
"outputFile": "monocles chat-1.7.8.9-git-universal-release.apk"
|
"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",
|
"type": "ONE_OF_MANY",
|
||||||
"filters": [
|
"filters": [
|
||||||
|
@ -46,13 +33,13 @@
|
||||||
"filters": [
|
"filters": [
|
||||||
{
|
{
|
||||||
"filterType": "ABI",
|
"filterType": "ABI",
|
||||||
"value": "arm64-v8a"
|
"value": "x86_64"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"attributes": [],
|
"attributes": [],
|
||||||
"versionCode": 16004,
|
"versionCode": 16003,
|
||||||
"versionName": "1.7.8.9",
|
"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",
|
"type": "ONE_OF_MANY",
|
||||||
|
@ -66,6 +53,19 @@
|
||||||
"versionCode": 16002,
|
"versionCode": 16002,
|
||||||
"versionName": "1.7.8.9",
|
"versionName": "1.7.8.9",
|
||||||
"outputFile": "monocles chat-1.7.8.9-git-x86-release.apk"
|
"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"
|
"elementType": "File"
|
||||||
|
|
|
@ -101,6 +101,8 @@ import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewConfiguration;
|
import android.view.ViewConfiguration;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.AlphaAnimation;
|
||||||
|
import android.view.animation.Animation;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
@ -298,20 +300,19 @@ public class ConversationFragment extends XmppFragment
|
||||||
MessageAdapter.OnInlineImageLongClicked {
|
MessageAdapter.OnInlineImageLongClicked {
|
||||||
|
|
||||||
//Voice recoder
|
//Voice recoder
|
||||||
|
|
||||||
private MediaRecorder mRecorder;
|
private MediaRecorder mRecorder;
|
||||||
private Integer oldOrientation;
|
private Integer oldOrientation;
|
||||||
private long mStartTime = 0;
|
private int mStartTime = 0;
|
||||||
private boolean recording = false;
|
private boolean recording = false;
|
||||||
|
|
||||||
private CountDownLatch outputFileWrittenLatch = new CountDownLatch(1);
|
private final CountDownLatch outputFileWrittenLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
private Handler mHandler = new Handler();
|
private final Handler mHandler = new Handler();
|
||||||
private Runnable mTickExecutor = new Runnable() {
|
private final Runnable mTickExecutor = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
tick();
|
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);
|
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.setEnabled(false);
|
||||||
//binding.shareButton.setText(R.string.please_wait);
|
//binding.shareButton.setText(R.string.please_wait);
|
||||||
mHandler.removeCallbacks(mTickExecutor);
|
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.recordVoiceButton.setOnClickListener(this.mRecordVoiceButtonListener);
|
||||||
binding.emojiButton.setOnClickListener(this.memojiButtonListener);
|
binding.emojiButton.setOnClickListener(this.memojiButtonListener);
|
||||||
binding.keyboardButton.setOnClickListener(this.mkeyboardButtonListener);
|
binding.keyboardButton.setOnClickListener(this.mkeyboardButtonListener);
|
||||||
|
binding.timer.setOnClickListener(this.mTimerClickListener);
|
||||||
binding.takePictureButton.setOnClickListener(this.mtakePictureButtonListener);
|
binding.takePictureButton.setOnClickListener(this.mtakePictureButtonListener);
|
||||||
binding.messagesView.setOnScrollListener(mOnScrollListener);
|
binding.messagesView.setOnScrollListener(mOnScrollListener);
|
||||||
binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
||||||
|
@ -3211,13 +3225,13 @@ public class ConversationFragment extends XmppFragment
|
||||||
}
|
}
|
||||||
setupOutputFile();
|
setupOutputFile();
|
||||||
mRecorder.setOutputFile(mOutputFile.getAbsolutePath());
|
mRecorder.setOutputFile(mOutputFile.getAbsolutePath());
|
||||||
|
binding.timer.clearAnimation();
|
||||||
try {
|
try {
|
||||||
mRecorder.prepare();
|
mRecorder.prepare();
|
||||||
mRecorder.start();
|
mRecorder.start();
|
||||||
recording = true;
|
recording = true;
|
||||||
mStartTime = SystemClock.elapsedRealtime();
|
//mStartTime = SystemClock.elapsedRealtime();
|
||||||
mHandler.postDelayed(mTickExecutor, 100);
|
mHandler.postDelayed(mTickExecutor, 0);
|
||||||
Log.d("Voice Recorder", "started recording to " + mOutputFile.getAbsolutePath());
|
Log.d("Voice Recorder", "started recording to " + mOutputFile.getAbsolutePath());
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} 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) {
|
protected void stopRecording(final boolean saveFile) {
|
||||||
|
binding.timer.clearAnimation();
|
||||||
try {
|
try {
|
||||||
if (recording) {
|
if (recording) {
|
||||||
stopRecording();
|
stopRecording();
|
||||||
|
@ -3249,6 +3300,7 @@ public class ConversationFragment extends XmppFragment
|
||||||
} finally {
|
} finally {
|
||||||
mRecorder = null;
|
mRecorder = null;
|
||||||
mStartTime = 0;
|
mStartTime = 0;
|
||||||
|
mHandler.removeCallbacks(mTickExecutor);
|
||||||
}
|
}
|
||||||
if (!saveFile && mOutputFile != null) {
|
if (!saveFile && mOutputFile != null) {
|
||||||
if (mOutputFile.delete()) {
|
if (mOutputFile.delete()) {
|
||||||
|
@ -3367,7 +3419,26 @@ public class ConversationFragment extends XmppFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tick() {
|
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
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue