Fix vibration deprecations
This commit is contained in:
parent
66f4865de3
commit
2405eb45a0
2 changed files with 18 additions and 2 deletions
|
@ -24,7 +24,9 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -93,7 +95,11 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener,
|
|||
}
|
||||
layout.shareButton.setOnLongClickListener {
|
||||
val v = (activity as Context).getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
v.vibrate(50)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
v.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE))
|
||||
} else {
|
||||
v.vibrate(50)
|
||||
}
|
||||
shareGpxTrack()
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.y20k.trackbook.helpers
|
|||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.location.Location
|
||||
import android.os.Build
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -226,7 +228,15 @@ class MapOverlay(private var markerListener: MarkerListener) {
|
|||
|
||||
override fun onItemLongPress(index: Int, item: OverlayItem): Boolean {
|
||||
val v = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
v.vibrate(50)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
v.vibrate(
|
||||
VibrationEffect.createOneShot(
|
||||
50, VibrationEffect.DEFAULT_AMPLITUDE
|
||||
)
|
||||
)
|
||||
} else {
|
||||
v.vibrate(50)
|
||||
}
|
||||
Toast.makeText(context, item.snippet, Toast.LENGTH_LONG).show()
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue