kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
map kinda works
rodzic
4e7d59f775
commit
ecef170004
|
@ -45,7 +45,7 @@ android {
|
|||
|
||||
composeOptions {
|
||||
kotlinCompilerVersion "1.3.61-dev-withExperimentalGoogleExtensions-20200129"
|
||||
kotlinCompilerExtensionVersion "0.1.0-dev06"
|
||||
kotlinCompilerExtensionVersion "0.1.0-dev07"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.view.ViewGroup
|
|||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.compose.Composable
|
||||
import androidx.ui.core.ContextAmbient
|
||||
|
||||
/**
|
||||
* Composes an Android [View] given a layout resource [resId]. The method handles the inflation
|
||||
|
@ -36,14 +35,7 @@ import androidx.ui.core.ContextAmbient
|
|||
@Composable
|
||||
// TODO(popam): support modifiers here
|
||||
fun AndroidView(@LayoutRes resId: Int, postInflationCallback: (View) -> Unit = { _ -> }) {
|
||||
val context = ContextAmbient.current
|
||||
|
||||
val r = AndroidViewHolder(context)
|
||||
r.postInflationCallback = postInflationCallback
|
||||
r.resId = resId
|
||||
|
||||
// Hmm - how is merely creating an AndroidViewHolder sufficient to have it end up in the
|
||||
// activities view hierarchy?
|
||||
AndroidViewHolder(postInflationCallback = postInflationCallback, resId = resId)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.geeksville.mesh.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import androidx.compose.Composable
|
||||
import androidx.compose.onCommit
|
||||
import androidx.ui.core.ContextAmbient
|
||||
import androidx.ui.core.Text
|
||||
import androidx.ui.fakeandroidview.AndroidView
|
||||
import androidx.ui.layout.Column
|
||||
import androidx.ui.material.MaterialTheme
|
||||
|
@ -11,9 +14,49 @@ import com.geeksville.android.Logging
|
|||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.model.UIState
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
|
||||
object mapLog : Logging
|
||||
|
||||
|
||||
/**
|
||||
* mapbox requires this, until compose has a nicer way of doing it, do it here
|
||||
*/
|
||||
private val mapLifecycleCallbacks = object : Application.ActivityLifecycleCallbacks {
|
||||
var view: MapView? = null
|
||||
|
||||
override fun onActivityPaused(activity: Activity) {
|
||||
view!!.onPause()
|
||||
}
|
||||
|
||||
override fun onActivityStarted(activity: Activity) {
|
||||
view!!.onStart()
|
||||
}
|
||||
|
||||
override fun onActivityDestroyed(activity: Activity) {
|
||||
view!!.onDestroy()
|
||||
}
|
||||
|
||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
||||
view!!.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onActivityStopped(activity: Activity) {
|
||||
view!!.onStop()
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Activity calls [super.onCreate()][Activity.onCreate].
|
||||
*/
|
||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
view!!.onResume()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun MapContent() {
|
||||
analyticsScreen(name = "map")
|
||||
|
@ -21,13 +64,30 @@ fun MapContent() {
|
|||
val typography = MaterialTheme.typography()
|
||||
val context = ContextAmbient.current
|
||||
|
||||
onCommit(AppStatus.currentScreen) {
|
||||
onDispose {
|
||||
// We no longer care about activity lifecycle
|
||||
(context.applicationContext as Application).unregisterActivityLifecycleCallbacks(
|
||||
mapLifecycleCallbacks
|
||||
)
|
||||
mapLifecycleCallbacks.view = null
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
Text("hi")
|
||||
AndroidView(R.layout.map_view) { view ->
|
||||
view as MapView
|
||||
view.onCreate(UIState.savedInstanceState)
|
||||
view.getMapAsync {
|
||||
mapLog.info("In getmap")
|
||||
|
||||
mapLifecycleCallbacks.view = view
|
||||
(context.applicationContext as Application).registerActivityLifecycleCallbacks(
|
||||
mapLifecycleCallbacks
|
||||
)
|
||||
|
||||
view.getMapAsync { map ->
|
||||
map.setStyle(Style.OUTDOORS) {
|
||||
// Map is set up and the style has loaded. Now you can add data or make other map adjustments
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mapbox.mapboxsdk.maps.MapView android:id="@+id/mapView"
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||
mapbox:mapbox_uiZoomGestures="true"
|
||||
mapbox:mapbox_uiScrollGestures="true"
|
||||
mapbox:mapbox_cameraTargetLat="-32.557013"
|
||||
mapbox:mapbox_cameraTargetLng="-56.149056"
|
||||
mapbox:mapbox_cameraZoom="5.526846"></com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
|
Ładowanie…
Reference in New Issue