Example usage for android.os VibrationEffect createOneShot

List of usage examples for android.os VibrationEffect createOneShot

Introduction

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

Prototype

public static VibrationEffect createOneShot(long milliseconds, int amplitude) 

Source Link

Document

Create a one shot vibration.

Usage

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

@Override
public void process(Frame frame) {
    byte[] i = frame.getImage();
    Resolution r = frame.getSize();/*from  w w  w.  j  a  va2 s .  com*/

    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();
    }
}

From source file:org.rebo.app.TileMap.java

@Override
public boolean longPressHelper(final GeoPoint p1, final GeoPoint p2) {
    if (Build.VERSION.SDK_INT >= 26) {
        ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(50, 100));
    } else {// w  w w. ja v  a2s  .co  m
        ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50);
    }
    //        showToastOnUiThread("Distance Touch!");
    App.routeSearch.showRoute(p1, p2);
    return true;
}