Java Code Examples for android.os.VibrationEffect#createWaveform()
The following examples show how to use
android.os.VibrationEffect#createWaveform() .
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: 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 3
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 4
Source File: ApiTwentySixPlus.java From linphone-android with GNU General Public License v3.0 | 5 votes |
public static void vibrate(Vibrator vibrator) { long[] timings = {0, 1000, 1000}; int[] amplitudes = {0, VibrationEffect.DEFAULT_AMPLITUDE, 0}; VibrationEffect effect = VibrationEffect.createWaveform(timings, amplitudes, 1); AudioAttributes audioAttrs = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .build(); vibrator.vibrate(effect, audioAttrs); }
Example 5
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
VibratorService(Context context) { vibratorInit(); // Reset the hardware to a default state, in case this is a runtime // restart instead of a fresh boot. vibratorOff(); mSupportsAmplitudeControl = vibratorSupportsAmplitudeControl(); mContext = context; PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*vibrator*"); mWakeLock.setReferenceCounted(true); mAppOps = mContext.getSystemService(AppOpsManager.class); mBatteryStatsService = IBatteryStats.Stub.asInterface(ServiceManager.getService( BatteryStats.SERVICE_NAME)); mPreviousVibrationsLimit = mContext.getResources().getInteger( com.android.internal.R.integer.config_previousVibrationsDumpLimit); mDefaultVibrationAmplitude = mContext.getResources().getInteger( com.android.internal.R.integer.config_defaultVibrationAmplitude); mAllowPriorityVibrationsInLowPowerMode = mContext.getResources().getBoolean( com.android.internal.R.bool.config_allowPriorityVibrationsInLowPowerMode); mPreviousVibrations = new LinkedList<>(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); context.registerReceiver(mIntentReceiver, filter); VibrationEffect clickEffect = createEffectFromResource( com.android.internal.R.array.config_virtualKeyVibePattern); VibrationEffect doubleClickEffect = VibrationEffect.createWaveform( DOUBLE_CLICK_EFFECT_FALLBACK_TIMINGS, -1 /*repeatIndex*/); VibrationEffect heavyClickEffect = createEffectFromResource( com.android.internal.R.array.config_longPressVibePattern); VibrationEffect tickEffect = createEffectFromResource( com.android.internal.R.array.config_clockTickVibePattern); mFallbackEffects = new SparseArray<>(); mFallbackEffects.put(VibrationEffect.EFFECT_CLICK, clickEffect); mFallbackEffects.put(VibrationEffect.EFFECT_DOUBLE_CLICK, doubleClickEffect); mFallbackEffects.put(VibrationEffect.EFFECT_TICK, tickEffect); mFallbackEffects.put(VibrationEffect.EFFECT_HEAVY_CLICK, heavyClickEffect); mScaleLevels = new SparseArray<>(); mScaleLevels.put(SCALE_VERY_LOW, new ScaleLevel(SCALE_VERY_LOW_GAMMA, SCALE_VERY_LOW_MAX_AMPLITUDE)); mScaleLevels.put(SCALE_LOW, new ScaleLevel(SCALE_LOW_GAMMA, SCALE_LOW_MAX_AMPLITUDE)); mScaleLevels.put(SCALE_NONE, new ScaleLevel(SCALE_NONE_GAMMA)); mScaleLevels.put(SCALE_HIGH, new ScaleLevel(SCALE_HIGH_GAMMA)); mScaleLevels.put(SCALE_VERY_HIGH, new ScaleLevel(SCALE_VERY_HIGH_GAMMA)); }