Skip to content

Instantly share code, notes, and snippets.

@panchicore
Created January 16, 2020 16:27
Show Gist options
  • Save panchicore/7d3780a5bbe38de16a5f786e8ecff954 to your computer and use it in GitHub Desktop.
Save panchicore/7d3780a5bbe38de16a5f786e8ecff954 to your computer and use it in GitHub Desktop.
Device shake detection implemented in Kotlin, powered by Seismic.
import android.content.Context
import android.hardware.SensorManager
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.squareup.seismic.ShakeDetector
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity(), ShakeDetector.Listener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
val sd = ShakeDetector(this)
sd.start(sensorManager)
}
override fun hearShake() {
// shaked.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment