android.os.VibrationEffect Java Examples
The following examples show how to use
android.os.VibrationEffect.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CallActivity.java From meshenger-android with GNU General Public License v3.0 | 6 votes |
private void startRinging() { log("startRinging"); int ringerMode = ((AudioManager) getSystemService(AUDIO_SERVICE)).getRingerMode(); if (ringerMode == AudioManager.RINGER_MODE_SILENT) { return; } vibrator = ((Vibrator) getSystemService(VIBRATOR_SERVICE)); long[] pattern = {1500, 800, 800, 800}; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { VibrationEffect vibe = VibrationEffect.createWaveform(pattern, 0); vibrator.vibrate(vibe); } else { vibrator.vibrate(pattern, 0); } if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) { return; } ringtone = RingtoneManager.getRingtone(this, RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE)); ringtone.play(); }
Example #2
Source File: RecorderService.java From screenrecorder with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onShake() { if (!isRecording) { Vibrator vibrate = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); getManager().cancel(Const.SCREEN_RECORDER_WAITING_FOR_SHAKE_NOTIFICATION_ID); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) vibrate.vibrate(500); else VibrationEffect.createOneShot(500, 255); startRecording(); Toast.makeText(this, "Rec start", Toast.LENGTH_SHORT).show(); } else { Intent recordStopIntent = new Intent(this, RecorderService.class); recordStopIntent.setAction(Const.SCREEN_RECORDING_STOP); startService(recordStopIntent); Toast.makeText(this, "Rec stop", Toast.LENGTH_SHORT).show(); mShakeDetector.stop(); } }
Example #3
Source File: AlarmReceiver.java From fastnfitness with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onReceive(Context context, Intent arg1) { long[] pattern = { 0, // Start immediately 500, 500, 500, 500, 500}; Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createWaveform(pattern, -1)); } else { //deprecated in API 26 if (v != null) { v.vibrate(pattern, -1); } } }
Example #4
Source File: Haptics.java From OsmGo with MIT License | 6 votes |
@PluginMethod() @SuppressWarnings("MissingPermission") public void vibrate(PluginCall call) { Context c = this.getContext(); int duration = call.getInt("duration", 300); if(!hasPermission(Manifest.permission.VIBRATE)) { call.error("Can't vibrate: Missing VIBRATE permission in AndroidManifest.xml"); return; } if (Build.VERSION.SDK_INT >= 26) { ((Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibratePre26(duration); } call.success(); }
Example #5
Source File: MainActivity.java From MockSMS with Apache License 2.0 | 6 votes |
@Override public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) { AsyncTask.execute(new Runnable() { @Override public void run() { for (int i = 0; i < 2; i++) { Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && v != null) { v.vibrate(VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE)); } else if (v != null) { v.vibrate(250); } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } }); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); dateView.setText(new SimpleDateFormat("EEE, d MMM yyyy HH:mm", Locale.getDefault()).format(new Date(calendar.getTimeInMillis()))); }
Example #6
Source File: MainActivity.java From MockSMS with Apache License 2.0 | 6 votes |
@Override public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); timePickerDialog.show(getFragmentManager(), DATE_PICK_TAG); Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && v != null) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else if (v != null) { v.vibrate(500); } }
Example #7
Source File: MainActivity.java From MockSMS with Apache License 2.0 | 6 votes |
@Override public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) { AsyncTask.execute(() -> { for (int i = 0; i < 2; i++) { Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && v != null) { v.vibrate(VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE)); } else if (v != null) { v.vibrate(250); } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } }); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); dateView.setText(new SimpleDateFormat("EEE, d MMM yyyy HH:mm", Locale.getDefault()).format(new Date(calendar.getTimeInMillis()))); }
Example #8
Source File: MainActivity.java From MockSMS with Apache License 2.0 | 6 votes |
@Override public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); timePickerDialog.show(getFragmentManager(), DATE_PICK_TAG); Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && v != null) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else if (v != null) { v.vibrate(500); } }
Example #9
Source File: MetronomeService.java From Metronome-Android with Apache License 2.0 | 6 votes |
@Override public void run() { if (isPlaying) { handler.postDelayed(this, interval); if (emphasisIndex >= emphasisList.size()) emphasisIndex = 0; boolean isEmphasis = emphasisList.get(emphasisIndex); if (listener != null) listener.onTick(isEmphasis, emphasisIndex); emphasisIndex++; if (soundId != -1) soundPool.play(soundId, 1, 1, 0, 0, isEmphasis ? 1.5f : 1); else if (Build.VERSION.SDK_INT >= 26) vibrator.vibrate(VibrationEffect.createOneShot(isEmphasis ? 50 : 20, VibrationEffect.DEFAULT_AMPLITUDE)); else vibrator.vibrate(isEmphasis ? 50 : 20); } }
Example #10
Source File: CallActivity.java From Meshenger with GNU General Public License v3.0 | 6 votes |
private void ringPhone(){ int ringerMode = ((AudioManager) getSystemService(AUDIO_SERVICE)).getRingerMode(); if(ringerMode == AudioManager.RINGER_MODE_SILENT) return; vibrator = ((Vibrator) getSystemService(VIBRATOR_SERVICE)); long[] pattern = {1500, 800, 800, 800}; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { VibrationEffect vibe = VibrationEffect.createWaveform(pattern, 0); vibrator.vibrate(vibe); }else{ vibrator.vibrate(pattern, 0); } if(ringerMode == AudioManager.RINGER_MODE_VIBRATE) return; ringtone = RingtoneManager.getRingtone(this, RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE)); ringtone.play(); }
Example #11
Source File: FunctionButtonBar.java From alpha-wallet-android with MIT License | 6 votes |
@Override public void onLongTokenClick(View view, Token token, List<BigInteger> tokenIds) { //show radio buttons of all token groups if (adapter != null) adapter.setRadioButtons(true); selection = tokenIds; Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vb != null && vb.hasVibrator()) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { VibrationEffect vibe = VibrationEffect.createOneShot(200, DEFAULT_AMPLITUDE); vb.vibrate(vibe); } else { //noinspection deprecation vb.vibrate(200); } } //Wait for availability to complete waitForMapBuild(); populateButtons(token, getSelectedTokenId(tokenIds)); showButtons(); }
Example #12
Source File: KeyService.java From alpha-wallet-android with MIT License | 6 votes |
private void vibrate() { Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vb != null && vb.hasVibrator()) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { VibrationEffect vibe = VibrationEffect.createOneShot(200, DEFAULT_AMPLITUDE); vb.vibrate(vibe); } else { //noinspection deprecation vb.vibrate(200); } } }
Example #13
Source File: Rumble.java From Rumble-4-Android with MIT License | 6 votes |
private static void apiIndependentVibrate(long[] pattern) { if (rumbleDisabled) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate(VibrationEffect.createWaveform(pattern, -1)); } else { vibrator.vibrate(pattern, -1); } }
Example #14
Source File: Rumble.java From Rumble-4-Android with MIT License | 6 votes |
private static void apiIndependentVibrate(long milliseconds) { if (rumbleDisabled) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibrator.vibrate(milliseconds); } }
Example #15
Source File: DetailsMovie_Fragment.java From Android with MIT License | 6 votes |
private void openload_upload(String right_url) { Link l = new Link(); l.setUrl(right_url); l.setId(movie.getId().toString()); l.setTitle(movie.getTitle()); l.setYear(movie.getReleaseDate().substring(0,4)); new UploadOpenload(mContext,l); progresssbar_watch.setVisibility(View.GONE); watch.setVisibility(View.VISIBLE); Toast.makeText(mContext,"Go Premium!", Toast.LENGTH_SHORT).show(); Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(100,VibrationEffect.DEFAULT_AMPLITUDE)); }else{ v.vibrate(100); } }
Example #16
Source File: InputManager.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * @hide */ @Override public void vibrate(int uid, String opPkg, VibrationEffect effect, AudioAttributes attributes) { long[] pattern; int repeat; if (effect instanceof VibrationEffect.OneShot) { VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) effect; pattern = new long[] { 0, oneShot.getDuration() }; repeat = -1; } else if (effect instanceof VibrationEffect.Waveform) { VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) effect; pattern = waveform.getTimings(); repeat = waveform.getRepeatIndex(); } else { // TODO: Add support for prebaked effects Log.w(TAG, "Pre-baked effects aren't supported on input devices"); return; } try { mIm.vibrate(mDeviceId, pattern, repeat, mToken); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } }
Example #17
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public boolean isHapticFeedback() { if (effect instanceof VibrationEffect.Prebaked) { VibrationEffect.Prebaked prebaked = (VibrationEffect.Prebaked) effect; switch (prebaked.getId()) { case VibrationEffect.EFFECT_CLICK: case VibrationEffect.EFFECT_DOUBLE_CLICK: case VibrationEffect.EFFECT_HEAVY_CLICK: case VibrationEffect.EFFECT_TICK: case VibrationEffect.EFFECT_POP: case VibrationEffect.EFFECT_THUD: return true; default: Slog.w(TAG, "Unknown prebaked vibration effect, " + "assuming it isn't haptic feedback."); return false; } } final long duration = effect.getDuration(); return duration >= 0 && duration < MAX_HAPTIC_FEEDBACK_DURATION; }
Example #18
Source File: ClientMonitor.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * @param context context of FingerprintService * @param halDeviceId the HAL device ID of the associated fingerprint hardware * @param token a unique token for the client * @param receiver recipient of related events (e.g. authentication) * @param userId target user id for operation * @param groupId groupId for the fingerprint set * @param restricted whether or not client has the {@link Manifest#MANAGE_FINGERPRINT} * permission * @param owner name of the client that owns this */ public ClientMonitor(Context context, long halDeviceId, IBinder token, IFingerprintServiceReceiver receiver, int userId, int groupId,boolean restricted, String owner) { mContext = context; mHalDeviceId = halDeviceId; mToken = token; mReceiver = receiver; mTargetUserId = userId; mGroupId = groupId; mIsRestricted = restricted; mOwner = owner; mSuccessVibrationEffect = VibrationEffect.get(VibrationEffect.EFFECT_CLICK); mErrorVibrationEffect = VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK); try { if (token != null) { token.linkToDeath(this, 0); } } catch (RemoteException e) { Slog.w(TAG, "caught remote exception in linkToDeath: ", e); } }
Example #19
Source File: Tool.java From openlauncher with Apache License 2.0 | 5 votes |
public static void vibrate(View view) { Vibrator vibrator = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE); if (vibrator == null) { // some manufacturers do not vibrate on long press // might as well make this a fallback method view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate(VibrationEffect.createOneShot(50, 160)); } else { vibrator.vibrate(50); } }
Example #20
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static VibrationEffect createEffectFromTimings(long[] timings) { if (timings == null || timings.length == 0) { return null; } else if (timings.length == 1) { return VibrationEffect.createOneShot(timings[0], VibrationEffect.DEFAULT_AMPLITUDE); } else { return VibrationEffect.createWaveform(timings, -1); } }
Example #21
Source File: MainActivity.java From Metronome-Android with Apache License 2.0 | 5 votes |
@Override public void run() { if (isPlaying) { handler.postDelayed(this, interval); if (soundId != -1) soundPool.play(soundId, 1.0f, 1.0f, 0, 0, 1.0f); else if (Build.VERSION.SDK_INT >= 26) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); else vibrator.vibrate(50); } }
Example #22
Source File: Tool.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
public static void vibrate(Context context) { if(context==null) return; Vibrator vibrator = (Vibrator) context.getSystemService(VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT >= 26) { vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibrator.vibrate(50); } }
Example #23
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public VibrationInfo(long startTimeDebug, VibrationEffect effect, VibrationEffect originalEffect, int usageHint, int uid, String opPkg) { mStartTimeDebug = startTimeDebug; mEffect = effect; mOriginalEffect = originalEffect; mUsageHint = usageHint; mUid = uid; mOpPkg = opPkg; }
Example #24
Source File: BulkReadCardDataOperationRunner.java From Walrus with GNU General Public License v3.0 | 5 votes |
@Override @WorkerThread public void onResult(CardData cardData) { if (cardData.equals(lastCardData)) { return; } lastCardData = cardData; SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); if (sharedPref.getBoolean("pref_key_bulk_read_vibrate", true)) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator != null) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate(VibrationEffect.createOneShot(300, 255)); } else { vibrator.vibrate(300); } } } final Card card = Card.copyOf(cardTemplate); // noinspection NonAtomicOperationOnVolatileField card.name += " (" + ++numberOfCardsRead + ")"; card.setCardData(cardData, WalrusApplication.getCurrentBestLocation()); new Handler(context.getMainLooper()).post(new Runnable() { @Override public void run() { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); databaseHelper.getCardDao().create(card); localBroadcastManager.sendBroadcast(new Intent(QueryUtils.ACTION_WALLET_UPDATE)); localBroadcastManager.sendBroadcast(new Intent(ACTION_UPDATE)); } }); }
Example #25
Source File: AndroidController.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
@Override public void startVibration(int duration, float strength) { if (hasVibrator) { if (Build.VERSION.SDK_INT >= 26) { vib.vibrate(VibrationEffect.createOneShot(duration, (int)(Math.min(1,Math.max(0,strength))*255))); } else { vib.vibrate(duration); } vibrationEndMs = TimeUtils.millis() + duration; } }
Example #26
Source File: ContextUtils.java From memetastic with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("UnnecessaryReturnStatement") @SuppressLint("MissingPermission") public void vibrate(final int... ms) { int ms_v = ms != null && ms.length > 0 ? ms[0] : 50; Vibrator vibrator = ((Vibrator) _context.getSystemService(VIBRATOR_SERVICE)); if (vibrator == null) { return; } else if (Build.VERSION.SDK_INT >= 26) { vibrator.vibrate(VibrationEffect.createOneShot(ms_v, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibrator.vibrate(ms_v); } }
Example #27
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private Vibration(IBinder token, VibrationEffect effect, int usageHint, int uid, String opPkg) { this.token = token; this.effect = effect; this.startTime = SystemClock.elapsedRealtime(); this.startTimeDebug = System.currentTimeMillis(); this.usageHint = usageHint; this.uid = uid; this.opPkg = opPkg; }
Example #28
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void doVibratorOn(long millis, int amplitude, int uid, int usageHint) { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "doVibratorOn"); try { synchronized (mInputDeviceVibrators) { if (amplitude == VibrationEffect.DEFAULT_AMPLITUDE) { amplitude = mDefaultVibrationAmplitude; } if (DEBUG) { Slog.d(TAG, "Turning vibrator on for " + millis + " ms" + " with amplitude " + amplitude + "."); } noteVibratorOnLocked(uid, millis); final int vibratorCount = mInputDeviceVibrators.size(); if (vibratorCount != 0) { final AudioAttributes attributes = new AudioAttributes.Builder().setUsage(usageHint).build(); for (int i = 0; i < vibratorCount; i++) { mInputDeviceVibrators.get(i).vibrate(millis, attributes); } } else { // Note: ordering is important here! Many haptic drivers will reset their // amplitude when enabled, so we always have to enable frst, then set the // amplitude. vibratorOn(millis); doVibratorSetAmplitude(amplitude); } } } finally { Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR); } }
Example #29
Source File: ContextUtils.java From openlauncher with Apache License 2.0 | 5 votes |
@SuppressWarnings("UnnecessaryReturnStatement") @SuppressLint("MissingPermission") public void vibrate(final int... ms) { int ms_v = ms != null && ms.length > 0 ? ms[0] : 50; Vibrator vibrator = ((Vibrator) _context.getSystemService(VIBRATOR_SERVICE)); if (vibrator == null) { return; } else if (Build.VERSION.SDK_INT >= 26) { vibrator.vibrate(VibrationEffect.createOneShot(ms_v, VibrationEffect.DEFAULT_AMPLITUDE)); } else { vibrator.vibrate(ms_v); } }
Example #30
Source File: VibrationUtils.java From zephyr with MIT License | 5 votes |
public static void vibrate(@Nullable Context context, int length) { if (context == null) { return; } Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(length, VibrationEffect.DEFAULT_AMPLITUDE)); } else { v.vibrate(length); } } }