Search in sources :

Example 1 with OnPlayListener

use of org.kymjs.blog.ui.widget.RecordButtonUtil.OnPlayListener in project KJFrameForAndroid by kymjs.

the class TweetRecordFragment method initWidget.

@Override
protected void initWidget(View view) {
    super.initWidget(view);
    RelativeLayout.LayoutParams params = (LayoutParams) mBtnRecort.getLayoutParams();
    params.width = DensityUtils.getScreenW(getActivity());
    params.height = (int) (DensityUtils.getScreenH(getActivity()) * 0.4);
    mBtnRecort.setLayoutParams(params);
    mBtnRecort.setOnFinishedRecordListener(new OnFinishedRecordListener() {

        @Override
        public void onFinishedRecord(String audioPath, int recordTime) {
            mLayout.setVisibility(View.VISIBLE);
            if (recordTime < 10) {
                mTvTime.setText("0" + recordTime + "\"");
            } else {
                mTvTime.setText(recordTime + "\"");
            }
            mImgAdd.setVisibility(View.GONE);
            filePath = null;
        }

        @Override
        public void onCancleRecord() {
            mLayout.setVisibility(View.GONE);
        }
    });
    drawable = (AnimationDrawable) mImgVolume.getBackground();
    mBtnRecort.getAudioUtil().setOnPlayListener(new OnPlayListener() {

        @Override
        public void stopPlay() {
            drawable.stop();
            mImgVolume.setBackgroundDrawable(drawable.getFrame(0));
        }

        @Override
        public void starPlay() {
            mImgVolume.setBackgroundDrawable(drawable);
            drawable.start();
        }
    });
    mEtSpeech.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > MAX_LEN) {
                mTvInputLen.setText("已达到最大长度");
            } else {
                mTvInputLen.setText("你还可以输入" + (MAX_LEN - s.length()) + "个字");
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() > MAX_LEN) {
                mEtSpeech.setText(s.subSequence(0, MAX_LEN));
                CharSequence text = mEtSpeech.getText();
                if (text instanceof Spannable) {
                    Selection.setSelection((Spannable) text, MAX_LEN);
                }
            }
        }
    });
}
Also used : LayoutParams(android.widget.RelativeLayout.LayoutParams) OnFinishedRecordListener(org.kymjs.blog.ui.widget.RecordButton.OnFinishedRecordListener) OnPlayListener(org.kymjs.blog.ui.widget.RecordButtonUtil.OnPlayListener) RelativeLayout(android.widget.RelativeLayout) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) LayoutParams(android.widget.RelativeLayout.LayoutParams) Spannable(android.text.Spannable)

Aggregations

Editable (android.text.Editable)1 Spannable (android.text.Spannable)1 TextWatcher (android.text.TextWatcher)1 RelativeLayout (android.widget.RelativeLayout)1 LayoutParams (android.widget.RelativeLayout.LayoutParams)1 OnFinishedRecordListener (org.kymjs.blog.ui.widget.RecordButton.OnFinishedRecordListener)1 OnPlayListener (org.kymjs.blog.ui.widget.RecordButtonUtil.OnPlayListener)1