Fix vibration deprecations

This commit is contained in:
TacoTheDank 2020-07-31 21:13:21 -04:00
parent 66f4865de3
commit 2405eb45a0
2 changed files with 18 additions and 2 deletions

View file

@ -24,7 +24,9 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.VibrationEffect
import android.os.Vibrator import android.os.Vibrator
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -93,7 +95,11 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener,
} }
layout.shareButton.setOnLongClickListener { layout.shareButton.setOnLongClickListener {
val v = (activity as Context).getSystemService(Context.VIBRATOR_SERVICE) as Vibrator val v = (activity as Context).getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
v.vibrate(50) v.vibrate(50)
}
shareGpxTrack() shareGpxTrack()
return@setOnLongClickListener true return@setOnLongClickListener true
} }

View file

@ -21,6 +21,8 @@ package org.y20k.trackbook.helpers
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.location.Location import android.location.Location
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator import android.os.Vibrator
import android.widget.Toast import android.widget.Toast
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -226,7 +228,15 @@ class MapOverlay(private var markerListener: MarkerListener) {
override fun onItemLongPress(index: Int, item: OverlayItem): Boolean { override fun onItemLongPress(index: Int, item: OverlayItem): Boolean {
val v = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator val v = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(
VibrationEffect.createOneShot(
50, VibrationEffect.DEFAULT_AMPLITUDE
)
)
} else {
v.vibrate(50) v.vibrate(50)
}
Toast.makeText(context, item.snippet, Toast.LENGTH_LONG).show() Toast.makeText(context, item.snippet, Toast.LENGTH_LONG).show()
return true return true
} }