diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt index aef3dd8e36..613aa418a9 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt @@ -15,6 +15,9 @@ import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import android.widget.LinearLayout +import android.widget.RelativeLayout +import androidx.annotation.IdRes +import androidx.annotation.Keep import androidx.collection.LongSparseArray import com.google.android.gms.dynamic.IObjectWrapper import com.google.android.gms.dynamic.unwrap @@ -97,7 +100,69 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) MapsInitializer.setApiKey(BuildConfig.HMSMAP_KEY) } - this.view = object : FrameLayout(mapContext) {} + this.view = object : FrameLayout(mapContext) { + private val fakeWatermark = View(mapContext).apply { + tag = "GoogleWatermark" + visibility = GONE + } + private val fakeCompass = View(mapContext).apply { + tag = "GoogleMapCompass" + visibility = GONE + } + private val fakeZoomInButton = View(mapContext).apply { + tag = "GoogleMapZoomInButton" + visibility = GONE + } + + private val zoomInButtonRoot = RelativeLayout(mapContext).apply { + addView(fakeZoomInButton) + visibility = GONE + } + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + addView(zoomInButtonRoot) + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + removeView(zoomInButtonRoot) + } + + @Keep + fun findViewTraversal(@IdRes id: Int): T? { + return null + } + + @Keep + fun findViewWithTagTraversal(tag: Any): T? { + if ("GoogleWatermark" == tag) { + return try { + @Suppress("UNCHECKED_CAST") + fakeWatermark as T + } catch (e: ClassCastException) { + null + } + } + if ("GoogleMapCompass" == tag) { + return try { + @Suppress("UNCHECKED_CAST") + fakeCompass as T + } catch (e: ClassCastException) { + null + } + } + if ("GoogleMapZoomInButton" == tag) { + return try { + @Suppress("UNCHECKED_CAST") + fakeZoomInButton as T + } catch (e: ClassCastException) { + null + } + } + return null + } + } } override fun getCameraPosition(): CameraPosition { @@ -601,7 +666,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) } private fun initMap(map: HuaweiMap) { - if (this.map != null) return + if (this.map != null && initialized) return loaded = true this.map = map diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/MapFragment.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/MapFragment.kt index 5bb62383b2..bb2b1ae7da 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/MapFragment.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/MapFragment.kt @@ -35,7 +35,7 @@ class MapFragmentImpl(private val activity: Activity) : IMapFragmentDelegate.Stu if (options == null) { options = GoogleMapOptions() } - Log.d(TAG, "onCreate: $options") + Log.d(TAG, "onCreate $this : $options ") map = GoogleMapImpl(activity, options ?: GoogleMapOptions()) } @@ -47,7 +47,7 @@ class MapFragmentImpl(private val activity: Activity) : IMapFragmentDelegate.Stu if (map == null) { map = GoogleMapImpl(activity, options ?: GoogleMapOptions()) } - Log.d(TAG, "onCreateView: $options") + Log.d(TAG, "onCreateView $this : $options") map!!.onCreate(savedInstanceState) val view = map!!.view val parent = view.parent as ViewGroup? @@ -67,10 +67,15 @@ class MapFragmentImpl(private val activity: Activity) : IMapFragmentDelegate.Stu override fun getMapAsync(callback: IOnMapReadyCallback) = map?.getMapAsync(callback) ?: Unit override fun onDestroyView() { - map?.onDestroy() + Log.d(TAG, "onDestroyView: $this : $options") + if (options?.useViewLifecycleInFragment == true) { + map?.onDestroy() + map = null + } } override fun onDestroy() { + Log.d(TAG, "onDestroy: $this") map?.onDestroy() map = null options = null