-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start declaring apis with java interop (#6292)
- Loading branch information
Showing
12 changed files
with
165 additions
and
17 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
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
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
83 changes: 83 additions & 0 deletions
83
...-app/src/main/java/com/mapbox/navigation/qa_test_app/testing/CarJavaInterfaceChecker.java
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,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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/testing/JavaFlow.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,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> { | ||
fun accept(value: T) | ||
} |