Skip to content

Commit

Permalink
add methods for vibration
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 17, 2025
1 parent 0ae6597 commit acb07db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.VIBRATE" />

<uses-feature
android:name="android.hardware.wifi"
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/com/geode/launcher/utils/GeodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.VibrationEffect
import android.os.Vibrator
import android.os.VibratorManager
import android.provider.DocumentsContract
import android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
import android.util.Log
Expand Down Expand Up @@ -443,6 +446,40 @@ object GeodeUtils {

private external fun permissionCallback(granted: Boolean)

internal fun getVibrator(): Vibrator? = activity.get()?.run {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val manager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
manager.defaultVibrator
} else {
@Suppress("DEPRECATION")
getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
}
}

// vibration
@JvmStatic
fun vibrateSupported(): Boolean = getVibrator()?.hasVibrator() == true

@JvmStatic
fun vibrate(ms: Long) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getVibrator()?.vibrate(VibrationEffect.createOneShot(ms, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
@Suppress("DEPRECATION")
getVibrator()?.vibrate(ms)
}
}

@JvmStatic
fun vibratePattern(pattern: LongArray, repeat: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getVibrator()?.vibrate(VibrationEffect.createWaveform(pattern, repeat))
} else {
@Suppress("DEPRECATION")
getVibrator()?.vibrate(pattern, repeat)
}
}

const val ARGUMENT_SAFE_MODE = "--geode:safe-mode"

private var additionalLaunchArguments = arrayListOf<String>()
Expand Down

0 comments on commit acb07db

Please sign in to comment.