Skip to content

Commit

Permalink
invalidate on UI interaction immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixam97 committed May 11, 2024
1 parent afe30b2 commit 8d396f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions automotive/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 29
targetSdkVersion 33
versionCode 234
versionName "0.27.0.0028"
versionCode 235
versionName "0.27.0.0029"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.ixam97.carStatsViewer.carApp

import android.car.Car
import android.content.pm.PackageManager
import androidx.car.app.AppManager
import androidx.car.app.CarAppPermission
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.annotations.ExperimentalCarApi
Expand Down Expand Up @@ -68,7 +65,7 @@ class CarStatsViewerScreen(

private var lastInvalidate: Long = 0L
private var invalidateInQueue = false
private var enableInvalidate = false
private var invalidateTabViewEnabled = false

private val gauge = Gauge(carContext)

Expand Down Expand Up @@ -131,15 +128,15 @@ class CarStatsViewerScreen(

override fun onPause(owner: LifecycleOwner) {
super.onPause(owner)
enableInvalidate = false
invalidateTabViewEnabled = false
InAppLogger.d("[$TAG] Pausing Screen Lifecycle")
// session.carDataSurfaceCallback.pause()
}

override fun onResume(owner: LifecycleOwner) {
super.onResume(owner)
enableInvalidate = true
invalidateTabView()
invalidateTabViewEnabled = true
invalidate() // TabView()
InAppLogger.d("[$TAG] Resuming Screen Lifecycle")
// session.carDataSurfaceCallback.resume()
}
Expand All @@ -151,7 +148,7 @@ class CarStatsViewerScreen(
private fun createTabTemplate() = TabTemplate.Builder(object : TabCallback {
override fun onTabSelected(tabContentId: String) {
selectedTabContentID = tabContentId
invalidateTabView()
invalidate() // TabView()
InAppLogger.v("[$TAG] Tab change requested invalidate.")
}
}).apply {
Expand Down Expand Up @@ -202,7 +199,7 @@ class CarStatsViewerScreen(
}.build()

internal fun invalidateTabView() {
if (invalidateInQueue || !enableInvalidate) return
if (invalidateInQueue || !invalidateTabViewEnabled) return
val nanoTime = System.nanoTime()
if (lastInvalidate + 1_000_000_000 < nanoTime) {
invalidate()
Expand Down Expand Up @@ -244,7 +241,7 @@ class CarStatsViewerScreen(
setItemSize(GridTemplate.ITEM_SIZE_LARGE)
setOnClickListener {
appPreferences.carAppSelectedRealTimeData = if (appPreferences.carAppSelectedRealTimeData == 1) 0 else 1
invalidateTabView()
invalidate() // TabView()
}
}.build())
addItem(GridItem.Builder().apply {
Expand Down Expand Up @@ -277,7 +274,7 @@ class CarStatsViewerScreen(
setItemSize(GridTemplate.ITEM_SIZE_MEDIUM)
setOnClickListener {
appPreferences.carAppSelectedRealTimeData = if (appPreferences.carAppSelectedRealTimeData == 2) 0 else 2
invalidateTabView()
invalidate() // TabView()
}
}.build())
}.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class CarDataSurfaceCallback(val carContext: CarContext): SurfaceCallback {
}

fun pause() {
if (!rendererEnabled) return
synchronized(this) {
renderFrame(clearFrame = true)
}
Expand All @@ -101,6 +102,7 @@ class CarDataSurfaceCallback(val carContext: CarContext): SurfaceCallback {
}

fun resume() {
if (rendererEnabled) return
rendererEnabled = true
invalidatePlot()
InAppLogger.i("[$TAG] Renderer enabled")
Expand Down

0 comments on commit 8d396f2

Please sign in to comment.