Monday, 30 July 2018

If the button is ACTION_DOWN, can it be forcibly held down for 1 second?

Holds the current button (ACTION_DOWN) to get the current time when pressed. When I release the button (ACTION_UP), the current time is also taken, and the audio file is cut and pasted by the time difference. If the user presses and releases a button too fast, it will generate an invalid audio file. So I would like to implement the function of unconditional pressing more than 1 second.

Buttons ACTION_DOWN, ACTION_UP Is there a way to implement such functionality in a motion event? If you know, please give me a favor. Below is the source code for the touch listener.

recordBtn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    long currentDuration = vAudioPlayer.getCurrentDuration();
                    // 녹음 시작 ( combineList 사이즈가 짝수일 때 )
                    if (mRecordThread != null) {
                        if (combineList.size() % 2 == 0) {
                            mRecordThread.startFileWrite(currentDuration);
                            combineList.add(currentDuration);
                        }
                    }
                }

                // 버튼, 이미지 뷰 애니메이션
                micBg1.setVisibility(View.VISIBLE);
                micBg2.setVisibility(View.VISIBLE);

                micBg1.startAnimation(animMic1);
                micBg2.startAnimation(animMic2);

                //userImg.setImageBitmap(userImgBitmap);
                userImg.startAnimation(animZoomIn);
                // artistImg.setImageBitmap(artistBlurImg);
                artistImg.startAnimation(animZoomOut);

                break;
                case MotionEvent.ACTION_UP: {
                    long currentDuration = vAudioPlayer.getCurrentDuration();
                    if (mRecordThread != null) {
                        // 병합을 시작 ( combineList가 홀수일 때: 레코드 버튼을 눌렀을 때 combineList의 사이즈가 홀수가 된다 )
                        if (combineList.size() % 2 == 1) {
                            mRecordThread.stopFileWrite();

                            File waveFile = new File(RecordActivity.currentCreateFileName.replaceAll("/ucc/", "/tmp/")
                                    + "_" + calTime(combineList.get(combineList.size() - 1), false) + "_uv.pcm");

                            // 위의 경로에 해당 녹음 파일이 존재하면 wav 파일로 변환,
                            if (waveFile.exists()) {

                                copyWaveFile(RecordActivity.currentCreateFileName.replaceAll("/ucc/", "/tmp/") + "_" + calTime(combineList.get(combineList.size() - 1), false) + "_uv.pcm",
                                        RecordActivity.currentCreateFileName.replaceAll("/ucc/", "/tmp/") + "_" + calTime(combineList.get(combineList.size() - 1), false) + "_u0.wav");

                                // wav 볼륨 파일 증폭
                                if (mMp3ConcatThread != null) {
                                    mMp3ConcatThread.startCombine(null, 3333333333333333333L, combineList.get(combineList.size() - 1), currentDuration);
                                }
                            }

                            combineList.add(currentDuration);
                            // startCombine Thread 분기 처리( if old_position: 0, 3333333333333333333L, 7777777777777777777L, 그 외 )
                            if (combineList.size() == 2) {
                                // 0: 처음 한번 녹음할 때
                                mMp3ConcatThread.startCombine(null, 0, combineList.get(combineList.size() - 2), currentDuration);
                            } else {
                                // 그 외: 두번 이상 녹음할 때
                                mMp3ConcatThread.startCombine(null, combineList.get(combineList.size() - 3), combineList.get(combineList.size() - 2), currentDuration);
                            }
                        }
                    }
                }

                // 버튼, 이미지 뷰 애니메이션
                micBg1.setVisibility(View.GONE);
                micBg2.setVisibility(View.GONE);

                micBg1.clearAnimation();
                micBg2.clearAnimation();

                // userImg.setImageBitmap(userBlurImg);
                userImg.startAnimation(animZoomOut);
                // artistImg.setImageBitmap(artistImgBitmap);
                artistImg.startAnimation(animZoomIn);
                break;
            }
            return false;
        }
    });



from If the button is ACTION_DOWN, can it be forcibly held down for 1 second?

No comments:

Post a Comment