Example usage for android.os VibrationEffect DEFAULT_AMPLITUDE

List of usage examples for android.os VibrationEffect DEFAULT_AMPLITUDE

Introduction

In this page you can find the example usage for android.os VibrationEffect DEFAULT_AMPLITUDE.

Prototype

int DEFAULT_AMPLITUDE

To view the source code for android.os VibrationEffect DEFAULT_AMPLITUDE.

Click Source Link

Document

The default vibration strength of the device.

Usage

From source file:org.fedorahosted.freeotp.main.ScanDialogFragment.java

@Override
public void process(Frame frame) {
    byte[] i = frame.getImage();
    Resolution r = frame.getSize();/*w w w.ja  v a2 s  . c o  m*/

    LuminanceSource ls = new PlanarYUVLuminanceSource(i, r.width, r.height, 0, 0, r.width, r.height, false);

    try {
        BinaryBitmap bb = new BinaryBitmap(new HybridBinarizer(ls));
        final String uri = new QRCodeReader().decode(bb).getText();

        int size = mImage.getWidth();
        if (size > mImage.getHeight())
            size = mImage.getHeight();

        BitMatrix bm = new QRCodeWriter().encode(uri, BarcodeFormat.QR_CODE, size, size);
        mFotoapparat.stop();

        final Bitmap b = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        for (int x = 0; x < size; x++) {
            for (int y = 0; y < size; y++) {
                b.setPixel(x, y, bm.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }

        Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            v.vibrate(VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE));
        } else {
            v.vibrate(250);
        }

        mImage.post(new Runnable() {
            @Override
            public void run() {
                mProgress.setVisibility(View.INVISIBLE);
                mCamera.animate().setInterpolator(new DecelerateInterpolator()).setDuration(2000).alpha(0.0f)
                        .start();

                mImage.setImageBitmap(b);
                mImage.animate().setInterpolator(new DecelerateInterpolator()).setDuration(2000).alpha(1.0f)
                        .withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                mImage.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        Activity a = (Activity) getActivity();
                                        a.addToken(Uri.parse(uri), true);
                                    }
                                });
                                dismiss();
                            }
                        }).start();
            }
        });
    } catch (NotFoundException | ChecksumException | FormatException | WriterException e) {
        e.printStackTrace();
    }
}