-
Notifications
You must be signed in to change notification settings - Fork 140
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
Showing
10 changed files
with
187 additions
and
12 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
15 changes: 15 additions & 0 deletions
15
android-auto-app/src/main/java/com/mapbox/maps/testapp/auto/app/MainActivity.kt
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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
package com.mapbox.maps.testapp.auto.app | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.mapbox.maps.testapp.auto.R | ||
import com.mapbox.maps.testapp.auto.service.MapboxCarAppService | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
switchButton.setOnCheckedChangeListener { _, isChecked -> | ||
if (MapboxCarAppService.enableCustomCallback != isChecked) { | ||
Toast.makeText( | ||
this, | ||
"Custom setting changed please reconnect to the Android Auto", | ||
Toast.LENGTH_LONG) | ||
.show() | ||
} | ||
MapboxCarAppService.enableCustomCallback = isChecked | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
android-auto-app/src/main/java/com/mapbox/maps/testapp/auto/custom/CustomMapSession.kt
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,77 @@ | ||
package com.mapbox.maps.testapp.auto.custom | ||
|
||
import android.Manifest.permission.ACCESS_FINE_LOCATION | ||
import android.content.Intent | ||
import android.content.pm.PackageManager.PERMISSION_GRANTED | ||
import android.content.res.Configuration | ||
import androidx.car.app.AppManager | ||
import androidx.car.app.Screen | ||
import androidx.car.app.ScreenManager | ||
import androidx.car.app.Session | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import com.mapbox.maps.MapInitOptions | ||
import com.mapbox.maps.MapboxExperimental | ||
import com.mapbox.maps.extension.androidauto.MapboxCarMap | ||
import com.mapbox.maps.extension.androidauto.mapboxMapInstaller | ||
import com.mapbox.maps.logI | ||
import com.mapbox.maps.testapp.auto.car.CarAnimationThreadController | ||
import com.mapbox.maps.testapp.auto.car.CarMapShowcase | ||
import com.mapbox.maps.testapp.auto.car.CarMapWidgets | ||
import com.mapbox.maps.testapp.auto.car.MapScreen | ||
import com.mapbox.maps.testapp.auto.car.RequestPermissionScreen | ||
|
||
/** | ||
* Session class for the Mapbox Map sample app for Android Auto. | ||
*/ | ||
@OptIn(MapboxExperimental::class) | ||
class CustomMapSession : Session() { | ||
|
||
private val carAnimationThreadController = CarAnimationThreadController() | ||
private val carMapWidgets = CarMapWidgets() | ||
private val carMapShowcase = CarMapShowcase() | ||
private val mapboxCarMap = MapboxCarMap() | ||
|
||
init { | ||
lifecycle.addObserver(object : DefaultLifecycleObserver { | ||
override fun onCreate(owner: LifecycleOwner) { | ||
val mapInitOptions = MapInitOptions(carContext) | ||
mapboxCarMap.registerObserver(carAnimationThreadController) | ||
mapboxCarMap.registerObserver(carMapWidgets) | ||
mapboxCarMap.registerObserver(carMapShowcase) | ||
|
||
val handle = mapboxCarMap.setupWithCustomCallback(carContext, mapInitOptions) | ||
carContext.getCarService(AppManager::class.java) | ||
.setSurfaceCallback(object : CustomSurfaceCallback(handle) { | ||
override fun onClick(x: Float, y: Float) { | ||
super.onClick(x, y) | ||
logI("CustomMapSession", "onClick $x $y") | ||
} | ||
}) | ||
} | ||
|
||
override fun onDestroy(owner: LifecycleOwner) { | ||
mapboxCarMap.unregisterObserver(carMapShowcase) | ||
mapboxCarMap.unregisterObserver(carMapWidgets) | ||
mapboxCarMap.unregisterObserver(carAnimationThreadController) | ||
} | ||
}) | ||
} | ||
|
||
override fun onCreateScreen(intent: Intent): Screen { | ||
// The onCreate is guaranteed to be called before onCreateScreen. You can pass the | ||
// mapboxCarMap to other screens. Each screen can register and unregister observers. | ||
// This allows you to scope behaviors to sessions, screens, or events. | ||
val mapScreen = MapScreen(mapboxCarMap) | ||
|
||
return if (carContext.checkSelfPermission(ACCESS_FINE_LOCATION) != PERMISSION_GRANTED) { | ||
carContext.getCarService(ScreenManager::class.java) | ||
.push(mapScreen) | ||
RequestPermissionScreen(carContext) | ||
} else mapScreen | ||
} | ||
|
||
override fun onCarConfigurationChanged(newConfiguration: Configuration) { | ||
carMapShowcase.loadMapStyle(carContext) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
android-auto-app/src/main/java/com/mapbox/maps/testapp/auto/custom/CustomSurfaceCallback.kt
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,34 @@ | ||
package com.mapbox.maps.testapp.auto.custom | ||
|
||
import android.graphics.Rect | ||
import androidx.car.app.SurfaceCallback | ||
import androidx.car.app.SurfaceContainer | ||
import com.mapbox.maps.MapboxExperimental | ||
import com.mapbox.maps.extension.androidauto.CarMapSurfaceOwner | ||
|
||
@OptIn(MapboxExperimental::class) | ||
abstract class CustomSurfaceCallback constructor( | ||
private val carMapSurfaceOwner: CarMapSurfaceOwner | ||
) : SurfaceCallback { | ||
|
||
override fun onSurfaceAvailable(surfaceContainer: SurfaceContainer) = | ||
carMapSurfaceOwner.onSurfaceAvailable(surfaceContainer) | ||
|
||
override fun onSurfaceDestroyed(surfaceContainer: SurfaceContainer) = | ||
carMapSurfaceOwner.onSurfaceDestroyed(surfaceContainer) | ||
|
||
override fun onVisibleAreaChanged(visibleArea: Rect) = | ||
carMapSurfaceOwner.onVisibleAreaChanged(visibleArea) | ||
|
||
override fun onStableAreaChanged(stableArea: Rect) = | ||
carMapSurfaceOwner.onStableAreaChanged(stableArea) | ||
|
||
override fun onScale(focusX: Float, focusY: Float, scaleFactor: Float) = | ||
carMapSurfaceOwner.onScale(focusX, focusY, scaleFactor) | ||
|
||
override fun onScroll(distanceX: Float, distanceY: Float) = | ||
carMapSurfaceOwner.onScroll(distanceX, distanceY) | ||
|
||
override fun onFling(velocityX: Float, velocityY: Float) = | ||
carMapSurfaceOwner.onFling(velocityX, velocityY) | ||
} |
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
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