-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
v.lazin
committed
Aug 16, 2024
1 parent
e558651
commit 03f11f3
Showing
7 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ru.dgis.sdk.demo.car | ||
|
||
import androidx.car.app.CarContext | ||
import androidx.car.app.Screen | ||
import androidx.car.app.model.Action | ||
import androidx.car.app.model.ActionStrip | ||
import androidx.car.app.model.Template | ||
import androidx.car.app.navigation.model.NavigationTemplate | ||
|
||
class MainScreen(carContext: CarContext) : Screen(carContext) { | ||
override fun onGetTemplate(): Template { | ||
return NavigationTemplate.Builder() | ||
.setActionStrip( | ||
ActionStrip.Builder() | ||
.addAction(Action.BACK) | ||
.build() | ||
) | ||
.setMapActionStrip( | ||
ActionStrip.Builder() | ||
.addAction(Action.PAN) | ||
.build() | ||
) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ru.dgis.sdk.demo.car | ||
|
||
import androidx.car.app.CarAppService | ||
import androidx.car.app.Session | ||
import androidx.car.app.validation.HostValidator | ||
|
||
class MapService : CarAppService() { | ||
override fun createHostValidator(): HostValidator { | ||
// Avoid using ALLOW_ALL_HOSTS_VALIDATOR in production as it is insecure. | ||
// Refer to the Android Auto documentation for proper security practices. | ||
return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR | ||
} | ||
|
||
override fun onCreateSession(): Session { | ||
return MapSession() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ru.dgis.sdk.demo.car | ||
|
||
import android.content.Intent | ||
import androidx.car.app.AppManager | ||
import androidx.car.app.CarToast | ||
import androidx.car.app.Screen | ||
import ru.dgis.sdk.androidauto.AndroidAutoMapSession | ||
import ru.dgis.sdk.map.Map | ||
import ru.dgis.sdk.map.MapOptions | ||
import ru.dgis.sdk.map.ScreenPoint | ||
|
||
class MapSession : AndroidAutoMapSession(MapOptions()) { | ||
private var map: Map? = null | ||
|
||
private fun showToast(message: String) { | ||
carContext.getCarService(AppManager::class.java) | ||
.showToast(message, CarToast.LENGTH_SHORT) | ||
} | ||
|
||
override fun onCreateScreen(intent: Intent): Screen { | ||
return MainScreen(carContext) | ||
} | ||
|
||
override fun onMapReady(map: Map) { | ||
this.map = map | ||
} | ||
|
||
override fun onMapReadyException(exception: Exception) { | ||
exception.message?.let(::showToast) | ||
} | ||
|
||
override fun onMapClicked(x: Float, y: Float) { | ||
map?.getRenderedObjects(centerPoint = ScreenPoint(x = x, y = y))?.onResult { | ||
val objectInfo = it.firstOrNull() | ||
showToast("$objectInfo") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<automotiveApp> | ||
<uses name="template" /> | ||
</automotiveApp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters