Example usage for android.os Vibrator vibrate

List of usage examples for android.os Vibrator vibrate

Introduction

In this page you can find the example usage for android.os Vibrator vibrate.

Prototype

@RequiresPermission(android.Manifest.permission.VIBRATE)
    public void vibrate(VibrationEffect vibe) 

Source Link

Usage

From source file:net.tjohns.badgescanner.ScanActivity.java

private void scanBadge() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(VIBRATION_DURATION);

    Intent intent = getIntent();/*w ww  .  ja v a  2  s . com*/

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
        Tag rawTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        MifareClassic tag = MifareClassic.get(rawTag);
        try {
            // Read from badge
            NfcConnection tagConnection = new NfcConnection(tag, MifareClassic.KEY_DEFAULT);
            mBadge = new Badge();
            mBadge.readFromTag(tagConnection);
            tagConnection.close();
        } catch (TagLostException e) {
            // TODO(trevorjohns): Convert to dialog
            Toast.makeText(this, "Tag lost", Toast.LENGTH_LONG);
            finish();
        } catch (IOException e) {
            // TODO(trevorjohns): Convert to dialog
            Toast.makeText(this, "IOExcpetion detected", Toast.LENGTH_LONG);
            e.printStackTrace();
            finish();
        }
    }
}

From source file:com.finchuk.clock2.alarms.ui.ExpandedAlarmViewHolder.java

@OnClick(com.finchuk.clock2.R.id.vibrate)
void onVibrateToggled() {
    final boolean checked = mVibrate.isChecked();
    if (checked) {
        Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(300);
    }/*from w  w  w.  j  av  a  2s  . c om*/
    final Alarm oldAlarm = getAlarm();
    Alarm newAlarm = oldAlarm.toBuilder().vibrates(checked).build();
    oldAlarm.copyMutableFieldsTo(newAlarm);
    persistUpdatedAlarm(newAlarm, false);
}

From source file:com.tamuhack.bootcamp.MessagesFragment.java

/**
 * Call whenever you want the most recent list of messages
 *//*from  w w  w .  j av a 2 s .co m*/
private void fetchMessages() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Messages");
    query.setLimit(100);
    query.addDescendingOrder("createdAt");
    query.include("poster");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> parseObjectList, ParseException e) {
            if (e == null) {

                // found some messages, print how many
                Log.d(TAG, "Retrieved " + parseObjectList.size() + " messages");

                // create message objects so that we can use them later
                //  to make the visible list in the adapter
                ArrayList<Message> messages = new ArrayList<Message>();
                for (int i = parseObjectList.size() - 1; i >= 0; i--) {
                    messages.add(new Message(parseObjectList.get(i)));
                }

                // did we get any new messages? if so we should scroll to the bottom
                boolean hasNewMessages = mAdapter.areListsDifferent(messages);

                if (hasNewMessages) {
                    mAdapter.setMessages(messages);
                    mRecyclerView.scrollToPosition(messages.size() - 1);
                    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    v.vibrate(50);
                }

                // fetch messages again in a couple seconds
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        fetchMessages();
                    }
                }, 5000);

            } else {
                Log.d(TAG, "Error: " + e.getMessage());
                showError();
            }
        }
    });

}

From source file:com.intel.xdk.notification.Notification.java

public void vibrate() {
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(500);
}

From source file:com.example.pavle92.riddlequizapp.ARSimple.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_model3d);

    kontekst = getApplicationContext();/*from w  w w  .j  a va2 s .c  o m*/
    Bundle bnd = getIntent().getExtras();
    lat = bnd.getDouble("lat");
    log = bnd.getDouble("log");

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    userName = settings.getString("UserName", "");

    //assets
    AssetHelper assetHelper = new AssetHelper(getAssets());
    assetHelper.cacheAssetFolder(getApplicationContext(), "Data");

    mainLayout = (FrameLayout) this.findViewById(R.id.mainLayout);

    if (!checkCameraPermission()) {
        //if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { //ASK EVERY TIME - it's essential!
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA },
                MY_PERMISSIONS_REQUEST_CAMERA);
    }

    // When the screen is tapped, inform the renderer and vibrate the phone
    mainLayout.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            simpleRenderer.click();

            Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
            vib.vibrate(40);

            //                    Toast.makeText(this,marker.getTitle(),Toast.LENGTH_SHORT).show();

            Thread t1 = new Thread(new Runnable() {
                @Override
                public void run() {

                    Intent in = new Intent(ARSimple.this, AnswerBox.class);

                    Place nearest = MyPlacesHTTPHelper.getNearestPlace(lat, log);
                    in.putExtra("lat", Double.valueOf(nearest.getLatitude()));
                    in.putExtra("log", Double.valueOf(nearest.getLongitude()));
                    in.putExtra("riddleQuestionAnsw",
                            nearest.getRidle() + "&" + nearest.getHint() + "&" + nearest.getSolution());
                    in.putExtra("userName", userName);
                    in.putExtra("userNameQ", "RiddleQuizTeam");
                    Log.e("QQQQ", "RiddleQuizTeam");
                    startActivityForResult(in, 9890);
                }
            });
            t1.start();

            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    });
}

