Я реализовал компас в своем приложении, и мне нужно, чтобы компас останавливался при нажатии кнопки. Есть ли способ сделать это? Мне просто нужно получить угол, в этом случае, когда делается снимок.
Вот как я реализую компас
private fun startCompass()
{
mSendorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager?
}
override fun onResume() {
super.onResume()
@Suppress("DEPRECATION")
mSendorManager?.registerListener(this,
mSendorManager?.getDefaultSensor(Sensor.TYPE_ORIENTATION),
SensorManager.SENSOR_DELAY_GAME)
}
override fun onAccuracyChanged(p0: Sensor?, p1: Int) {
TODO("Not yet implemented")
}
override fun onSensorChanged(event: SensorEvent?) {
val degree= (event?.values?.get(0)!!).roundToLong()
val rotateAnimation = RotateAnimation(
currentDegree,
(-degree).toFloat(),
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f
)
rotateAnimation.duration=210
rotateAnimation.fillAfter = true
currentDegree=(degree).toFloat()
where = when(degree){
in 281..349 -> "NW"
in 261..280 -> "W"
in 191..260 -> "SW"
in 171..190 -> "S"
in 101..170 -> "SE"
in 81..100 -> "E"
in 11..80 -> "NE"
else -> "N"
}
text_view_degree.text="$currentDegree º $where"
}