Created
May 24, 2018 08:52
-
-
Save alextcn/277eb26f6a06311e95fb0269ba12d186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.jackqack.hodler.utils | |
import android.content.Context | |
import android.os.Build | |
import android.os.VibrationEffect | |
import android.os.Vibrator | |
object Vibrator { | |
private const val VIBRATE_LENGTH_LONG_TOUCH = 50L | |
private const val VIBRATE_AMPLITUDE_LONG_TOUCH = 75 | |
fun longClick(context: Context) { | |
val vibe = context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator? | |
if (vibe == null || !vibe.hasVibrator()) return | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val amplitude = if (vibe.hasAmplitudeControl()) VIBRATE_AMPLITUDE_LONG_TOUCH else VibrationEffect.DEFAULT_AMPLITUDE | |
vibe.vibrate(VibrationEffect.createOneShot(VIBRATE_LENGTH_LONG_TOUCH, amplitude)) | |
} else { | |
vibe.vibrate(VIBRATE_LENGTH_LONG_TOUCH) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment