List of usage examples for android.os Vibrator vibrate
@RequiresPermission(android.Manifest.permission.VIBRATE) public void vibrate(VibrationEffect vibe)
From source file:us.shandian.blacklight.ui.statuses.TimeLineFragment.java
@Override public boolean onLongClick(View arg0) { Vibrator vibrator = (Vibrator) getActivity().getApplication().getSystemService(Service.VIBRATOR_SERVICE); vibrator.vibrate(50); Toast.makeText(getActivity().getApplicationContext(), getString(R.string.new_post), Toast.LENGTH_SHORT) .show();/*w ww . ja v a2s.co m*/ return true; }
From source file:com.joshmoles.byobcontroller.ControlActivity.java
private void btnVibrate() { Vibrator vibe = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); vibe.vibrate(Consts.VIBE_LENGTH); }
From source file:com.tessoft.nearhere.GcmIntentService.java
private void sendNotification(Bundle extras) { String title = extras.getString("title"); String type = extras.getString("type"); String msg = extras.getString("message"); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setAutoCancel(true);//from w w w . j av a 2s.c o m Intent intent = null; boolean isActive = false; // check if background // ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE ); // List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses(); // for(int i = 0; i < procInfos.size(); i++) // { // if(procInfos.get(i).processName.equals("com.tessoft.nearhere")) // isActive = true; // } // check if foreground ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE); if (services.get(0).topActivity.getPackageName().toString() .equalsIgnoreCase(getApplicationContext().getPackageName().toString())) { isActive = true; } if (isActive) { intent = new Intent("updateUnreadCount"); intent.putExtra("type", type); if ("message".equals(type)) { intent.putExtra("fromUserID", extras.getString("fromUserID")); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); } else if ("postReply".equals(type)) { intent.putExtra("postID", extras.getString("postID")); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); } getApplicationContext().sendBroadcast(intent); } else { if ("message".equals(type)) { intent = new Intent(this, UserMessageActivity.class); HashMap hash = new HashMap(); hash.put("fromUserID", extras.getString("fromUserID")); hash.put("userID", extras.getString("toUserID")); intent.putExtra("messageInfo", hash); mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); mBuilder.setVibrate(new long[] { 1000, 1000 }); } else if ("postReply".equals(type)) { intent = new Intent(this, TaxiPostDetailActivity.class); intent.putExtra("postID", extras.getString("postID")); mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); mBuilder.setVibrate(new long[] { 1000, 1000 }); } else if ("newPostByDistance".equals(type)) { intent = new Intent(this, TaxiPostDetailActivity.class); intent.putExtra("postID", extras.getString("postID")); } else if ("event".equals(type)) { intent = new Intent(this, EventViewerActivity.class); intent.putExtra("eventSeq", extras.getString("eventSeq")); intent.putExtra("pushNo", extras.getString("pushNo")); if ("on".equals(extras.getString("sound"))) mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); if ("on".equals(extras.getString("vibrate"))) mBuilder.setVibrate(new long[] { 1000, 1000 }); } else if ("eventssl".equals(type)) { intent = new Intent(this, EventViewerActivity.class); intent.putExtra("eventSeq", extras.getString("eventSeq")); intent.putExtra("pushNo", extras.getString("pushNo")); intent.putExtra("ssl", "true"); if ("on".equals(extras.getString("sound"))) mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); if ("on".equals(extras.getString("vibrate"))) mBuilder.setVibrate(new long[] { 1000, 1000 }); } else { intent = new Intent(this, MainActivity.class); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }
From source file:digital.dispatch.TaxiLimoNewUI.GCM.GCMIntentService.java
@Override protected void onMessage(Context context, Intent intent) { String message = intent.getStringExtra("message"); c = context;//from w w w. j a va2 s . c o m Logger.v(TAG, "Received message " + message); if (!message.isEmpty()) { if (checkDisplayMsg(context, message, intent)) { WakeLocker.acquire(context); displayMessage(context, gcmType.message, message, id); sendNotification(context, message); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); WakeLocker.release(); } } }
From source file:com.phonegap.Notification.java
/** * Vibrates the device for the specified amount of time. * /*from w ww . ja v a 2s .com*/ * @param time Time to vibrate in ms. */ public void vibrate(long time) { // Start the vibration, 0 defaults to half a second. if (time == 0) { time = 500; } Vibrator vibrator = (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(time); }
From source file:in.blogspot.anselmbros.torchie.ui.fragment.SettingsFragment.java
private void vibrate(long time) { Vibrator vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); if (vib.hasVibrator()) vib.vibrate(time); }
From source file:org.fedorahosted.freeotp.main.ScanDialogFragment.java
@Override public void process(Frame frame) { byte[] i = frame.getImage(); Resolution r = frame.getSize();// www . j av a 2s. 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(); } }
From source file:org.y20k.transistor.helpers.CollectionAdapter.java
private void handleLongClick(int position) { // get current playback state loadAppState(mActivity);//from ww w .j ava 2 s . c om if (mPlayback && position == mStationIDCurrent) { // stop playback service mPlayerService.startActionStop(mActivity); // set playback state mStationIDLast = mStationIDCurrent; mPlayback = false; // inform user Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_long_press_playback_stopped), Toast.LENGTH_LONG).show(); } else { // start playback service String stationName = mCollection.getStations().get(position).getStationName(); String streamUri = mCollection.getStations().get(position).getStreamUri().toString(); mPlayerService.startActionPlay(mActivity, streamUri, stationName, position); // set playback state mStationIDLast = mStationIDCurrent; mStationIDCurrent = position; mPlayback = true; // inform user Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_long_press_playback_started), Toast.LENGTH_LONG).show(); } // vibrate 50 milliseconds Vibrator v = (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(50); // notify MainActivityFragment if (mCollectionChangedListener != null) { mCollectionChangedListener.collectionChanged(); } // Save station name and ID saveAppState(mActivity); }
From source file:de.uni_weimar.m18.anatomiederstadt.element.Quiz4Buttons.java
@Override public void onClick(View v) { Button correctButton;//from w w w . j a va 2 s .c o m switch (mCorrect) { case 1: correctButton = (Button) getActivity().findViewById(R.id.button1); break; case 2: correctButton = (Button) getActivity().findViewById(R.id.button2); break; case 3: correctButton = (Button) getActivity().findViewById(R.id.button3); break; case 4: correctButton = (Button) getActivity().findViewById(R.id.button4); break; default: correctButton = (Button) getActivity().findViewById(R.id.button1); } mTries += 1; if (v.getId() == correctButton.getId()) { // correct answer String congratulations = String.format(getString(R.string.congratulations_format_string), mPoints); SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP).margin(32, 32) .backgroundDrawable(R.drawable.points_snackbar_shape).text(congratulations) .eventListener(new EventListener() { @Override public void onShow(Snackbar snackbar) { } @Override public void onShowByReplace(Snackbar snackbar) { } @Override public void onShown(Snackbar snackbar) { } @Override public void onDismiss(Snackbar snackbar) { } @Override public void onDismissByReplace(Snackbar snackbar) { } @Override public void onDismissed(Snackbar snackbar) { if (mListener != null) { mListener.correctAnswerAction(mTarget); } } })); //Toast.makeText(getActivity(), "RRRRRRRICHTIG!", Toast.LENGTH_SHORT).show(); submitPointsToBackend(mPoints); } else if (mTries >= mMaxTries) { // user entered wrong answer too often String sorry = getString(R.string.sorry_correct_answer) + "\n\"" + correctButton.getText() + "\""; new MaterialDialog.Builder(getActivity()).title(getString(R.string.sorry_correct_answer_dialog_title)) .content(sorry).positiveText(getString(R.string.sorry_dismiss)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { if (mListener != null) { // go to next page anyway mListener.correctAnswerAction(mTarget); } } }).show(); } else { // wrong answer mPoints -= mPenalty; Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(300); new MaterialDialog.Builder(getActivity()).title(getString(R.string.wrong_answer_dialog_title)) .content(mHint).positiveText(R.string.wrong_answer_dismiss).show(); //Toast.makeText(getActivity(), "BZZZZZZZZZTTTT... falsch!", Toast.LENGTH_SHORT).show(); } }
From source file:me.heron.safefoodscanner.activity.MainActivity.java
private void buzz() { Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(Constants.BUZZ_LENGTH_MILLISECOND); }