Search in sources :

Example 1 with BeepManager

use of com.github.obsessive.simplifyreader.ui.activity.qrcode.utils.BeepManager in project SimplifyReader by chentao0707.

the class CaptureActivity method initViewsAndEvents.

@Override
protected void initViewsAndEvents() {
    hasSurface = false;
    mInactivityTimer = new InactivityTimer(this);
    mBeepManager = new BeepManager(this);
    initCropViewAnimator();
    capturePictureBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            readyGoForResult(CommonImagePickerListActivity.class, IMAGE_PICKER_REQUEST_CODE);
        }
    });
    captureLightBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isLightOn) {
                cameraManager.setTorch(false);
                captureLightBtn.setSelected(false);
            } else {
                cameraManager.setTorch(true);
                captureLightBtn.setSelected(true);
            }
            isLightOn = !isLightOn;
        }
    });
    captureModeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.capture_mode_barcode) {
                PropertyValuesHolder qr2barWidthVH = PropertyValuesHolder.ofFloat("width", 1.0f, (float) mBarcodeCropWidth / mQrcodeCropWidth);
                PropertyValuesHolder qr2barHeightVH = PropertyValuesHolder.ofFloat("height", 1.0f, (float) mBarcodeCropHeight / mQrcodeCropHeight);
                ValueAnimator valueAnimator = ValueAnimator.ofPropertyValuesHolder(qr2barWidthVH, qr2barHeightVH);
                valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        Float fractionW = (Float) animation.getAnimatedValue("width");
                        Float fractionH = (Float) animation.getAnimatedValue("height");
                        RelativeLayout.LayoutParams parentLayoutParams = (RelativeLayout.LayoutParams) captureCropView.getLayoutParams();
                        parentLayoutParams.width = (int) (mQrcodeCropWidth * fractionW);
                        parentLayoutParams.height = (int) (mQrcodeCropHeight * fractionH);
                        captureCropView.setLayoutParams(parentLayoutParams);
                    }
                });
                valueAnimator.addListener(new Animator.AnimatorListener() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        initCrop();
                        setDataMode(DecodeUtils.DECODE_DATA_MODE_BARCODE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                    }
                });
                valueAnimator.start();
            } else if (checkedId == R.id.capture_mode_qrcode) {
                PropertyValuesHolder bar2qrWidthVH = PropertyValuesHolder.ofFloat("width", 1.0f, (float) mQrcodeCropWidth / mBarcodeCropWidth);
                PropertyValuesHolder bar2qrHeightVH = PropertyValuesHolder.ofFloat("height", 1.0f, (float) mQrcodeCropHeight / mBarcodeCropHeight);
                ValueAnimator valueAnimator = ValueAnimator.ofPropertyValuesHolder(bar2qrWidthVH, bar2qrHeightVH);
                valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        Float fractionW = (Float) animation.getAnimatedValue("width");
                        Float fractionH = (Float) animation.getAnimatedValue("height");
                        RelativeLayout.LayoutParams parentLayoutParams = (RelativeLayout.LayoutParams) captureCropView.getLayoutParams();
                        parentLayoutParams.width = (int) (mBarcodeCropWidth * fractionW);
                        parentLayoutParams.height = (int) (mBarcodeCropHeight * fractionH);
                        captureCropView.setLayoutParams(parentLayoutParams);
                    }
                });
                valueAnimator.addListener(new Animator.AnimatorListener() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        initCrop();
                        setDataMode(DecodeUtils.DECODE_DATA_MODE_QRCODE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                    }
                });
                valueAnimator.start();
            }
        }
    });
}
Also used : RadioGroup(android.widget.RadioGroup) InactivityTimer(com.github.obsessive.simplifyreader.ui.activity.qrcode.utils.InactivityTimer) BeepManager(com.github.obsessive.simplifyreader.ui.activity.qrcode.utils.BeepManager) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) SurfaceView(android.view.SurfaceView) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) CommonImagePickerListActivity(com.github.obsessive.simplifyreader.ui.activity.picker.CommonImagePickerListActivity) RelativeLayout(android.widget.RelativeLayout) PropertyValuesHolder(com.nineoldandroids.animation.PropertyValuesHolder)

Aggregations

SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 RadioGroup (android.widget.RadioGroup)1 RelativeLayout (android.widget.RelativeLayout)1 InjectView (butterknife.InjectView)1 CommonImagePickerListActivity (com.github.obsessive.simplifyreader.ui.activity.picker.CommonImagePickerListActivity)1 BeepManager (com.github.obsessive.simplifyreader.ui.activity.qrcode.utils.BeepManager)1 InactivityTimer (com.github.obsessive.simplifyreader.ui.activity.qrcode.utils.InactivityTimer)1 Animator (com.nineoldandroids.animation.Animator)1 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)1 PropertyValuesHolder (com.nineoldandroids.animation.PropertyValuesHolder)1 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)1