From source file:eisene.riskspeedtools.TimerSetupFrag.java

@Override
public void onTimerFinished() {
    Vibrator v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1500);
}

From source file:com.google.cloud.solutions.griddler.android.ui.game.LetterView.java

/**
 * Handles the animations when a tile is selected and not selected
 *//*from   ww w.  j a  v  a  2 s . c  om*/
public void udateUI() {
    LetterRenderModel renderModel = gameManager.getBoardRenderModel().getGridLayout().getBoard()
            .get(letterLocation);
    if (renderModel.getIsSelected() && !this.isSelected) {
        isSelected = true;
        selectedAnimationSet.start();
        Vibrator vibrationService = (Vibrator) this.getContext().getSystemService(Context.VIBRATOR_SERVICE);
        vibrationService.vibrate(10);
    } else if (this.isSelected && !renderModel.getIsSelected()) {
        isSelected = false;
        unselectedAnimationSet.start();
    }
}

From source file:edu.tjhsst.ion.gcmFrame.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM data received.// ww w  .ja  v a 2  s.  c  om
 * title
 * text
 * url
 * sound
 * ongoing
 * wakeup
 */
private void sendNotification(Bundle data) {
    Vibrator vib = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);

    int vibrate = Integer.parseInt(data.getString("vibrate", "0"));
    if (vibrate > 0) {

        vib.vibrate(vibrate);
    }
    String[] vibratepattern = data.getString("vibrate", "").split(",");
    long[] vibpattern = new long[vibratepattern.length];
    int i = 0;
    for (String p : vibratepattern) {
        vibpattern[i++] = Long.parseLong(p);
    }
    if (vibratepattern.length > 0) {
        vib.vibrate(vibpattern, -1);
    }
    String notif_title = data.getString("title", "");
    String notif_text = data.getString("text", "");
    String notif_url = data.getString("url", "");
    String notif_strsound = data.getString("sound", "");
    String notif_strongoing = data.getString("ongoing", "");
    String notif_strwakeup = data.getString("wakeup", "");
    boolean notif_sound = notif_strsound.equals("true");
    boolean notif_ongoing = notif_strongoing.equals("true");
    boolean notif_wakeup = notif_strwakeup.equals("true");

    Intent intent;
    if (notif_url.length() > 0) {
        intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } else {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(notif_url));
    }
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
    PowerManager.WakeLock wl = null;
    if (notif_wakeup) {
        Log.d("showNotification", "Wakeup enabled");
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        // FIXME: FULL_WAKE_LOCK is deprecated
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
        wl.acquire(500);
    }
    // NotificationCompat supports API level 12
    NotificationCompat.Builder n = new NotificationCompat.Builder(this).setContentTitle(notif_title)
            .setContentText(notif_text).setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_ic_notification))
            .setContentIntent(pIntent).setAutoCancel(true).setOngoing(notif_ongoing)
            .setTicker(notif_title + ": " + notif_text);
    if (notif_sound) {
        n.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notif = n.build();
    notificationManager.notify(0, notif);

    if (notif_wakeup) {
        wl.release();
    }

}

From source file:com.slodin.transalarm.GeofenceTransitionsIntentService.java

public void setOffAlarm() {
    Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    // Vibrate for 1000 milliseconds
    v.vibrate(1000);
    r = RingtoneManager.getRingtone(this, notification);
    r.play();/*from ww  w. j  a v  a  2  s  .  c om*/
}

From source file:com.example.isaac.nileswestlitcenter.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from ww  w.  ja  v  a2s .co m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {

        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {

            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.

        }
        if (extras.getString("subject") != null) {
            if (intent.getExtras().getString("delete") != null) {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    //delete from arraylist
                    for (int i = 0; i < storeWhileScreenOff.size(); i++) {
                        if (storeWhileScreenOff.get(i)[1] == extras.getString("subject")
                                && storeWhileScreenOff.get(i)[2] == extras.getString("name")) {
                            storeWhileScreenOff.remove(i);
                            return;
                        }
                    }
                    //not in stored list, but on screen
                    storeWhileScreenOff.add(
                            new String[] { "true", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(true, extras.getString("subject"), extras.getString("name"));
                    //                    MainActivity.deleteStudentFromList(extras.getString("subject"),extras.getString("name"));
                    //                   or MainActivity.delete(extras.getInt("id"));
                }
            } else {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    storeWhileScreenOff.add(
                            new String[] { "false", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(false, extras.getString("subject"), extras.getString("name"));
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotification(extras.getString("subject"), extras.getString("name"));
                Vibrator v = (Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                // Vibrate for 500 milliseconds
                v.vibrate(1000);
                ((PowerManager) getSystemService(POWER_SERVICE))
                        .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                                "TAG")
                        .acquire();
                Log.i(TAG, "Received: " + extras.toString());

            }

        }
    }

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}