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:de.dreier.mytargets.MainActivity.java

@Override
public void onEndFinished(final List<Shot> shotList, boolean remote) {
    confirm.setVisibility(View.VISIBLE);
    confirm.setTotalTimeMs(2500);// www . jav  a  2s .c  o m
    confirm.start();
    confirm.setListener(new DelayedConfirmationView.DelayedConfirmationListener() {
        @Override
        public void onTimerSelected(View view) {
            mTarget.setEnd(new End(round.shotsPerEnd, 0));
            confirm.setVisibility(View.INVISIBLE);
            confirm.reset();
        }

        @Override
        public void onTimerFinished(View view) {
            Intent intent = new Intent(MainActivity.this, ConfirmationActivity.class);
            intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.SUCCESS_ANIMATION);
            intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE, getString(R.string.saved));
            startActivity(intent);
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(200);
            finish();
            sendMessage(shotList);
        }
    });
}

From source file:nl.endran.scrumpoker.fragments.cardselection.QuickSettingsFragment.java

private void installShakeListener() {
    shakeManager.start(new ShakeManager.Listener() {
        @Override//from   ww w  .j  av  a  2s. c  o  m
        public void onShake() {
            Context context = getContext();
            if (context != null && tracking != null) {
                Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(500);
                tracking.logCustom(new CustomEvent("Reveal").putCustomAttribute("Type", "Shake"));
                informListener();
            }
        }
    });
}

From source file:br.com.imovelhunter.imovelhunterwebmobile.GcmIntentService.java

private void vibrar() {
    Vibrator rr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long milliseconds = 1000;
    rr.vibrate(milliseconds);
}

From source file:org.ohmage.appwidget.StressButtonService.java

