-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android Auto] Start declaring apis with java interop #6292
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ object MapboxNavigationApp { | |
* Returns true after [setup] has been called and false after [disable] is called. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun isSetup(): Boolean = mapboxNavigationAppDelegate.isSetup | ||
|
||
/** | ||
|
@@ -81,6 +82,7 @@ object MapboxNavigationApp { | |
* [Activity.isChangingConfigurations]. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun setup(navigationOptions: NavigationOptions) = apply { | ||
mapboxNavigationAppDelegate.setup { navigationOptions } | ||
} | ||
|
@@ -93,6 +95,7 @@ object MapboxNavigationApp { | |
* [Activity.isChangingConfigurations]. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun setup(navigationOptionsProvider: NavigationOptionsProvider) = apply { | ||
mapboxNavigationAppDelegate.setup(navigationOptionsProvider) | ||
} | ||
|
@@ -110,6 +113,7 @@ object MapboxNavigationApp { | |
* You can re-enable [MapboxNavigation] by calling [MapboxNavigationApp.setup]. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun disable() = apply { | ||
mapboxNavigationAppDelegate.disable() | ||
} | ||
|
@@ -124,6 +128,7 @@ object MapboxNavigationApp { | |
* it will be removed from the observers automatically. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun attach(lifecycleOwner: LifecycleOwner) = apply { | ||
mapboxNavigationAppDelegate.attach(lifecycleOwner) | ||
} | ||
|
@@ -138,6 +143,7 @@ object MapboxNavigationApp { | |
* and will potentially cause [MapboxNavigation] to never be created. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun detach(lifecycleOwner: LifecycleOwner) = apply { | ||
mapboxNavigationAppDelegate.detach(lifecycleOwner) | ||
} | ||
|
@@ -146,6 +152,7 @@ object MapboxNavigationApp { | |
* Register an observer to receive the [MapboxNavigation] instance. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun registerObserver(mapboxNavigationObserver: MapboxNavigationObserver) = apply { | ||
mapboxNavigationAppDelegate.registerObserver(mapboxNavigationObserver) | ||
} | ||
|
@@ -154,6 +161,7 @@ object MapboxNavigationApp { | |
* Unregister the observer that was registered through [registerObserver]. | ||
*/ | ||
@UiThread | ||
@JvmStatic | ||
fun unregisterObserver(mapboxNavigationObserver: MapboxNavigationObserver) = apply { | ||
mapboxNavigationAppDelegate.unregisterObserver(mapboxNavigationObserver) | ||
} | ||
|
@@ -164,6 +172,7 @@ object MapboxNavigationApp { | |
* | ||
* @throws IllegalStateException when the class has not been registered. | ||
*/ | ||
@JvmStatic | ||
fun <T : MapboxNavigationObserver> getObserver(kClass: KClass<T>): T { | ||
return mapboxNavigationAppDelegate.getObserver(kClass) | ||
} | ||
|
@@ -172,16 +181,38 @@ object MapboxNavigationApp { | |
* Provides access to any registered observer instance. If no observers have been registered | ||
* with this class type, an empty list is returned. | ||
*/ | ||
@JvmStatic | ||
fun <T : MapboxNavigationObserver> getObservers(kClass: KClass<T>): List<T> { | ||
return mapboxNavigationAppDelegate.getObservers(kClass) | ||
} | ||
|
||
/** | ||
* Java interoperability. Provides access to any registered observer instance. If multiple | ||
* instances of the same class have been registered, the first observer will be returned. | ||
* | ||
* @throws IllegalStateException when the class has not been registered. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to add |
||
*/ | ||
@JvmStatic | ||
fun <T : MapboxNavigationObserver> getObserver(clazz: Class<T>): T { | ||
return mapboxNavigationAppDelegate.getObserver(clazz) | ||
} | ||
|
||
/** | ||
* Java interoperability. Provides access to any registered observer instance. If no observers | ||
* have been registered with this class type, an empty list is returned. | ||
*/ | ||
@JvmStatic | ||
fun <T : MapboxNavigationObserver> getObservers(clazz: Class<T>): List<T> { | ||
return mapboxNavigationAppDelegate.getObservers(clazz) | ||
} | ||
|
||
/** | ||
* [MapboxNavigation] has functions that do not require observation streams. This function | ||
* allows you to get the current instance to call those functions. | ||
* | ||
* For example, you do not need to [registerObserver] in order to call | ||
* [MapboxNavigation.postUserFeedback] or [MapboxNavigation.setRoutes]. | ||
*/ | ||
@JvmStatic | ||
fun current(): MapboxNavigation? = mapboxNavigationAppDelegate.current() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.mapbox.navigation.qa_test_app.testing; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.car.app.CarContext; | ||
import androidx.lifecycle.LifecycleOwner; | ||
|
||
import com.mapbox.androidauto.MapboxCarNavigationManager; | ||
import com.mapbox.androidauto.internal.car.search.CarPlaceSearch; | ||
import com.mapbox.maps.extension.androidauto.MapboxCarMap; | ||
import com.mapbox.navigation.base.options.NavigationOptions; | ||
import com.mapbox.navigation.core.MapboxNavigation; | ||
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp; | ||
import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver; | ||
|
||
import java.util.List; | ||
|
||
import kotlinx.coroutines.CoroutineScope; | ||
|
||
class CarJavaInterfaceChecker { | ||
|
||
void MapboxNavigationApp( | ||
LifecycleOwner lifecycleOwner, | ||
NavigationOptions navigationOptions, | ||
MapboxNavigationObserver observer | ||
) { | ||
// Set up now | ||
MapboxNavigationApp.setup(navigationOptions); | ||
|
||
// Set up provider | ||
MapboxNavigationApp.setup(() -> navigationOptions); | ||
|
||
// Control lifecycles | ||
MapboxNavigationApp.attach(lifecycleOwner); | ||
MapboxNavigationApp.disable(); | ||
MapboxNavigationApp.detach(lifecycleOwner); | ||
|
||
// Get current instance | ||
MapboxNavigation mapboxNavigation = MapboxNavigationApp.current(); | ||
|
||
// Register and unregister observer | ||
MapboxNavigationApp.registerObserver(observer); | ||
MapboxNavigationApp.unregisterObserver(observer); | ||
|
||
MapboxNavigationObserver otherObserver = MapboxNavigationApp.getObserver(CarPlaceSearch.class); | ||
List<CarPlaceSearch> otherObservers = MapboxNavigationApp.getObservers(CarPlaceSearch.class); | ||
} | ||
|
||
void MapboxNavigationObserver() { | ||
MapboxNavigationObserver observer = new MapboxNavigationObserver() { | ||
@Override | ||
public void onAttached(@NonNull MapboxNavigation mapboxNavigation) { | ||
|
||
} | ||
|
||
@Override | ||
public void onDetached(@NonNull MapboxNavigation mapboxNavigation) { | ||
|
||
} | ||
}; | ||
} | ||
|
||
void MapboxCarNavigationManager( | ||
CarContext carContext, | ||
LifecycleOwner lifecycleOwner, | ||
MapboxCarMap mapboxCarMap | ||
) { | ||
// Constructor | ||
MapboxCarNavigationManager sut = new MapboxCarNavigationManager(carContext); | ||
|
||
// Observing auto drive | ||
CoroutineScope scope = JavaFlow.lifecycleScope(lifecycleOwner); | ||
JavaFlow.collect(sut.getAutoDriveEnabledFlow(), scope, (enabled) -> { | ||
// check enabled | ||
}); | ||
|
||
// Get auto drive value | ||
boolean isEnabled = sut.getAutoDriveEnabledFlow().getValue(); | ||
|
||
// Register onto MapboxNavigationAPp | ||
MapboxNavigationApp.registerObserver(sut); | ||
MapboxNavigationApp.unregisterObserver(sut); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mapbox.navigation.qa_test_app.testing | ||
|
||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.lifecycleScope | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* This is not production tested. It is used to showcase java interoperability. | ||
*/ | ||
object JavaFlow { | ||
|
||
@JvmStatic | ||
fun lifecycleScope(owner: LifecycleOwner): CoroutineScope = owner.lifecycleScope | ||
|
||
@JvmStatic | ||
fun <T> collect(flow: Flow<T>, scope: CoroutineScope, consumer: Consumer<T>) { | ||
scope.launch { | ||
flow.collect { value -> consumer.accept(value) } | ||
} | ||
} | ||
} | ||
|
||
interface Consumer<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
fun accept(value: T) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we automate checks if any of public objects' functions or public static functions don't have java interrupt @kmadsen ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I don't know I just lost some confidence in the @JvmStatic https://mapbox.atlassian.net/browse/NAVSDK-544
https://issuetracker.google.com/issues/158393309
It changes the method signature so any changes will risk SEMVER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.8 is the first stable version for
MapboxNavigationApp
so this could be fine. But for other functions that have had previous stable versions - it will change the method signature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crash looks like it should be fixed by #6316.