Skip to content

Commit

Permalink
Merge pull request #324 from MarcoSanz12/SensorDelay
Browse files Browse the repository at this point in the history
Use SENSOR_DELAY_GAME for acceleration, gyroscope & magnetometer
  • Loading branch information
hannesa2 authored May 19, 2024
2 parents c59d488 + 39faf78 commit c738cd6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions library/src/main/java/com/panoramagl/PLManager.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.panoramagl

import android.content.Context
import android.content.pm.PackageManager
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.hardware.SensorManager.SENSOR_DELAY_NORMAL
import android.opengl.GLSurfaceView
import android.os.Handler
import android.os.Looper
Expand All @@ -15,6 +15,7 @@ import android.view.GestureDetector.OnDoubleTapListener
import android.view.GestureDetector.SimpleOnGestureListener
import android.widget.ProgressBar
import android.widget.RelativeLayout
import androidx.core.app.ActivityCompat
import com.panoramagl.computation.PLMath
import com.panoramagl.downloaders.PLFileDownloaderManager
import com.panoramagl.downloaders.PLIFileDownloaderManager
Expand Down Expand Up @@ -46,6 +47,7 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene
private var mGLSurfaceView: GLSurfaceView? = null
var sensorManager: SensorManager
private set
var sensorDelay : Int
private var gestureDetector: GestureDetector? = null
var contentLayout: ViewGroup? = null
private set
Expand Down Expand Up @@ -125,6 +127,10 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene

init {
sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
sensorDelay = if (ActivityCompat.checkSelfPermission(context,android.Manifest.permission.HIGH_SAMPLING_RATE_SENSORS) == PackageManager.PERMISSION_GRANTED)
SensorManager.SENSOR_DELAY_FASTEST
else
SensorManager.SENSOR_DELAY_GAME
}

fun onCreate() {
Expand Down Expand Up @@ -890,7 +896,7 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene
if (sensorManager.registerListener(
this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SENSOR_DELAY_NORMAL
sensorDelay
)
) return true
Timber.d("Accelerometer sensor is not available on the device!")
Expand Down Expand Up @@ -934,7 +940,7 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene
return sensorManager.registerListener(
this,
sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
(PLConstants.kDefaultGyroscopeInterval * 1000.0f).toInt()
sensorDelay
)
}

Expand All @@ -949,7 +955,7 @@ open class PLManager(private val context: Context) : PLIView, SensorEventListene
return sensorManager.registerListener(
this,
sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
(PLConstants.kDefaultMagnetometerInterval * 1000.0f).toInt()
sensorDelay
)
}

Expand Down

0 comments on commit c738cd6

Please sign in to comment.