Search in sources :

Example 1 with DownTimerListener

use of com.rongseal.widget.downtime.DownTimerListener in project SeaStar by 13120241790.

the class RecordDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getContext().setTheme(android.R.style.Theme_InputMethod);
    setContentView(R.layout.layout_dialog_record);
    Window window = getWindow();
    WindowManager.LayoutParams attributesParams = window.getAttributes();
    attributesParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    attributesParams.dimAmount = 0.4f;
    @SuppressWarnings("deprecation") int width = (int) (window.getWindowManager().getDefaultDisplay().getWidth() * 0.85);
    window.setLayout(width, LayoutParams.WRAP_CONTENT);
    downMinTimer = new DownTimer();
    downMinTimer.setListener(new DownTimerListener() {

        @Override
        public void onTick(long millisUntilFinished) {
            recordTimeFlag = false;
        }

        @Override
        public void onFinish() {
            recordTimeFlag = true;
        }
    });
    downMaxTimer = new DownTimer();
    downMaxTimer.setListener(new DownTimerListener() {

        @Override
        public void onTick(long millisUntilFinished) {
        }

        @Override
        public void onFinish() {
            animation.stop();
            recorderUtils.onRecord(false);
            view_line.setVisibility(View.VISIBLE);
            btn_detail_record.setVisibility(View.GONE);
            img_record_animation.setVisibility(View.GONE);
            btn_detail_confirm.setVisibility(View.VISIBLE);
            btn_detail_confirm.setText(R.string.submit_text);
            btn_detail_cancel.setVisibility(View.VISIBLE);
            img_record_bg.setVisibility(View.VISIBLE);
            tv_record_play.setVisibility(View.VISIBLE);
            NToast.shortToast(getContext(), R.string.record_time_max_text);
        }
    });
    recorderUtils = new MediaRecorderUtils();
    img_record_animation = (ImageView) findViewById(R.id.img_record_animation);
    img_record_bg = (ImageView) findViewById(R.id.img_record_bg);
    tv_record_play = (TextView) findViewById(R.id.tv_record_play);
    tv_record_play.setOnClickListener(this);
    animation = (AnimationDrawable) img_record_animation.getBackground();
    btn_detail_cancel = (Button) findViewById(R.id.btn_detail_cancel);
    btn_detail_cancel.setOnClickListener(this);
    btn_detail_cancel.setVisibility(View.GONE);
    view_line = (View) findViewById(R.id.view_line);
    view_line.setVisibility(View.GONE);
    btn_detail_confirm = (Button) findViewById(R.id.btn_detail_confirm);
    btn_detail_confirm.setOnClickListener(this);
    btn_detail_confirm.setVisibility(View.GONE);
    btn_detail_record = (Button) findViewById(R.id.btn_detail_record);
    btn_detail_record.setVisibility(View.VISIBLE);
    btn_detail_record.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    animation.stop();
                    animation.start();
                    if (downMinTimer != null) {
                        downMinTimer.stopDown();
                    }
                    downMinTimer.startDown(2000);
                    if (downMaxTimer != null) {
                        downMaxTimer.stopDown();
                    }
                    downMaxTimer.startDown(5000);
                    recorderUtils.onRecord(true);
                    break;
                case MotionEvent.ACTION_UP:
                    animation.stop();
                    recorderUtils.onRecord(false);
                    if (downMaxTimer != null) {
                        downMaxTimer.stopDown();
                    }
                    if (recordTimeFlag) {
                        view_line.setVisibility(View.VISIBLE);
                        btn_detail_record.setVisibility(View.GONE);
                        img_record_animation.setVisibility(View.GONE);
                        btn_detail_confirm.setVisibility(View.VISIBLE);
                        btn_detail_confirm.setText(R.string.submit_text);
                        btn_detail_cancel.setVisibility(View.VISIBLE);
                        img_record_bg.setVisibility(View.VISIBLE);
                        tv_record_play.setVisibility(View.VISIBLE);
                    } else {
                        NToast.shortToast(getContext(), R.string.record_time_text);
                    }
                    break;
            }
            return false;
        }
    });
}
Also used : Window(android.view.Window) OnTouchListener(android.view.View.OnTouchListener) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) WindowManager(android.view.WindowManager) MotionEvent(android.view.MotionEvent) DownTimer(com.rongseal.widget.downtime.DownTimer) DownTimerListener(com.rongseal.widget.downtime.DownTimerListener) MediaRecorderUtils(com.rongseal.utlis.MediaRecorderUtils)

Aggregations

MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 OnTouchListener (android.view.View.OnTouchListener)1 Window (android.view.Window)1 WindowManager (android.view.WindowManager)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 MediaRecorderUtils (com.rongseal.utlis.MediaRecorderUtils)1 DownTimer (com.rongseal.widget.downtime.DownTimer)1 DownTimerListener (com.rongseal.widget.downtime.DownTimerListener)1