@Override
protected void onHandleIntent(Intent intent) {

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(100);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Calendar now = Calendar.getInstance();
    String launchTime = dateFormat.format(now.getTime());

    final SharedPreferencesHelper preferencesHelper = new SharedPreferencesHelper(this);

    if (preferencesHelper.isUserDisabled()) {
        ((OhmageApplication) getApplication()).resetAll();
    }//from   ww w.j  av a 2 s . c om

    if (!preferencesHelper.isAuthenticated()) {
        Log.i(TAG, "no credentials saved, so launch Login");
        startActivity(new Intent(this, LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        return;
    }

    List<Prompt> prompts = null;

    String surveyId = "stressButton";
    String surveyTitle = "Stress";

    try {
        prompts = PromptXmlParser.parsePrompts(CampaignXmlHelper.loadDefaultCampaign(this), surveyId);
    } catch (NotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (prompts != null && prompts.size() > 0) {

        startService(new Intent(this, SurveyGeotagService.class));

        if (((AbstractPrompt) prompts.get(0)).getResponseObject() == null) {
            Toast.makeText(this, "There is a bug: default value not being set!", Toast.LENGTH_SHORT).show();
        } else {
            ((AbstractPrompt) prompts.get(0)).setDisplayed(true);
            ((AbstractPrompt) prompts.get(0)).setSkipped(false);
            Log.i(TAG, prompts.get(0).getResponseJson());
            storeResponse(surveyId, surveyTitle, launchTime, prompts);
            //Toast.makeText(this, "Registered stressful event.", Toast.LENGTH_SHORT).show();
            mHandler.post(new DisplayToast("Registered stressful event!"));

        }
    }
}

From source file:hongik.android.project.best.HistoryActivity.java

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

    Intent reviewIntent = new Intent(this, ReviewActivity.class);
    reviewIntent.putExtra("BUID", nowPeripheral.getBDAddress().replace(":", ""));
    reviewIntent.putExtra("CID", cid);
    nowPeripheral = null;/*from   w ww  . ja  v  a2s.c om*/
    startActivityForResult(reviewIntent, 2);
}

From source file:il.ac.shenkar.todos.notifications.NotificationService.java

@Override
public void onHandleIntent(Intent intent) {
    taskListModel = TaskList.getSingletonObject(this);
    // Vibrate the mobile phone
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    //vibrator.vibrate(vibrationTime);
    vibrator.vibrate(vibrationTime);
    taskListModel.getDataBase().open();// w w w.j  av  a2 s  .c om

    String[] tokens = intent.getStringExtra("description").split(",");
    taskId = Integer.parseInt(tokens[0]);
    String title = tokens[1];
    String windowTitle = null;
    String toSend = null;
    Task triggeredTask = null;
    boolean alarmRepeating = true;

    // check if alert was triggered by the location alert
    if (title.equals("GPS location nearby !")) {
        alarmType = "GPS";
        alarmRepeating = false;
        taskId = intent.getIntExtra("Id", 0);
        windowTitle = "GPS location nearby !";
        toSend = "Title: " + tokens[3] + "\n\nLocation: " + tokens[2];
        triggeredTask = Utils.findTaskById(this, taskId);

        if (triggeredTask != null) {
            // remove the alarm
            new TaskAlarms(this).cancelProximityAlert(taskId, triggeredTask.getTaskTitle());
            taskListModel.getDataBase().disableTaskLocationAlert(taskId);
        }
    } else // triggered by time alert
    {
        alarmType = "Time";
        windowTitle = "Notification";
        toSend = "Title: " + title + "\n\nDescription: " + tokens[2];
        triggeredTask = Utils.findTaskById(this, taskId);

        if (triggeredTask != null) {
            String taskNotification = triggeredTask.getDate();
            // checks if the alarm has an interval
            if (!taskNotification.contains("(")) {
                alarmRepeating = false;
                new TaskAlarms(this).cancelAlarm(taskId, triggeredTask.getTaskTitle());
                taskListModel.getDataBase().disableTaskNotification(taskId);
            }
        }
    }

    // Prepare intent which is triggered if the
    // notification is selected
    Intent myIntent = new Intent(this, NotificationReceiverActivity.class);
    myIntent.putExtra("windowTitle", windowTitle);
    myIntent.putExtra("taskContent", toSend);
    PendingIntent pIntent = PendingIntent.getActivity(this, taskId, myIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    Notification noti = new Notification.Builder(this).setContentTitle(title).setContentText(tokens[2])
            .setSmallIcon(R.drawable.app_icon).setContentIntent(pIntent).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    noti.flags |= Notification.FLAG_SHOW_LIGHTS;
    noti.ledARGB = 0xff00ffff;
    noti.ledOnMS = 300;
    noti.ledOffMS = 1000;

    if (Utils.IS_DEFAULT_SOUND) {
        //To play the default sound with your notification:
        noti.defaults |= Notification.DEFAULT_SOUND;
    } else {
        new MediaPlayerHandler(this).playAudio(Utils.LOUD_NOTIFICATION__SOUND);
    }
    notificationManager.notify(taskId, noti);

    if (!alarmRepeating) {
        // brodcast a message to main activity
        messageToActivity();
    }
}

From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java

private void nativeVibrate(Context context, boolean hasVibration) {
    if (hasVibration) {
        final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

        vibrator.vibrate(Const.VIBRATION_DURATION);
    }/*  w ww  .  j av  a 2  s  .  c o m*/
}

From source file:org.namelessrom.devicecontrol.modules.info.hardware.GpsView.java

public void onResume() {
    final Context context = getContext();
    final boolean location = BaseActivity.isGranted(context, Manifest.permission.ACCESS_COARSE_LOCATION)
            && BaseActivity.isGranted(context, Manifest.permission.ACCESS_FINE_LOCATION);
    if (!location) {
        final Intent intent = new Intent(BaseActivity.ACTION_REQUEST_PERMISSION);
        final ArrayList<String> permissions = new ArrayList<>(2);
        permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
        permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
        intent.putStringArrayListExtra(BaseActivity.EXTRA_PERMISSIONS, permissions);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }//from www.  j  a  va2  s.  c  o  m

    addressSubscription = addressObservable.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<String>() {
                @Override
                public void call(String s) {
                    if (BuildConfig.DEBUG) {
                        final Vibrator vibrator = App.get().getVibrator();
                        vibrator.cancel();
                        vibrator.vibrate(75);
                    }
                    statusView.setText(s);
                }
            }, new ErrorHandler(statusView));
}

From source file:angeloid.dreamnarae.Boot_Script.java

@Override
public void onReceive(Context c, Intent i) {

    boot_top = c.getString(R.string.boot_top);
    boot_bottom = c.getString(R.string.boot_bottom);
    boot_ticker = c.getString(R.string.boot_tickker);

    if (!(RootTools.isAccessGiven())) {
        Toast.makeText(c, R.string.noroottoast, Toast.LENGTH_LONG).show();
    } else {/*  w  w w.j  a va  2s. com*/
        if (new File("/system/etc/dreamnarae.sh").exists()) {
            CommandCapture command = new CommandCapture(0, "mount -o rw,remount /system",
                    "sh /system/etc/dreamnarae.sh", "sh /system/etc/install-recovery.sh");

            NotificationManager manager = (NotificationManager) c
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder ncbuilder = new NotificationCompat.Builder(c);
            ncbuilder.setContentTitle(boot_top);
            ncbuilder.setContentText(boot_bottom);
            ncbuilder.setSmallIcon(R.drawable.ic_launcher);
            ncbuilder.setAutoCancel(true);
            ncbuilder.setTicker(boot_ticker);
            Vibrator vibe = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
            try {
                RootTools.getShell(true).add(command).waitForFinish();
                Log.d("debug", "ok!");
                vibe.vibrate(200);
                manager.notify(1, ncbuilder.build());
            } catch (InterruptedException e) {
            } catch (IOException e) {
            } catch (TimeoutException e) {
            } catch (RootDeniedException e) {
            }

        }

    }
}

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

@OnClick(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  a2 s. c om
    final Alarm oldAlarm = getAlarm();
    Alarm newAlarm = oldAlarm.toBuilder().vibrates(checked).build();
    oldAlarm.copyMutableFieldsTo(newAlarm);
    persistUpdatedAlarm(newAlarm, false);
}