@@ -36,6 +36,7 @@ import com.google.android.gms.maps.CameraUpdateFactory
3636import com.google.android.gms.maps.GoogleMap
3737import com.google.android.gms.maps.GoogleMapOptions
3838import com.google.android.libraries.navigation.NavigationViewForAuto
39+ import com.google.android.libraries.navigation.PromptVisibilityChangedListener
3940
4041open class AndroidAutoBaseScreen (carContext : CarContext ) :
4142 Screen (carContext), SurfaceCallback , NavigationReadyListener {
@@ -45,6 +46,7 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
4546 private var mNavigationView: NavigationViewForAuto ? = null
4647 private var mAutoMapView: GoogleMapsAutoMapView ? = null
4748 private var mViewRegistry: GoogleMapsViewRegistry ? = null
49+ private var mPromptVisibilityListener: PromptVisibilityChangedListener ? = null
4850 protected var mIsNavigationReady: Boolean = false
4951 var mGoogleMap: GoogleMap ? = null
5052
@@ -124,6 +126,13 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
124126 navigationView,
125127 googleMap,
126128 )
129+
130+ // Set up prompt visibility listener
131+ mPromptVisibilityListener = PromptVisibilityChangedListener { promptVisible ->
132+ onPromptVisibilityChanged(promptVisible)
133+ }
134+ navigationView.addPromptVisibilityChangedListener(mPromptVisibilityListener)
135+
127136 sendAutoScreenAvailabilityChangedEvent(true )
128137 invalidate()
129138 }
@@ -133,6 +142,13 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
133142 override fun onSurfaceDestroyed (surfaceContainer : SurfaceContainer ) {
134143 super .onSurfaceDestroyed(surfaceContainer)
135144 sendAutoScreenAvailabilityChangedEvent(false )
145+
146+ // Clean up prompt visibility listener
147+ if (mPromptVisibilityListener != null ) {
148+ mNavigationView?.removePromptVisibilityChangedListener(mPromptVisibilityListener)
149+ mPromptVisibilityListener = null
150+ }
151+
136152 mViewRegistry?.unregisterAndroidAutoView()
137153 mNavigationView?.onPause()
138154 mNavigationView?.onStop()
@@ -166,6 +182,14 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
166182 ) {}
167183 }
168184
185+ // Called when Flutter sends a custom event to native via sendCustomNavigationAutoEvent
186+ // Override this method in your AndroidAutoBaseScreen subclass to handle custom events from
187+ // Flutter
188+ open fun onCustomNavigationAutoEventFromFlutter (event : String , data : Any ) {
189+ // Default implementation does nothing
190+ // Subclasses can override to handle custom events
191+ }
192+
169193 private fun sendAutoScreenAvailabilityChangedEvent (isAvailable : Boolean ) {
170194 GoogleMapsNavigationPlugin .getInstance()?.autoViewEventApi?.onAutoScreenAvailabilityChanged(
171195 isAvailable
@@ -175,4 +199,57 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
175199 override fun onNavigationReady (ready : Boolean ) {
176200 mIsNavigationReady = ready
177201 }
202+
203+ /* *
204+ * Checks if a traffic prompt is currently visible on the Android Auto screen.
205+ *
206+ * This can be useful to dynamically adjust your UI based on prompt visibility, such as when
207+ * building templates or deciding whether to show custom elements.
208+ *
209+ * @return true if a prompt is currently visible, false otherwise
210+ *
211+ * Example:
212+ * ```kotlin
213+ * override fun onGetTemplate(): Template {
214+ * val builder = NavigationTemplate.Builder()
215+ *
216+ * // Only show custom actions if prompt is not visible
217+ * if (!isPromptVisible()) {
218+ * builder.setActionStrip(myCustomActionStrip)
219+ * }
220+ *
221+ * return builder.build()
222+ * }
223+ * ```
224+ */
225+ fun isPromptVisible (): Boolean {
226+ return mNavigationView?.isPromptVisible ? : false
227+ }
228+
229+ /* *
230+ * Called when traffic prompt visibility changes on the Android Auto screen.
231+ *
232+ * Override this method to add custom behavior when prompts appear or disappear, such as
233+ * hiding/showing your custom UI elements to avoid overlapping with system prompts.
234+ *
235+ * @param promptVisible true if the prompt is now visible, false if it's hidden
236+ *
237+ * Example:
238+ * ```kotlin
239+ * override fun onPromptVisibilityChanged(promptVisible: Boolean) {
240+ * super.onPromptVisibilityChanged(promptVisible)
241+ * if (promptVisible) {
242+ * // Hide your custom buttons or UI elements
243+ * } else {
244+ * // Show your custom buttons or UI elements
245+ * }
246+ * }
247+ * ```
248+ */
249+ open fun onPromptVisibilityChanged (promptVisible : Boolean ) {
250+ // Send event to Flutter by default
251+ GoogleMapsNavigationPlugin .getInstance()?.autoViewEventApi?.onPromptVisibilityChanged(
252+ promptVisible
253+ ) {}
254+ }
178255}
0 commit comments