英文:
How to draw content to an AndroidAuto Surface
问题
我正在为AndroidAuto开发一个简单的Kotlin应用程序,它是一个导航应用程序,没有路线,而是使用自定义的地理参考图像作为地图。
我已经熟悉了屏幕和在桌面主机单元上运行服务,我还成功地将导航模板插入到我的一个屏幕中,问题是我不知道如何在这个界面中插入除按钮之外的任何内容。如果有人知道在这个界面上绘制地图或其他内容的方法,那将非常好。
这是我的屏幕Kotlin代码,它在模拟器上渲染一个空的地图布局,没有内容(只有按钮,就像我在驾驶一样消失了)。我知道表面已准备好绘制,因为dpi在日志中返回,但从这一点出发,我不知道如何继续插入地图或其他内容到这个模板中。任何帮助都将是非常好的。
英文:
I am developing a simple Kotlin app for AndroidAuto, it is a navigation app without routes that uses a custom georeferenced image as map.
Im already familiar with Screens and running the service on the Desktop Head Unit, i also have managed to insert a NavigationTemplate to one of my Screens, the problem is that i don't know how to insert any content on this surface beyond buttons. It would be nice if someone knew a way to plot a map or anything else on this surface.
class MapScreen(carContext: CarContext) : Screen(carContext), SurfaceCallback{
init {
Log.d("HelloMapScreen", "Register surface callback")
carContext.getCarService(AppManager::class.java).setSurfaceCallback(this)
}
override fun onGetTemplate(): Template {
return NavigationTemplate.Builder()
.setActionStrip(ActionStrip.Builder()
.addAction(Action.BACK)
.addAction(Action.APP_ICON)
.addAction(Action.PAN)
.addAction(Action.Builder().setTitle("SomeButton")
.build())
.build()
)
.setMapActionStrip(ActionStrip.Builder()
.addAction(Action.PAN)
.build()
)
.build()
}
override fun onSurfaceAvailable(surfaceContainer: SurfaceContainer) {
Log.d("HelloMapScreen", "Received a surface.")
Log.d("Dpi", surfaceContainer.dpi.toString())
}
}
This is my screen kotlin code, it renderizes a empty map layout on the emulator with no content (just the buttons, that disappear as if i was driving) i know the surface is ready to draw because the dpi is being returned on the logcat, but from this point i don't know how to proceed to insert a map or anything else on this template.
Any help would be great.
答案1
得分: 0
请查看在GitHub上提供的导航示例应用代码(或者获取更更新的版本,请查看AndroidX版本)。还可能对Open Street Maps仓库的Android Auto目录感兴趣。
英文:
Check out the navigation sample app code available on GitHub (or for a more up-to-date version, see the AndroidX version of it). The Open Street Maps repo's Android Auto directory may also be of interest.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论